scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

fgets.c (250B)


      1 #include <stdio.h>
      2 #undef fgets
      3 
      4 char *
      5 fgets(char *s, int n, FILE *fp)
      6 {
      7 	int ch;
      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 }