From 77edf68c1a986fa3f80f5d5c986a736cbb5d24c4 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 30 Apr 2017 14:00:19 +0200 Subject: Do not reopen /dev/std{in,out,err} when specified explicitly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/util.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index b5aac6e..95b46f4 100644 --- a/src/util.c +++ b/src/util.c @@ -234,9 +234,16 @@ int xenopen(int status, const char *path, int flags, int mode, ...) { int fd; - if (!strncmp(path, "/dev/fd/", sizeof("/dev/fd/") - 1)) + if (!strncmp(path, "/dev/fd/", sizeof("/dev/fd/") - 1)) { if (!toi(path + sizeof("/dev/fd/") - 1, 0, INT_MAX, &fd)) return fd; + } else if (!strcmp(path, "/dev/stdin")) { + return STDIN_FILENO; + } else if (!strcmp(path, "/dev/stdout")) { + return STDOUT_FILENO; + } else if (!strcmp(path, "/dev/stderr")) { + return STDERR_FILENO; + } fd = open(path, flags, mode); if (fd < 0) enprintf(status, "open %s:", path); -- cgit v1.2.3-70-g09d2