diff options
author | Rob Landley <rob@landley.net> | 2018-06-14 14:10:17 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-06-14 14:10:17 -0500 |
commit | d63bc6849c2a3b6ff0b909390488cb423208d61d (patch) | |
tree | c3d80ccff30c984608ac661962441dce3582f8ed /lib | |
parent | 5605a0ff2ad28eafa3ce6f2f4ef1ca96498ab79d (diff) | |
download | toybox-d63bc6849c2a3b6ff0b909390488cb423208d61d.tar.gz |
Change do_lines() semantics to end with a callback(0,0) to indicate EOF,
adjusting existing users.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -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); } |