(wrong string) ée

From: <git_AT_suckless.org>
Date: Sat, 21 Jan 2017 16:44:13 +0100 (CET)

commit 69e3e11a75ed1dabc854406e29bacd5401912874
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Sat Jan 21 16:34:08 2017 +0100
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Sat Jan 21 16:40:13 2017 +0100

    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_AT_kth.se>

diff --git a/src/util.c b/src/util.c
index c315010..60e4cb0 100644
--- a/src/util.c
+++ b/src/util.c
_AT_@ -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>
_AT_@ -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
_AT_@ -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, ...);
Received on Sat Jan 21 2017 - 16:44:13 CET

This archive was generated by hypermail 2.3.0 : Sat Jan 21 2017 - 16:48:25 CET