* 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.
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>
# 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));
extern void __libc_fatal __P ((__const char *__message))
__attribute__ ((__noreturn__));
-
+
#endif
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)
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
{
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))
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)
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)
/* 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))
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;
--- /dev/null
+/* 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;
+}
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;
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
{