shithub: scc

ref: 4eaac6bfb11cc84259e8b418d4babffdf1c637eb
dir: /lib/c/stdio/fgets.c/

View raw version
#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;
}