MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / linenoiseNoTTY

Function linenoiseNoTTY

tools/shell/linenoise.cpp:3835–3868  ·  view source on GitHub ↗

This function is called when linenoise() is called with the standard * input file descriptor not attached to a TTY. So for example when the * program using linenoise is called in pipe or with a file redirected * to its standard input. In this case, we want to be able to return the * line regardless of its length (by default we are limited to 4k). */

Source from the content-addressed store, hash-verified

3833 * to its standard input. In this case, we want to be able to return the
3834 * line regardless of its length (by default we are limited to 4k). */
3835static char* linenoiseNoTTY(void) {
3836 const int EOF = -1;
3837
3838 char* line = NULL;
3839 size_t len = 0, maxlen = 0;
3840
3841 while (1) {
3842 if (len == maxlen) {
3843 if (maxlen == 0)
3844 maxlen = 16;
3845 maxlen *= 2;
3846 char* oldval = line;
3847 line = (char*)realloc(line, maxlen);
3848 if (line == NULL) {
3849 if (oldval)
3850 free(oldval);
3851 return NULL;
3852 }
3853 }
3854 int c = fgetc(stdin);
3855 if (c == EOF || c == '\n') {
3856 if (c == EOF && len == 0) {
3857 free(line);
3858 return NULL;
3859 } else {
3860 line[len] = '\0';
3861 return line;
3862 }
3863 } else {
3864 line[len] = c;
3865 len++;
3866 }
3867 }
3868}
3869
3870/* The high level function that is the main API of the linenoise library.
3871 * This function checks if the terminal has basic capabilities, just checking

Callers 1

linenoiseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected