document sticky EOF
[unix-history] / usr / src / lib / libc / stdio / fgets.c
index 877564c..abe686e 100644 (file)
@@ -1,4 +1,7 @@
-/* @(#)fgets.c 4.1 (Berkeley) %G% */
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)fgets.c    5.2 (Berkeley) %G%";
+#endif LIBC_SCCS and not lint
+
 #include       <stdio.h>
 
 char *
 #include       <stdio.h>
 
 char *
@@ -10,12 +13,12 @@ register FILE *iop;
        register char *cs;
 
        cs = s;
        register char *cs;
 
        cs = s;
-       while (--n>0 && (c = getc(iop))>=0) {
+       while (--n>0 && (c = getc(iop)) != EOF) {
                *cs++ = c;
                if (c=='\n')
                        break;
        }
                *cs++ = c;
                if (c=='\n')
                        break;
        }
-       if (c<0 && cs==s)
+       if (c == EOF && cs==s)
                return(NULL);
        *cs++ = '\0';
        return(s);
                return(NULL);
        *cs++ = '\0';
        return(s);