...but you can get 0 if you have a "no newline at end of file" file.
I've been through all the current callers, and just these ones weren't using the canonical test. --- toys/lsb/mount.c | 2 +- toys/pending/init.c | 2 +- toys/pending/lsof.c | 2 +- toys/pending/userdel.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
From 80af4c20000d20789aca6532b9c69345ffd6406b Mon Sep 17 00:00:00 2001 From: Elliott Hughes <e...@google.com> Date: Fri, 24 Sep 2021 16:49:02 -0700 Subject: [PATCH] getline() returns -1 on EOF, not 0. ...but you can get 0 if you have a "no newline at end of file" file. I've been through all the current callers, and just these ones weren't using the canonical test. --- toys/lsb/mount.c | 2 +- toys/pending/init.c | 2 +- toys/pending/lsof.c | 2 +- toys/pending/userdel.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/toys/lsb/mount.c b/toys/lsb/mount.c index 8ff084cf..960a6ca9 100644 --- a/toys/lsb/mount.c +++ b/toys/lsb/mount.c @@ -215,7 +215,7 @@ static void mount_filesystem(char *dev, char *dir, char *type, if (fp && !buf) { size_t i; - if (getline(&buf, &i, fp)<0) { + if (getline(&buf, &i, fp)<=0) { error_msg("%s: need -t", dev); break; } diff --git a/toys/pending/init.c b/toys/pending/init.c index 565c5c08..6f01c22b 100644 --- a/toys/pending/init.c +++ b/toys/pending/init.c @@ -136,7 +136,7 @@ static void parse_inittab(void) return; } - while (getline(&line, &allocated_length, fp)) { + while (getline(&line, &allocated_length, fp) > 0) { char *p = line, *x, *tty_name = 0, *command = 0, *extracted_token, *tmp; int action = 0, token_count = 0, i; diff --git a/toys/pending/lsof.c b/toys/pending/lsof.c index 5ab3af90..2ab4177a 100644 --- a/toys/pending/lsof.c +++ b/toys/pending/lsof.c @@ -115,7 +115,7 @@ static void scan_proc_net_file(char *path, int family, char type, if (!fp) return; - if (!getline(&line, &line_length, fp)) return; // Skip header. + if (getline(&line, &line_length, fp) <= 0) return; // Skip header. while (getline(&line, &line_length, fp) > 0) { fn(line, family, type); diff --git a/toys/pending/userdel.c b/toys/pending/userdel.c index abf67f43..51ee67c9 100644 --- a/toys/pending/userdel.c +++ b/toys/pending/userdel.c @@ -50,7 +50,7 @@ static void update_groupfiles(char *filename, char* username) newfp = xfopen(filenamesfx, "w+"); - while (getline(&line, &allocated_length, exfp)) { + while (getline(&line, &allocated_length, exfp) > 0) { sprintf(toybuf, "%s:",username); if (strncmp(line, toybuf, ulen+1)) { char *n, *p = strrchr(line, ':'); -- 2.33.0.685.g46640cef36-goog
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net