aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-06-07 20:22:14 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-06-12 02:48:42 +0200
commit412100289e7b3ebde5423f2099e247d1d9e41634 (patch)
tree2c3212c17fc795b9f30a0a23e71b808ab69634ba
parentec128558a4d067f51cd36d8026e6df849ea7de26 (diff)
downloadliberty-412100289e7b3ebde5423f2099e247d1d9e41634.tar.gz
liberty-412100289e7b3ebde5423f2099e247d1d9e41634.tar.xz
liberty-412100289e7b3ebde5423f2099e247d1d9e41634.zip
Improve read_line()
One less useless boolean variable.
-rw-r--r--liberty.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/liberty.c b/liberty.c
index 035d23d..178754c 100644
--- a/liberty.c
+++ b/liberty.c
@@ -3040,23 +3040,19 @@ xstrtoul (unsigned long *out, const char *s, int base)
}
static bool
-read_line (FILE *fp, struct str *s)
+read_line (FILE *fp, struct str *line)
{
- int c;
- bool at_end = true;
+ str_reset (line);
- str_reset (s);
- while ((c = fgetc (fp)) != EOF)
+ int c;
+ while ((c = fgetc (fp)) != '\n')
{
- at_end = false;
- if (c == '\r')
- continue;
- if (c == '\n')
- break;
- str_append_c (s, c);
+ if (c == EOF)
+ return line->len != 0;
+ if (c != '\r')
+ str_append_c (line, c);
}
-
- return !at_end;
+ return true;
}
static char *