MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / read_line

Function read_line

tools/cdb2sql/cdb2sql.cpp:546–588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544}
545
546static char *read_line()
547{
548 static char *line = NULL;
549
550 if (istty) {
551 if (line) {
552 free(line);
553 line = NULL;
554 }
555 if ((line = readline(prompt)) != NULL && line[0] != 0 &&
556 !skip_history(line))
557 add_history(line);
558 return line;
559 }
560 int total_len = 0;
561 int n = -1;
562 static size_t sz = 0;
563 static char *getline = NULL;
564 while ((n = getdelim(&getline, &sz, delimstr[delim_len - 1], stdin)) !=
565 -1) {
566 if (n > 0) {
567 total_len += n;
568 line = (char *)realloc(line, total_len + 1);
569 strcpy(line + total_len - n, getline);
570 if (has_delimiter(line, total_len, delimstr, delim_len) == true) {
571 line[total_len - delim_len] = 0;
572 return line;
573 }
574 }
575 }
576 if (n == -1 && total_len == 0) {
577 if (line) {
578 free(line);
579 line = NULL;
580 }
581 if (getline) {
582 free(getline);
583 getline = NULL;
584 }
585 return NULL;
586 }
587 return line;
588}
589
590#define checkfortype(str, STRTYPE, ret) \
591 do { \

Callers 2

get_multi_line_statementFunction · 0.70
mainFunction · 0.70

Calls 4

freeFunction · 0.85
skip_historyFunction · 0.85
reallocFunction · 0.85
has_delimiterFunction · 0.85

Tested by

no test coverage detected