Mercurial > hg > toybox
changeset 397:b7afbc6b753a
Forgot to check in loopfiles_rw changes needed by truncate.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 12 Dec 2011 15:19:52 -0600 |
parents | 7ca3bef07f0d |
children | a4dcbad4f92a |
files | lib/lib.c lib/lib.h |
diffstat | 2 files changed, 8 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/lib.c Sun Dec 11 03:58:43 2011 -0600 +++ b/lib/lib.c Mon Dec 12 15:19:52 2011 -0600 @@ -488,6 +488,7 @@ end = strchr(suffixes, tolower(*c)); if (end) val *= 1024L<<((end-suffixes)*10); } + return val; } @@ -624,7 +625,8 @@ // // Note: read only filehandles are automatically closed when function() // returns, but writeable filehandles must be close by function() -void loopfiles_rw(char **argv, int flags, void (*function)(int fd, char *name)) +void loopfiles_rw(char **argv, int flags, int permissions, int failok, + void (*function)(int fd, char *name)) { int fd; @@ -635,7 +637,7 @@ // Inability to open a file prints a warning, but doesn't exit. if (!strcmp(*argv,"-")) fd=0; - else if (0>(fd = open(*argv, flags, 0666))) { + else if (0>(fd = open(*argv, flags, permissions)) && !failok) { perror_msg("%s", *argv); toys.exitval = 1; continue; @@ -645,10 +647,10 @@ } while (*++argv); } -// Call loopfiles_rw with O_RDONLY (common case). +// Call loopfiles_rw with O_RDONLY and !failok (common case). void loopfiles(char **argv, void (*function)(int fd, char *name)) { - loopfiles_rw(argv, O_RDONLY, function); + loopfiles_rw(argv, O_RDONLY, 0, 0, function); } // Slow, but small.
--- a/lib/lib.h Sun Dec 11 03:58:43 2011 -0600 +++ b/lib/lib.h Mon Dec 12 15:19:52 2011 -0600 @@ -90,7 +90,8 @@ long atolx(char *c); off_t fdlength(int fd); char *xreadlink(char *name); -void loopfiles_rw(char **argv, int flags, void (*function)(int fd, char *name)); +void loopfiles_rw(char **argv, int flags, int permissions, int failok, + void (*function)(int fd, char *name)); void loopfiles(char **argv, void (*function)(int fd, char *name)); char *get_rawline(int fd, long *plen, char end); char *get_line(int fd);