summary refs log tree commit diff
path: root/stdio-common
diff options
context:
space:
mode:
Diffstat (limited to 'stdio-common')
-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
7 files changed, 58 insertions, 6 deletions
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;
+}