about summary refs log tree commit diff
path: root/sysdeps/posix/tempname.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-12-14 15:23:56 +0000
committerUlrich Drepper <drepper@redhat.com>1998-12-14 15:23:56 +0000
commit60876a75445b1b65e4a0ec54e18205a79f79466b (patch)
treef1ed7e59c543e092bbd492af3654abfad53a4344 /sysdeps/posix/tempname.c
parent59036602bf40d3b35884280881be4edfb1378430 (diff)
downloadglibc-60876a75445b1b65e4a0ec54e18205a79f79466b.tar.gz
glibc-60876a75445b1b65e4a0ec54e18205a79f79466b.tar.xz
glibc-60876a75445b1b65e4a0ec54e18205a79f79466b.zip
Update.
	* include/stdio.h: Add new parameter to __path_search.
	* libio/oldtmpfile.c: Add 0 as new parameter to __path_search.
	* stdio-common/tmpfile.c: Likewise.
	* stdio-common/tmpfile64.c: Likewise.
	* stdio-common/tmpnam.c: Likewise.
	* stdio-common/tmpnam_r.c: Likewise.
	* stdio-common/tempnam.c: Add 1 as new parameter to __path_search.
	* sysdeps/posix/tempname.c: Add new parameter.  If value is nonzero
	consider TMPDIR environment variable and dir parameter.  Otherwise not.
	* stdio-common/Makefile (tests): Add tst-tmpnam.
	* stdio-common/tst-tmpnam.c: New file.
Diffstat (limited to 'sysdeps/posix/tempname.c')
-rw-r--r--sysdeps/posix/tempname.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c
index 97a01d2b7e..1a113757aa 100644
--- a/sysdeps/posix/tempname.c
+++ b/sysdeps/posix/tempname.c
@@ -43,7 +43,8 @@ direxists (const char *dir)
    doesn't exist, none of the searched dirs exists, or there's not
    enough space in TMPL. */
 int
-__path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx)
+__path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
+	       int try_tmpdir)
 {
   const char *d;
   size_t dlen, plen;
@@ -60,14 +61,17 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx)
 	plen = 5;
     }
 
-  d = __secure_getenv ("TMPDIR");
-  if (d != NULL && direxists (d))
-    dir = d;
-  else if (dir != NULL && direxists (dir))
-    /* nothing */ ;
-  else if (direxists (P_tmpdir))
+  if (try_tmpdir)
+    {
+      d = __secure_getenv ("TMPDIR");
+      if (d != NULL && direxists (d))
+	dir = d;
+      else if (dir != NULL && direxists (dir))
+	/* nothing */ ;
+    }
+  if (direxists (P_tmpdir))
     dir = P_tmpdir;
-  else if (direxists ("/tmp"))
+  else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
     dir = "/tmp";
   else
     {