scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

fgets.c (254B)


      1 #include <stdio.h>
      2 #undef fgets
      3 
      4 char *
      5 fgets(char *s, int n, FILE *fp)
      6 {
      7 	int ch = 0;
      8 	char *t = s;
      9 
     10 	while (--n > 0 && (ch = getc(fp)) != EOF) {
     11 		if ((*t++ = ch) == '\n')
     12 			break;
     13 	}
     14 	if (ch == EOF && s == t)
     15 		return NULL;
     16 	*t = '\0';
     17 
     18 	return s;
     19 }