1 #include "stdio_impl.h"
4 #define MIN(a,b) ((a)<(b) ? (a) : (b))
6 char *fgets(char *restrict s, int n, FILE *restrict f)
24 if (f->rpos != f->rend) {
25 z = memchr(f->rpos, '\n', f->rend - f->rpos);
26 k = z ? z - f->rpos + 1 : f->rend - f->rpos;
28 memcpy(p, f->rpos, k);
34 if ((c = getc_unlocked(f)) < 0) {
35 if (p==s || !feof(f)) s = 0;
39 if ((*p++ = c) == '\n') break;
48 weak_alias(fgets, fgets_unlocked);