From a20626fb3516169c8c06bd1729cf29465d2cbd1f Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Wed, 20 Oct 2021 11:39:08 +0200 Subject: util: Go to next non-empty line, skip newlines in line_read() Otherwise, we'll stop returning lines at the first empty line in a file -- this is not expected in case of e.g. /etc/resolv.conf. Signed-off-by: Stefano Brivio --- util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'util.c') diff --git a/util.c b/util.c index 4c2e9bb..6fb535c 100644 --- a/util.c +++ b/util.c @@ -405,7 +405,11 @@ char *line_read(char *buf, size_t len, int fd) buf[len] = 0; - if (!(p = strchr(buf, '\n'))) + p = buf; + while (*p == '\n' && strlen(p) && (size_t)(p - buf) < len) + p++; + + if (!(p = strchr(p, '\n'))) return buf; *p = 0; -- cgit v1.2.3