in src/couch_quickjs/c_src/couchjs.c [204:248]
static ssize_t linein(char** line, size_t *linemax) {
#ifdef _WIN32
char *ptr, *eptr;
if (line == NULL || stdin == NULL || linemax == NULL) {
return -1;
}
if (*line == NULL || *linemax <= 1) {
return -1;
}
for (ptr = *line, eptr = *line + *linemax;;) {
int c = fgetc(stdin);
if (c == -1) {
if (feof(stdin)) {
ssize_t diff = (ssize_t)(ptr - *line);
if (diff != 0) {
*ptr = '\0';
return diff;
}
}
return -1;
}
*ptr++ = c;
if (c == '\n') {
*ptr = '\0';
return ptr - *line;
}
if (ptr + 1 > eptr) {
char *nline;
size_t nlinemax = *linemax * 2;
ssize_t d = ptr - *line;
if ((nline = realloc(*line, nlinemax)) == NULL) {
return -1;
}
*line = nline;
*linemax = nlinemax;
eptr = nline + nlinemax;
ptr = nline + d;
}
}
#else
return getline(line, linemax, stdin);
#endif
}