First work on resource monitor program.
[egate.git] / kernel / lgets.c
diff --git a/kernel/lgets.c b/kernel/lgets.c
new file mode 100644 (file)
index 0000000..5e43630
--- /dev/null
@@ -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 <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <ctype.h>
+#include <unistd.h>
+
+#include <lgets.h>
+
+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;
+}
+