+/* Utility: Read line from FIFO
+ * Europagate, 1995
+ *
+ * $Log: lgets.c,v $
+ * Revision 1.1 1995/05/01 12:43:58 adam
+ * lgets function moved from kernel to util.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <ctype.h>
+#include <unistd.h>
+
+#include <gw-log.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;
+}
+