aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-06-14 14:10:17 -0500
committerRob Landley <rob@landley.net>2018-06-14 14:10:17 -0500
commitd63bc6849c2a3b6ff0b909390488cb423208d61d (patch)
treec3d80ccff30c984608ac661962441dce3582f8ed /lib/lib.c
parent5605a0ff2ad28eafa3ce6f2f4ef1ca96498ab79d (diff)
downloadtoybox-d63bc6849c2a3b6ff0b909390488cb423208d61d.tar.gz
Change do_lines() semantics to end with a callback(0,0) to indicate EOF,
adjusting existing users.
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 3bfe7fc4..77d8cc8f 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -644,7 +644,7 @@ void loopfiles(char **argv, void (*function)(int fd, char *name))
loopfiles_rw(argv, O_RDONLY|O_CLOEXEC|WARN_ONLY, 0, function);
}
-// call loopfiles with do_lines()
+// glue to call dl_lines() from loopfiles
static void (*do_lines_bridge)(char **pline, long len);
static void loopfile_lines_bridge(int fd, char *name)
{
@@ -1344,6 +1344,7 @@ char *getgroupname(gid_t gid)
// Iterate over lines in file, calling function. Function can write 0 to
// the line pointer if they want to keep it, or 1 to terminate processing,
// otherwise line is freed. Passed file descriptor is closed at the end.
+// At EOF calls function(0, 0)
void do_lines(int fd, void (*call)(char **pline, long len))
{
FILE *fp = fd ? xfdopen(fd, "r") : stdin;
@@ -1359,6 +1360,7 @@ void do_lines(int fd, void (*call)(char **pline, long len))
free(line);
} else break;
}
+ call(0, 0);
if (fd) fclose(fp);
}