X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=kernel%2Flgets.c;fp=kernel%2Flgets.c;h=5e43630ccd4e4e730fa13e5e8cd015ee837e82fa;hb=97d62ebf41ad027327caf69db18123e7791a9416;hp=0000000000000000000000000000000000000000;hpb=03764a355d7c83d58dc7129680faed15a7353346;p=egate.git diff --git a/kernel/lgets.c b/kernel/lgets.c new file mode 100644 index 0000000..5e43630 --- /dev/null +++ b/kernel/lgets.c @@ -0,0 +1,42 @@ +/* Utility: Read line from FIFO + * Europagate, 1995 + * + * $Log: lgets.c,v $ + * Revision 1.1 1995/05/01 12:43:31 adam + * First work on resource monitor program. + * + */ + +#include +#include +#include +#include +#include + +#include + +int lgets (char *buf, int max, int fd) +{ + int r, no = 0; + + --max; + while (no <= max) + { + if ((r=read (fd, buf+no, 1)) != 1) + { + if (r == -1) + gw_log (GW_LOG_WARN|GW_LOG_ERRNO, "lgets", "read fail"); + else + gw_log (GW_LOG_WARN, "lgets", "read eof"); + buf[no] = '\0'; + return 0; + } + if (buf[no] == 1) + return 0; + if (buf[no++] == '\n') + break; + } + buf[no] = '\0'; + return 1; +} +