ref: 59fd8e09d75fc7b279a7e4b20fcd0fb7d92e8122
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;
}