From a4841776b6e1751232d46482731836a7c17b896f Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Fri, 3 Jan 2020 03:50:24 +0100 Subject: Still working on it... --- src/util/string.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/util/string.c') 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; +} -- cgit v1.2.3-70-g09d2