1 #include "stdio_impl.h"
7 ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restrict f)
28 if (f->rpos != f->rend) {
29 z = memchr(f->rpos, delim, f->rend - f->rpos);
30 k = z ? z - f->rpos + 1 : f->rend - f->rpos;
37 if (!z && m < SIZE_MAX/4) m += m/2;
43 /* Copy as much as fits and ensure no
44 * pushback remains in the FILE buf. */
46 memcpy(*s+i, f->rpos, k);
58 memcpy(*s+i, f->rpos, k);
62 if ((c = getc_unlocked(f)) == EOF) {
69 /* If the byte read by getc won't fit without growing the
70 * output buffer, push it back for next iteration. */
71 if (i+1 >= *n) *--f->rpos = c;
72 else if (((*s)[i++] = c) == delim) break;
81 weak_alias(getdelim, __getdelim);