Tweak the evutil_open_closeonexec patch to work on windows, old unixes.
authorNick Mathewson <nickm@torproject.org>
Sun, 12 Feb 2012 02:17:18 +0000 (21:17 -0500)
committerNick Mathewson <nickm@torproject.org>
Sun, 12 Feb 2012 02:17:18 +0000 (21:17 -0500)
Windows doesn't have a mode_t as far as I can tell.

Some unixes, iirc, don't like three-argument open without O_CREAT.

evutil.c
util-internal.h

index 7e392790d224aae7b5d4d9edcfd86c9b212357b4..b6634591a9bccbc0bfdfdad516d13550bee28c2f 100644 (file)
--- a/evutil.c
+++ b/evutil.c
@@ -88,7 +88,7 @@
 #endif
 
 int
-evutil_open_closeonexec(const char *pathname, int flags, mode_t mode)
+evutil_open_closeonexec(const char *pathname, int flags, unsigned mode)
 {
        int fd;
 
@@ -96,7 +96,10 @@ evutil_open_closeonexec(const char *pathname, int flags, mode_t mode)
        flags |= O_CLOEXEC;
 #endif
 
-       fd = open(pathname, flags, mode);
+       if (flags & O_CREAT)
+               fd = open(pathname, flags, (mode_t)mode);
+       else
+               fd = open(pathname, flags);
        if (fd < 0)
                return -1;
 
index d09aa471b1cbe30752798e9b9a0f98dce102d790..47fe962d9a6fb4c52268852c97d82d8afa79a834 100644 (file)
@@ -161,7 +161,10 @@ char EVUTIL_TOLOWER(char c);
 #define EVUTIL_UPCAST(ptr, type, field)                                \
        ((type *)(((char*)(ptr)) - evutil_offsetof(type, field)))
 
-int evutil_open_closeonexec(const char *pathname, int flags, mode_t mode);
+/* As open(pathname, flags, mode), except that the file is always opened with
+ * the close-on-exec flag set. (And the mode argument is mandatory.)
+ */
+int evutil_open_closeonexec(const char *pathname, int flags, unsigned mode);
 
 int evutil_read_file(const char *filename, char **content_out, size_t *len_out,
     int is_binary);