MCPcopy Create free account
hub / github.com/duckdb/duckdb / local_getline

Function local_getline

tools/shell/shell.cpp:524–555  ·  view source on GitHub ↗

** This routine reads a line of text from FILE in, stores ** the text in memory obtained from malloc() and returns a pointer ** to the text. NULL is returned at end of file, or if malloc() ** fails. ** ** If zLine is not NULL then it is a malloced buffer returned from ** a previous call to this routine that may be reused. */

Source from the content-addressed store, hash-verified

522** a previous call to this routine that may be reused.
523*/
524static char *local_getline(char *zLine, FILE *in) {
525 idx_t nLine = zLine == 0 ? 0 : 100;
526 idx_t n = 0;
527
528 while (1) {
529 if (n + 100 > nLine) {
530 nLine = nLine * 2 + 100;
531 zLine = (char *)realloc(zLine, nLine);
532 if (!zLine) {
533 shell_out_of_memory();
534 }
535 }
536 if (fgets(&zLine[n], nLine - n, in) == 0) {
537 if (n == 0) {
538 free(zLine);
539 return 0;
540 }
541 zLine[n] = 0;
542 break;
543 }
544 while (zLine[n])
545 n++;
546 if (n > 0 && zLine[n - 1] == '\n') {
547 n--;
548 if (n > 0 && zLine[n - 1] == '\r')
549 n--;
550 zLine[n] = 0;
551 break;
552 }
553 }
554 return zLine;
555}
556
557/*
558** Retrieve a single line of input text.

Callers 1

OneInputLineMethod · 0.85

Calls 1

shell_out_of_memoryFunction · 0.85

Tested by

no test coverage detected