aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c8
-rw-r--r--lib/lib.h3
2 files changed, 6 insertions, 5 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 9f9b8136..49fd5dd2 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -713,9 +713,9 @@ void poke(void *ptr, long long val, unsigned size)
void loopfiles_rw(char **argv, int flags, int permissions,
void (*function)(int fd, char *name))
{
- int fd, failok = !(flags&WARN_ONLY);
+ int fd, failok = !(flags&WARN_ONLY), anyway = flags & LOOPFILES_ANYWAY;
- flags &= ~WARN_ONLY;
+ flags &= ~(WARN_ONLY|LOOPFILES_ANYWAY);
// If no arguments, read from stdin.
if (!*argv) function((flags & O_ACCMODE) != O_RDONLY ? 1 : 0, "-");
@@ -726,10 +726,10 @@ void loopfiles_rw(char **argv, int flags, int permissions,
if (!strcmp(*argv, "-")) fd = 0;
else if (0>(fd = notstdio(open(*argv, flags, permissions))) && !failok) {
perror_msg_raw(*argv);
- continue;
+ if (!anyway) continue;
}
function(fd, *argv);
- if ((flags & O_CLOEXEC) && fd) close(fd);
+ if ((flags & O_CLOEXEC) && fd>0) close(fd);
} while (*++argv);
}
diff --git a/lib/lib.h b/lib/lib.h
index cf1920f9..7484eb8f 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -112,7 +112,8 @@ void show_help(FILE *out, int full);
// Tell xopen and friends to print warnings but return -1 as necessary
// The largest O_BLAH flag so far is arch/alpha's O_PATH at 0x800000 so
// plenty of headroom.
-#define WARN_ONLY (1<<31)
+#define WARN_ONLY (1<<31) // don't exit, just warn
+#define LOOPFILES_ANYWAY (1<<30) // call function with fd -1
// xwrap.c
void xstrncpy(char *dest, char *src, size_t size);