shithub: scc

ref: 2b9e16f9e9a4f8b06d778d5de834a30ac96fbd53
dir: /lib/c/fgets.c/

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