summary refs log tree commit diff
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
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.
-rw-r--r--ChangeLog12
-rw-r--r--include/stdio.h6
-rw-r--r--libio/oldtmpfile.c2
-rw-r--r--stdio-common/Makefile3
-rw-r--r--stdio-common/tempnam.c2
-rw-r--r--stdio-common/tmpfile.c2
-rw-r--r--stdio-common/tmpfile64.c2
-rw-r--r--stdio-common/tmpnam.c2
-rw-r--r--stdio-common/tmpnam_r.c2
-rw-r--r--stdio-common/tst-tmpnam.c51
-rw-r--r--sysdeps/posix/tempname.c20
11 files changed, 86 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index df88c1c5f7..e22c24821e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 1998-12-14  Ulrich Drepper  <drepper@cygnus.com>
 
+	* 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.
+
 	* po/es.po: Update from translation team.
 
 1998-12-12  Andreas Schwab  <schwab@issan.cs.uni-dortmund.de>
diff --git a/include/stdio.h b/include/stdio.h
index 071ce9f051..dcc9c15ec7 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -33,8 +33,8 @@ extern int __vsscanf __P ((__const char *__restrict __s,
 # include <stddef.h>
 /* Generate a unique file name (and possibly open it).  */
 extern int __path_search __P ((char *__tmpl, size_t __tmpl_len,
-			       __const char *__dir,
-			       __const char *__pfx));
+			       __const char *__dir, __const char *__pfx,
+			       int __try_tempdir));
 
 extern int __gen_tempname __P ((char *__tmpl, int __openit, int __large_file));
 
@@ -42,5 +42,5 @@ extern int __gen_tempname __P ((char *__tmpl, int __openit, int __large_file));
 extern void __libc_fatal __P ((__const char *__message))
      __attribute__ ((__noreturn__));
 
-   
+
 #endif
diff --git a/libio/oldtmpfile.c b/libio/oldtmpfile.c
index 6c4275d00c..72437fea0f 100644
--- a/libio/oldtmpfile.c
+++ b/libio/oldtmpfile.c
@@ -32,7 +32,7 @@ __old_tmpfile (void)
   int fd;
   FILE *f;
 
-  if (__path_search (buf, FILENAME_MAX, NULL, "tmpf"))
+  if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
     return NULL;
   fd = __gen_tempname (buf, 1, 0);
   if (fd < 0)
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 49f9ddb4f7..1ad5d473be 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -48,7 +48,8 @@ tests := tst-printf tstscanf test_rdwr test-popen tstgetln test-fseek \
 	 xbug errnobug \
 	 bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 bug10 bug11 bug12 \
 	 tfformat tiformat tstdiomisc tst-printfsz tst-wc-printf \
-	 scanf1 scanf2 scanf3 scanf4 scanf5 scanf7 scanf8 scanf9 scanf10
+	 scanf1 scanf2 scanf3 scanf4 scanf5 scanf7 scanf8 scanf9 scanf10 \
+	 tst-tmpnam
 
 include ../Rules
 
diff --git a/stdio-common/tempnam.c b/stdio-common/tempnam.c
index 5d4960f216..47ecf6d56d 100644
--- a/stdio-common/tempnam.c
+++ b/stdio-common/tempnam.c
@@ -31,7 +31,7 @@ tempnam (const char *dir, const char *pfx)
 {
   char buf[FILENAME_MAX];
 
-  if (__path_search (buf, FILENAME_MAX, dir, pfx))
+  if (__path_search (buf, FILENAME_MAX, dir, pfx, 1))
     return NULL;
 
   if (__gen_tempname (buf, 0, 0))
diff --git a/stdio-common/tmpfile.c b/stdio-common/tmpfile.c
index 4a9e4e2e0a..cfd3606bec 100644
--- a/stdio-common/tmpfile.c
+++ b/stdio-common/tmpfile.c
@@ -36,7 +36,7 @@ tmpfile (void)
   int fd;
   FILE *f;
 
-  if (__path_search (buf, FILENAME_MAX, NULL, "tmpf"))
+  if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
     return NULL;
   fd = __gen_tempname (buf, 1, 0);
   if (fd < 0)
diff --git a/stdio-common/tmpfile64.c b/stdio-common/tmpfile64.c
index 0f3a0044a4..2ea6bfc3a8 100644
--- a/stdio-common/tmpfile64.c
+++ b/stdio-common/tmpfile64.c
@@ -35,7 +35,7 @@ tmpfile64 ()
   int fd;
   FILE *f;
 
-  if (__path_search (buf, FILENAME_MAX, NULL, "tmpf"))
+  if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
     return NULL;
   fd = __gen_tempname (buf, 1, 1);
   if (fd < 0)
diff --git a/stdio-common/tmpnam.c b/stdio-common/tmpnam.c
index 0bbb318953..beba12d130 100644
--- a/stdio-common/tmpnam.c
+++ b/stdio-common/tmpnam.c
@@ -34,7 +34,7 @@ tmpnam (char *s)
   /* In the following call we use the buffer pointed to by S if
      non-NULL although we don't know the size.  But we limit the size
      to L_tmpnam characters in any case.  */
-  if (__path_search (s ? : tmpbuf, L_tmpnam, NULL, NULL))
+  if (__path_search (s ? : tmpbuf, L_tmpnam, NULL, NULL, 0))
     return NULL;
 
   if (__gen_tempname (s ? : tmpbuf, 0, 0))
diff --git a/stdio-common/tmpnam_r.c b/stdio-common/tmpnam_r.c
index 07c4650cc0..26214ecf2b 100644
--- a/stdio-common/tmpnam_r.c
+++ b/stdio-common/tmpnam_r.c
@@ -26,7 +26,7 @@ tmpnam_r (char *s)
   if (s == NULL)
     return NULL;
 
-  if (__path_search (s, L_tmpnam, NULL, NULL))
+  if (__path_search (s, L_tmpnam, NULL, NULL, 0))
     return NULL;
   if (__gen_tempname (s, 0, 0))
     return NULL;
diff --git a/stdio-common/tst-tmpnam.c b/stdio-common/tst-tmpnam.c
new file mode 100644
index 0000000000..2a23a14149
--- /dev/null
+++ b/stdio-common/tst-tmpnam.c
@@ -0,0 +1,51 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+  const char *name;
+  int retval = 0;
+
+  /* Set TMPDIR to a value other than the traditional /tmp.  */
+  setenv ("TMPDIR", "/usr", 1);
+
+  name = tmpnam (NULL);
+
+  printf ("name = %s\n", name);
+
+  /* Make sure the name is based on the value in TMPDIR.  */
+  if (strncmp (name, "/usr", 4) == 0)
+    {
+      puts ("error: `tmpnam' used TMPDIR value");
+      retval = 1;
+    }
+
+  /* Test that it is in the directory denoted by P_tmpdir.  */
+  if (strncmp (name, P_tmpdir, sizeof (P_tmpdir) - 1) != 0)
+    {
+      puts ("error: `tmpnam' return value not in P_tmpdir directory");
+      retval = 1;
+    }
+
+  return retval;
+}
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
     {