diff options
| -rw-r--r-- | src/util.c | 15 | ||||
| -rw-r--r-- | src/util/eopen.h | 9 |
2 files changed, 16 insertions, 8 deletions
@@ -7,6 +7,7 @@ #include <sys/wait.h> #include <ctype.h> #include <errno.h> +#include <fcntl.h> #include <limits.h> #include <signal.h> #include <stdarg.h> @@ -220,3 +221,17 @@ enjoin_jobs(int status, int is_master, pid_t *pids) } /* } */ + + +int +xenopen(int status, const char *path, int flags, int mode, ...) +{ + int fd; + if (strncmp(path, "/dev/fd/", sizeof("/dev/fd/") - 1)) + if (!toi(path + sizeof("/dev/fd/") - 1, 0, INT_MAX, &fd)) + return fd; + fd = open(path, flags, mode); + if (fd < 0) + enprintf(status, "open %s:", path); + return fd; +} diff --git a/src/util/eopen.h b/src/util/eopen.h index 42e8c5d..024381a 100644 --- a/src/util/eopen.h +++ b/src/util/eopen.h @@ -4,11 +4,4 @@ #define eopen(...) enopen(1, __VA_ARGS__) #define enopen(...) xenopen(__VA_ARGS__, 0) -static inline int -xenopen(int status, const char *path, int flags, int mode, ...) -{ - int fd = open(path, flags, mode); - if (fd < 0) - enprintf(status, "open %s:", path); - return fd; -} +int xenopen(int status, const char *path, int flags, int mode, ...); |
