[git commit nptl_merge] Extend __gen_tempname with mode argument

Mikhail Gusarov dottedmag at dottedmag.net
Mon Nov 9 21:17:04 UTC 2009


commit: http://git.uclibc.org/uClibc/commit/?id=8d74517c1619e3f688ad543717cee25d0b166a6e
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/nptl_merge

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 at dottedmag.net>
Signed-off-by: Austin Foxley <austinf at cetoncorp.com>
---
 libc/inet/getaddrinfo.c        |    2 +-
 libc/misc/internals/tempname.c |   14 +++++++-------
 libc/misc/internals/tempname.h |    3 ++-
 libc/stdio/tempnam.c           |    2 +-
 libc/stdio/tmpfile.c           |    3 ++-
 libc/stdio/tmpnam.c            |    2 +-
 libc/stdio/tmpnam_r.c          |    2 +-
 libc/stdlib/mkdtemp.c          |    3 ++-
 libc/stdlib/mkstemp.c          |    3 ++-
 libc/stdlib/mkstemp64.c        |    3 ++-
 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 b91486f..4a42b9e 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 cbd4ced..4abd3c6 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 ac40bef..e75b632 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 faf7c5e..66c905d 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 57f2527..c6b2dc8 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 1f180e0..323105b 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 eec589e..8f616b2 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 fa9ae3b..2bf15ae 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 c569cea..ce7d7db 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 02a03f0..2cdee70 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 f3af1c1..3c922e3 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';
 
-- 
1.6.3.3



More information about the uClibc-cvs mailing list