diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-21 16:34:08 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-21 16:40:13 +0100 |
| commit | 69e3e11a75ed1dabc854406e29bacd5401912874 (patch) | |
| tree | e7a456eb0b1feb49a0ece87ebb42cbcccd8412b8 /src/util.c | |
| parent | Add man pages (diff) | |
| download | blind-69e3e11a75ed1dabc854406e29bacd5401912874.tar.gz blind-69e3e11a75ed1dabc854406e29bacd5401912874.tar.bz2 blind-69e3e11a75ed1dabc854406e29bacd5401912874.tar.xz | |
Don't open files from /dev/fd/, just return the fd.
Advantage 1: Less file descriptors opened.
Advantage 2: The other end will be alerted when the process
closes the file descriptor, and does not have to wait until
the process exits.
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
| -rw-r--r-- | src/util.c | 15 |
1 files changed, 15 insertions, 0 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; +} |
