| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/string.c | 35 | 
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; +} | 


