|
|
1.1 ! root 1: /* ! 2: * libc/stdio/fgets.c ! 3: * ANSI-compliant C standard i/o library. ! 4: * fgets() ! 5: * ANSI 4.9.10.2. ! 6: * Get string from stream. ! 7: * Read up to n-1 characters, including newline. ! 8: */ ! 9: ! 10: #include <stdio.h> ! 11: ! 12: char * ! 13: fgets(s, n, stream) char *s; register int n; FILE *stream; ! 14: { ! 15: register c; ! 16: register char *cp; ! 17: ! 18: cp = s; ! 19: while (--n > 0 && (c = getc(stream)) != EOF) ! 20: if ((*cp++ = c) == '\n') ! 21: break; ! 22: if (c == EOF && (cp == s || ferror(stream))) ! 23: return NULL; /* ANSI says leave *cp unchanged */ ! 24: *cp = '\0'; /* else NUL-terminate */ ! 25: return s; ! 26: } ! 27: ! 28: /* end of libc/stdio/fgets.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.