summaryrefslogtreecommitdiff
path: root/clients/xzwrite/bfgets.c
blob: 96636f90bfa417f2af1777c2bf08cf0469710f0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* bfgets.c
 *
 * declaration:
 *   char *bfgets(s, n, iop)
 *      char *s;
 *      int  n;
 *      FILE *iop;
 *
 * Reads n-1 characters or until a newline from iop.  The terminating newline
 * is NOT RETURNED.
 *
 * Written by Barr3y Jaspan (bjaspan@athena.mit.edu)
 */

#include <stdio.h>

char *bfgets();

char *bfgets(s, n, iop)
   char *s;
   int  n;
   FILE *iop;
{
     register int c = 0;
     register char *cs;

     cs = s;
     while ((--n > 0) && ((c = getc(iop)) !=EOF) && (c != '\n'))
	  *cs++ = c;

     *cs = '\0';
     return (c == EOF && cs == s) ? NULL : s;
}