shithub: scc

ref: b95034ed959dbc24a91df409a35ae8282ba15cdd
dir: /src/libc/stdio/fgets.c/

View raw version
#include <stdio.h>
#undef fgets

char *
fgets(char * restrict s, int n, FILE * restrict 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;
}