MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_getline

Function cbm_getline

src/foundation/compat.c:367–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365
366#ifdef _WIN32
367ssize_t cbm_getline(char **lineptr, size_t *n, FILE *stream) {
368 if (!lineptr || !n || !stream) {
369 return CBM_NOT_FOUND;
370 }
371 if (!*lineptr || *n == 0) {
372 *n = CBM_SZ_128;
373 *lineptr = (char *)malloc(*n);
374 if (!*lineptr) {
375 return CBM_NOT_FOUND;
376 }
377 }
378 size_t pos = 0;
379 int c;
380 while ((c = fgetc(stream)) != EOF) {
381 if (pos + 1 >= *n) {
382 size_t new_n = *n * PAIR_LEN;
383 char *tmp = (char *)realloc(*lineptr, new_n);
384 if (!tmp) {
385 return CBM_NOT_FOUND;
386 }
387 *lineptr = tmp;
388 *n = new_n;
389 }
390 (*lineptr)[pos++] = (char)c;
391 if (c == '\n') {
392 break;
393 }
394 }
395 if (pos == 0 && c == EOF) {
396 return CBM_NOT_FOUND;
397 }
398 (*lineptr)[pos] = '\0';
399 return (ssize_t)pos;
400}
401#endif

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected