From 412100289e7b3ebde5423f2099e247d1d9e41634 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C5=99emysl=20Janouch?=
Date: Wed, 7 Jun 2017 20:22:14 +0200
Subject: [PATCH] Improve read_line()
One less useless boolean variable.
---
liberty.c | 22 +++++++++-------------
1 file 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)
{
+ str_reset (line);
+
int c;
- bool at_end = true;
-
- str_reset (s);
- while ((c = fgetc (fp)) != EOF)
+ 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 *