libc/mktemp: Pass flags to open()
authorSimon Arlott <sa.me.uk>
Sat, 3 Nov 2018 20:08:07 +0000 (20:08 +0000)
committerAaron LI <aly@aaronly.me>
Mon, 5 Nov 2018 14:33:16 +0000 (22:33 +0800)
The flags from the functions that call _gettemp() are never used.

They should be included in the call to open(), otherwise features like
O_CLOEXEC don't work.

aly:
(1) Checked FreeBSD and it behaves the same way as this fix.
(2) Improve the style a bit.

lib/libc/stdio/mktemp.c

index d186fd7..28d7002 100644 (file)
@@ -165,9 +165,10 @@ _gettemp(char *path, int *doopen, int domkdir, int slen, int oflags)
 
        for (;;) {
                if (doopen) {
-                       if ((*doopen =
-                           _open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0)
+                       if ((*doopen = _open(path, O_CREAT|O_EXCL|O_RDWR|oflags,
+                                            0600)) >= 0) {
                                return (1);
+                       }
                        if (errno != EEXIST)
                                return (0);
                } else if (domkdir) {