diff options
author | Mikhail Gusarov <dottedmag@dottedmag.net> | 2009-11-08 02:33:15 +0600 |
---|---|---|
committer | Austin Foxley <austinf@cetoncorp.com> | 2009-11-09 15:24:19 -0800 |
commit | 8d74517c1619e3f688ad543717cee25d0b166a6e (patch) | |
tree | ad2a9a1a66b1a8ef63463d94ffe038a6aeee6dee /libc | |
parent | 45bc2bc53ddb15fb8df194240d232e09b6872b39 (diff) |
Extend __gen_tempname with mode argument
sem_open(3) needs to create a temporary file in a way which can't
be efficiently implemented in terms of POSIX API. Extend
__gen_tempname with mode_t mode argument in order to ease
sem_open implementation.
Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
Diffstat (limited to 'libc')
-rw-r--r-- | libc/inet/getaddrinfo.c | 2 | ||||
-rw-r--r-- | libc/misc/internals/tempname.c | 14 | ||||
-rw-r--r-- | libc/misc/internals/tempname.h | 3 | ||||
-rw-r--r-- | libc/stdio/tempnam.c | 2 | ||||
-rw-r--r-- | libc/stdio/tmpfile.c | 3 | ||||
-rw-r--r-- | libc/stdio/tmpnam.c | 2 | ||||
-rw-r--r-- | libc/stdio/tmpnam_r.c | 2 | ||||
-rw-r--r-- | libc/stdlib/mkdtemp.c | 3 | ||||
-rw-r--r-- | libc/stdlib/mkstemp.c | 3 | ||||
-rw-r--r-- | libc/stdlib/mkstemp64.c | 3 | ||||
-rw-r--r-- | libc/stdlib/mktemp.c | 2 |
11 files changed, 22 insertions, 17 deletions
diff --git a/libc/inet/getaddrinfo.c b/libc/inet/getaddrinfo.c index b91486f53..4a42b9eb6 100644 --- a/libc/inet/getaddrinfo.c +++ b/libc/inet/getaddrinfo.c @@ -307,7 +307,7 @@ gaih_local(const char *name, const struct gaih_service *service, char *buf = ((struct sockaddr_un *)ai->ai_addr)->sun_path; if (__path_search(buf, L_tmpnam, NULL, NULL, 0) != 0 - || __gen_tempname(buf, __GT_NOCREATE) != 0 + || __gen_tempname(buf, __GT_NOCREATE, 0) != 0 ) { return -EAI_SYSTEM; } diff --git a/libc/misc/internals/tempname.c b/libc/misc/internals/tempname.c index cbd4ced7a..4abd3c6aa 100644 --- a/libc/misc/internals/tempname.c +++ b/libc/misc/internals/tempname.c @@ -168,14 +168,14 @@ static void brain_damaged_fillrand(unsigned char *buf, unsigned int len) KIND may be one of: __GT_NOCREATE: simply verify that the name does not exist - at the time of the call. + at the time of the call. mode argument is ignored. __GT_FILE: create the file using open(O_CREAT|O_EXCL) - and return a read-write fd. The file is mode 0600. + and return a read-write fd with given mode. __GT_BIGFILE: same as __GT_FILE but use open64(). - __GT_DIR: create a directory, which will be mode 0700. + __GT_DIR: create a directory with given mode. */ -int attribute_hidden __gen_tempname (char *tmpl, int kind) +int attribute_hidden __gen_tempname (char *tmpl, int kind, mode_t mode) { char *XXXXXX; unsigned int i; @@ -217,15 +217,15 @@ int attribute_hidden __gen_tempname (char *tmpl, int kind) fd = 0; } case __GT_FILE: - fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); + fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL, mode); break; #if defined __UCLIBC_HAS_LFS__ case __GT_BIGFILE: - fd = open64 (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); + fd = open64 (tmpl, O_RDWR | O_CREAT | O_EXCL, mode); break; #endif case __GT_DIR: - fd = mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR); + fd = mkdir (tmpl, mode); break; default: fd = -1; diff --git a/libc/misc/internals/tempname.h b/libc/misc/internals/tempname.h index ac40bef6e..e75b632d8 100644 --- a/libc/misc/internals/tempname.h +++ b/libc/misc/internals/tempname.h @@ -3,13 +3,14 @@ #define __need_size_t #include <stddef.h> +#include <sys/types.h> /* Disable support for $TMPDIR */ extern int ___path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx /*, int try_tmpdir */) attribute_hidden; #define __path_search(tmpl, tmpl_len, dir, pfx, try_tmpdir) ___path_search(tmpl, tmpl_len, dir, pfx) -extern int __gen_tempname (char *__tmpl, int __kind) attribute_hidden; +extern int __gen_tempname (char *__tmpl, int __kind, mode_t mode) attribute_hidden; /* The __kind argument to __gen_tempname may be one of: */ #define __GT_FILE 0 /* create a file */ diff --git a/libc/stdio/tempnam.c b/libc/stdio/tempnam.c index faf7c5ecb..66c905db8 100644 --- a/libc/stdio/tempnam.c +++ b/libc/stdio/tempnam.c @@ -36,7 +36,7 @@ tempnam (const char *dir, const char *pfx) if (__path_search (buf, FILENAME_MAX, dir, pfx, 1)) return NULL; - if (__gen_tempname (buf, __GT_NOCREATE)) + if (__gen_tempname (buf, __GT_NOCREATE, 0)) return NULL; return strdup (buf); diff --git a/libc/stdio/tmpfile.c b/libc/stdio/tmpfile.c index 57f252715..c6b2dc8a9 100644 --- a/libc/stdio/tmpfile.c +++ b/libc/stdio/tmpfile.c @@ -18,6 +18,7 @@ #include <features.h> #include <stdio.h> +#include <sys/stat.h> #include <unistd.h> #include "../misc/internals/tempname.h" #include <not-cancel.h> @@ -35,7 +36,7 @@ FILE * tmpfile (void) if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0)) return NULL; - fd = __gen_tempname (buf, __GT_FILE); + fd = __gen_tempname (buf, __GT_FILE, S_IRUSR | S_IWUSR); if (fd < 0) return NULL; diff --git a/libc/stdio/tmpnam.c b/libc/stdio/tmpnam.c index 1f180e08a..323105ba4 100644 --- a/libc/stdio/tmpnam.c +++ b/libc/stdio/tmpnam.c @@ -41,7 +41,7 @@ tmpnam (char *s) 0)) return NULL; - if (__builtin_expect (__gen_tempname (tmpbuf, __GT_NOCREATE), 0)) + if (__builtin_expect (__gen_tempname (tmpbuf, __GT_NOCREATE, 0), 0)) return NULL; if (s == NULL) diff --git a/libc/stdio/tmpnam_r.c b/libc/stdio/tmpnam_r.c index eec589e39..8f616b273 100644 --- a/libc/stdio/tmpnam_r.c +++ b/libc/stdio/tmpnam_r.c @@ -28,7 +28,7 @@ char * tmpnam_r (char *s) if (__path_search (s, L_tmpnam, NULL, NULL, 0)) return NULL; - if (__gen_tempname (s, __GT_NOCREATE)) + if (__gen_tempname (s, __GT_NOCREATE, 0)) return NULL; return s; diff --git a/libc/stdlib/mkdtemp.c b/libc/stdlib/mkdtemp.c index fa9ae3b05..2bf15ae06 100644 --- a/libc/stdlib/mkdtemp.c +++ b/libc/stdlib/mkdtemp.c @@ -19,6 +19,7 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/stat.h> #include "../misc/internals/tempname.h" #ifdef __USE_BSD @@ -29,7 +30,7 @@ (This function comes from OpenBSD.) */ char * mkdtemp (char *template) { - if (__gen_tempname (template, __GT_DIR)) + if (__gen_tempname (template, __GT_DIR, S_IRUSR | S_IWUSR | S_IXUSR)) return NULL; else return template; diff --git a/libc/stdlib/mkstemp.c b/libc/stdlib/mkstemp.c index c569ceaf5..ce7d7dba0 100644 --- a/libc/stdlib/mkstemp.c +++ b/libc/stdlib/mkstemp.c @@ -18,6 +18,7 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/stat.h> #include "../misc/internals/tempname.h" /* Generate a unique temporary file name from TEMPLATE. @@ -26,5 +27,5 @@ Then open the file and return a fd. */ int mkstemp (char *template) { - return __gen_tempname (template, __GT_FILE); + return __gen_tempname (template, __GT_FILE, S_IRUSR | S_IWUSR); } diff --git a/libc/stdlib/mkstemp64.c b/libc/stdlib/mkstemp64.c index 02a03f00e..2cdee70a2 100644 --- a/libc/stdlib/mkstemp64.c +++ b/libc/stdlib/mkstemp64.c @@ -18,6 +18,7 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/stat.h> #include "../misc/internals/tempname.h" /* Generate a unique temporary file name from TEMPLATE. @@ -26,5 +27,5 @@ Then open the file and return a fd. */ int mkstemp64 (char *template) { - return __gen_tempname (template, __GT_BIGFILE); + return __gen_tempname (template, __GT_BIGFILE, S_IRUSR | S_IWUSR); } diff --git a/libc/stdlib/mktemp.c b/libc/stdlib/mktemp.c index f3af1c15c..3c922e328 100644 --- a/libc/stdlib/mktemp.c +++ b/libc/stdlib/mktemp.c @@ -25,7 +25,7 @@ * they are replaced with a string that makes the filename unique. */ char *mktemp(char *template) { - if (__gen_tempname (template, __GT_NOCREATE) < 0) + if (__gen_tempname (template, __GT_NOCREATE, 0) < 0) /* We return the null string if we can't find a unique file name. */ template[0] = '\0'; |