source: trunk/minix/lib/stdio/fgets.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 488 bytes
RevLine 
[9]1/*
2 * fgets.c - get a string from a file
3 */
4/* $Header: /cvsup/minix/src/lib/stdio/fgets.c,v 1.1.1.1 2005/04/21 14:56:35 beng Exp $ */
5
6#include <stdio.h>
7
8char *
9fgets(char *s, register int n, register FILE *stream)
10{
11 register int ch;
12 register char *ptr;
13
14 ptr = s;
15 while (--n > 0 && (ch = getc(stream)) != EOF) {
16 *ptr++ = ch;
17 if ( ch == '\n')
18 break;
19 }
20 if (ch == EOF) {
21 if (feof(stream)) {
22 if (ptr == s) return NULL;
23 } else return NULL;
24 }
25 *ptr = '\0';
26 return s;
27}
Note: See TracBrowser for help on using the repository browser.