]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/clients/xzwrite/bfgets.c
finalize -3
[1ts-debian.git] / zephyr / clients / xzwrite / bfgets.c
1 /* bfgets.c
2  *
3  * declaration:
4  *   char *bfgets(s, n, iop)
5  *      char *s;
6  *      int  n;
7  *      FILE *iop;
8  *
9  * Reads n-1 characters or until a newline from iop.  The terminating newline
10  * is NOT RETURNED.
11  *
12  * Written by Barr3y Jaspan (bjaspan@athena.mit.edu)
13  */
14
15 #include <stdio.h>
16
17 char *bfgets();
18
19 char *bfgets(s, n, iop)
20    char *s;
21    int  n;
22    FILE *iop;
23 {
24      register int c = 0;
25      register char *cs;
26
27      cs = s;
28      while ((--n > 0) && ((c = getc(iop)) !=EOF) && (c != '\n'))
29           *cs++ = c;
30
31      *cs = '\0';
32      return (c == EOF && cs == s) ? NULL : s;
33 }