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);
59 memcpy(*s+i, f->rpos, k);
64 if ((c = getc_unlocked(f)) == EOF) {
71 /* If the byte read by getc won't fit without growing the
72 * output buffer, push it back for next iteration. */
73 if (i+1 >= *n) *--f->rpos = c;
74 else if (((*s)[i++] = c) == delim) break;
83 weak_alias(getdelim, __getdelim);