ref: e6baf91cf4a7df1de7d0d64688cf3f5ed0b89d1a
dir: /lib/c/fgets.c/
#include <stdio.h> #undef fgets char * fgets(char *s, int n, FILE *fp) { int ch; 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; }