summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2020-01-03 03:50:24 +0100
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2020-01-03 03:50:24 +0100
commita4841776b6e1751232d46482731836a7c17b896f (patch)
treebd818e08f2c145dc1629d0d568feb7106ff274d8 /src/util
parent63016ce5c71019de315434de3e91adbf535d4986 (diff)
Still working on it...
Diffstat (limited to 'src/util')
-rw-r--r--src/util/string.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/util/string.c b/src/util/string.c
index edb5eb6..7e754bd 100644
--- a/src/util/string.c
+++ b/src/util/string.c
@@ -34,3 +34,38 @@ int relabsd_util_parse_int
*output = ((int) buffer);
return 0;
}
+
+/*
+ * Returns -1 on error,
+ * 0 on EOF,
+ * 1 on newline.
+ */
+int relabsd_util_reach_next_line_or_eof (FILE f [const restrict static 1])
+{
+ char c;
+
+ c = (char) getc(f);
+
+ while ((c != '\n') && c != EOF)
+ {
+ c = (char) getc(f);
+ }
+
+ if (ferror(f))
+ {
+ /*
+ * The 'ferror' function's manual specifically states that it does not
+ * sets errno. There is no mention of errno in the 'getc' function's
+ * either, so I am assuming that errno cannot be used to indicate the
+ * error.
+ */
+ return -1;
+ }
+
+ if (c == EOF)
+ {
+ return 0;
+ }
+
+ return 1;
+}