Run latex
[egate.git] / kernel / lgets.c
1 /* Utility: Read line from FIFO
2  * Europagate, 1995
3  *
4  * $Log: lgets.c,v $
5  * Revision 1.1  1995/05/01 12:43:31  adam
6  * First work on resource monitor program.
7  *
8  */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <assert.h>
13 #include <ctype.h>
14 #include <unistd.h>
15
16 #include <lgets.h>
17
18 int lgets (char *buf, int max, int fd)
19 {
20     int r, no = 0;
21
22     --max;
23     while (no <= max)
24     {
25         if ((r=read (fd, buf+no, 1)) != 1)
26         {
27             if (r == -1)
28                 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, "lgets", "read fail");
29             else
30                 gw_log (GW_LOG_WARN, "lgets", "read eof");
31             buf[no] = '\0';
32             return 0;
33         }
34         if (buf[no] == 1)
35             return 0;     
36         if (buf[no++] == '\n')
37             break;
38     }
39     buf[no] = '\0';     
40     return 1;
41 }
42