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)
25 if (f->rpos != f->rend) {
26 z = memchr(f->rpos, '\n', f->rend - f->rpos);
27 k = z ? z - f->rpos + 1 : f->rend - f->rpos;
29 memcpy(p, f->rpos, k);
35 if ((c = getc_unlocked(f)) < 0) {
36 if (p==s || !feof(f)) s = 0;
40 if ((*p++ = c) == '\n') break;
49 weak_alias(fgets, fgets_unlocked);