ref: 5c59ce4b790db825f40a8b7de0e7086abb14eccb
dir: /src/libc/stdio/fgets.c/
#include <stdio.h> #undef fgets char * fgets(char *s, int n, FILE *fp) { int ch = 0; char *t = s; while (--n > 0 && (ch = getc(fp)) != EOF) { if ((*t++ = ch) == '\n') break; } if (ch == EOF && s == t) return NULL; *t = '\0'; return s; }