home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * $Source: /unixb/home/unixlib/source/unixlib37/src/stdio/c/RCS/fgets,v $
- * $Date: 1996/11/06 22:01:42 $
- * $Revision: 1.2 $
- * $State: Rel $
- * $Author: unixlib $
- *
- * $Log: fgets,v $
- * Revision 1.2 1996/11/06 22:01:42 unixlib
- * Yet more changes by NB, PB and SC.
- *
- * Revision 1.1 1996/04/19 21:32:42 simon
- * Initial revision
- *
- ***************************************************************************/
-
- static const char rcs_id[] = "$Id: fgets,v 1.2 1996/11/06 22:01:42 unixlib Rel $";
-
- #include <stdio.h>
-
- __STDIOLIB__
-
- char *
- fgets (char *_s, size_t n, FILE *f)
- {
- register char *s = _s;
- register int c = 0;
-
- /* Repeat, obtaining characters until we hit a newline,
- or exceed our count, n. */
- while (--n > 0 && (c = getc (f)) >= 0)
- if ((*s++ = c) == '\n')
- break;
-
- *s = 0;
-
- return ((c < 0 && s == _s) ? 0 : _s);
- }
-