Commit | Line | Data |
---|---|---|
2ce81398 DS |
1 | #if defined(LIBC_SCCS) && !defined(lint) |
2 | static char sccsid[] = "@(#)fgets.c 5.2 (Berkeley) %G%"; | |
3 | #endif LIBC_SCCS and not lint | |
b8f253e8 | 4 | |
0175c543 BJ |
5 | #include <stdio.h> |
6 | ||
7 | char * | |
8 | fgets(s, n, iop) | |
9 | char *s; | |
10 | register FILE *iop; | |
11 | { | |
12 | register c; | |
13 | register char *cs; | |
14 | ||
15 | cs = s; | |
41e01b3e | 16 | while (--n>0 && (c = getc(iop)) != EOF) { |
0175c543 BJ |
17 | *cs++ = c; |
18 | if (c=='\n') | |
19 | break; | |
20 | } | |
41e01b3e | 21 | if (c == EOF && cs==s) |
0175c543 BJ |
22 | return(NULL); |
23 | *cs++ = '\0'; | |
24 | return(s); | |
25 | } |