Browse Source

tmpnam, tempnam are obsolete in SUSV4

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Bernhard Reutner-Fischer 12 years ago
parent
commit
7c721d31e4

+ 5 - 3
include/stdio.h

@@ -114,7 +114,7 @@ typedef __STDIO_fpos64_t fpos64_t;
 
 
 
 
 #if defined __USE_SVID || defined __USE_XOPEN
 #if defined __USE_SVID || defined __USE_XOPEN
-/* Default path prefix for `tempnam' and `tmpnam'.  */
+/* Default path prefix for `mkstemp'.  */
 # define P_tmpdir	"/tmp"
 # define P_tmpdir	"/tmp"
 #endif
 #endif
 
 
@@ -173,18 +173,20 @@ extern FILE *__REDIRECT (tmpfile, (void), tmpfile64) __wur;
 extern FILE *tmpfile64 (void) __wur;
 extern FILE *tmpfile64 (void) __wur;
 #endif
 #endif
 
 
+#ifdef __UCLIBC_SUSV4_LEGACY__
 /* Generate a temporary filename.  */
 /* Generate a temporary filename.  */
 extern char *tmpnam (char *__s) __THROW __wur;
 extern char *tmpnam (char *__s) __THROW __wur;
+#endif
 __END_NAMESPACE_STD
 __END_NAMESPACE_STD
 
 
-#ifdef __USE_MISC
+#if defined __USE_MISC && defined __UCLIBC_SUSV4_LEGACY__
 /* This is the reentrant variant of `tmpnam'.  The only difference is
 /* This is the reentrant variant of `tmpnam'.  The only difference is
    that it does not allow S to be NULL.  */
    that it does not allow S to be NULL.  */
 extern char *tmpnam_r (char *__s) __THROW __wur;
 extern char *tmpnam_r (char *__s) __THROW __wur;
 #endif
 #endif
 
 
 
 
-#if defined __USE_SVID || defined __USE_XOPEN
+#if (defined __USE_SVID || defined __USE_XOPEN) && defined __UCLIBC_SUSV4_LEGACY__
 /* Generate a unique temporary filename using up to five characters of PFX
 /* Generate a unique temporary filename using up to five characters of PFX
    if it is not NULL.  The directory to put this file in is searched for
    if it is not NULL.  The directory to put this file in is searched for
    as follows: First the environment variable "TMPDIR" is checked.
    as follows: First the environment variable "TMPDIR" is checked.

+ 4 - 1
libc/stdio/Makefile.in

@@ -18,11 +18,14 @@ CSRC := \
 	setlinebuf.c setvbuf.c ungetc.c \
 	setlinebuf.c setvbuf.c ungetc.c \
 	printf.c vprintf.c vsprintf.c fprintf.c snprintf.c dprintf.c \
 	printf.c vprintf.c vsprintf.c fprintf.c snprintf.c dprintf.c \
 	asprintf.c sprintf.c vasprintf.c vdprintf.c vsnprintf.c \
 	asprintf.c sprintf.c vasprintf.c vdprintf.c vsnprintf.c \
-	tmpfile.c tmpnam.c tmpnam_r.c popen.c tempnam.c ctermid.c
+	tmpfile.c popen.c ctermid.c
 
 
 ifeq ($(UCLIBC_HAS_LFS),y)
 ifeq ($(UCLIBC_HAS_LFS),y)
 CSRC += fgetpos64.c fopen64.c freopen64.c fseeko64.c fsetpos64.c ftello64.c
 CSRC += fgetpos64.c fopen64.c freopen64.c fseeko64.c fsetpos64.c ftello64.c
 endif
 endif
+ifeq ($(UCLIBC_SUSV4_LEGACY),y)
+CSRC += tmpnam.c tmpnam_r.c tempnam.c
+endif
 
 
 # getc -> alias for fgetc
 # getc -> alias for fgetc
 # putc -> alias for fputc
 # putc -> alias for fputc

+ 1 - 0
libc/stdio/tempnam.c

@@ -42,3 +42,4 @@ tempnam (const char *dir, const char *pfx)
   return strdup (buf);
   return strdup (buf);
 }
 }
 
 
+link_warning (tempnam, "the use of OBSOLESCENT `tempnam' is discouraged, use `mkstemp'")

+ 1 - 2
libc/stdio/tmpnam.c

@@ -50,5 +50,4 @@ tmpnam (char *s)
   return s;
   return s;
 }
 }
 
 
-link_warning (tmpnam,
-	      "the use of `tmpnam' is dangerous, better use `mkstemp'")
+link_warning (tmpnam, "the use of `tmpnam' is dangerous, better use `mkstemp'")

+ 1 - 0
libc/stdio/tmpnam_r.c

@@ -33,3 +33,4 @@ char * tmpnam_r (char *s)
 
 
     return s;
     return s;
 }
 }
+link_warning (tmpnam_r, "the use of OBSOLESCENT `tmpnam_r' is discouraged, use `mkstemp'")

+ 2 - 0
libc/sysdeps/linux/arm/aeabi_lcsts.c

@@ -79,7 +79,9 @@ eabi_constant (BUFSIZ);
 eabi_constant (FOPEN_MAX);
 eabi_constant (FOPEN_MAX);
 eabi_constant (TMP_MAX);
 eabi_constant (TMP_MAX);
 eabi_constant (FILENAME_MAX);
 eabi_constant (FILENAME_MAX);
+#ifdef __UCLIBC_SUSV4_LEGACY__
 eabi_constant (L_tmpnam);
 eabi_constant (L_tmpnam);
+#endif
 
 
 FILE *__aeabi_stdin attribute_hidden;
 FILE *__aeabi_stdin attribute_hidden;
 FILE *__aeabi_stdout attribute_hidden;
 FILE *__aeabi_stdout attribute_hidden;

+ 3 - 1
libc/sysdeps/linux/common/bits/stdio_lim.h

@@ -21,7 +21,9 @@
 #endif
 #endif
 
 
 #ifdef _STDIO_H
 #ifdef _STDIO_H
-# define L_tmpnam 20
+# ifdef __UCLIBC_SUSV4_LEGACY__
+#  define L_tmpnam 20
+# endif
 # define TMP_MAX 238328
 # define TMP_MAX 238328
 # define FILENAME_MAX 4095
 # define FILENAME_MAX 4095
 
 

+ 1 - 3
test/misc/bug-glob1.c

@@ -32,9 +32,7 @@ prepare (int argc, char *argv[])
  again:
  again:
   strcpy (stpcpy (fname, argv[1]), ext);
   strcpy (stpcpy (fname, argv[1]), ext);
 
 
-/*
-  fname = mktemp (fname);
-*/
+/* fname = mktemp (fname); */
   close(mkstemp(fname));
   close(mkstemp(fname));
   unlink(fname);
   unlink(fname);
 
 

+ 32 - 16
test/nptl/tst-cancel4.c

@@ -978,6 +978,7 @@ tf_pause (void *arg)
 static void *
 static void *
 tf_accept (void *arg)
 tf_accept (void *arg)
 {
 {
+  int tfd;
   struct sockaddr_un sun;
   struct sockaddr_un sun;
   /* To test a non-blocking accept call we make the call file by using
   /* To test a non-blocking accept call we make the call file by using
      a datagrame socket.  */
      a datagrame socket.  */
@@ -999,12 +1000,13 @@ tf_accept (void *arg)
 	}
 	}
 
 
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
-      if (mktemp (sun.sun_path) == NULL)
+      tfd = mkstemp(sun.sun_path);
+      if (tfd < 0)
 	{
 	{
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  exit (1);
 	  exit (1);
 	}
 	}
-
+      close(tfd);
       sun.sun_family = AF_UNIX;
       sun.sun_family = AF_UNIX;
     }
     }
   while (bind (tempfd, (struct sockaddr *) &sun,
   while (bind (tempfd, (struct sockaddr *) &sun,
@@ -1049,6 +1051,7 @@ tf_accept (void *arg)
 static void *
 static void *
 tf_send (void *arg)
 tf_send (void *arg)
 {
 {
+  int tfd;
   struct sockaddr_un sun;
   struct sockaddr_un sun;
 
 
   tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
   tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
@@ -1067,12 +1070,13 @@ tf_send (void *arg)
 	}
 	}
 
 
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
-      if (mktemp (sun.sun_path) == NULL)
+      tfd = mkstemp(sun.sun_path);
+      if (tfd < 0)
 	{
 	{
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  exit (1);
 	  exit (1);
 	}
 	}
-
+      close(tfd);
       sun.sun_family = AF_UNIX;
       sun.sun_family = AF_UNIX;
     }
     }
   while (bind (tempfd, (struct sockaddr *) &sun,
   while (bind (tempfd, (struct sockaddr *) &sun,
@@ -1131,6 +1135,7 @@ tf_send (void *arg)
 static void *
 static void *
 tf_recv (void *arg)
 tf_recv (void *arg)
 {
 {
+  int tfd;
   struct sockaddr_un sun;
   struct sockaddr_un sun;
 
 
   tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
   tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
@@ -1149,12 +1154,13 @@ tf_recv (void *arg)
 	}
 	}
 
 
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
-      if (mktemp (sun.sun_path) == NULL)
+      tfd = mkstemp(sun.sun_path);
+      if (tfd < 0)
 	{
 	{
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  exit (1);
 	  exit (1);
 	}
 	}
-
+      close(tfd);
       sun.sun_family = AF_UNIX;
       sun.sun_family = AF_UNIX;
     }
     }
   while (bind (tempfd, (struct sockaddr *) &sun,
   while (bind (tempfd, (struct sockaddr *) &sun,
@@ -1212,6 +1218,7 @@ tf_recv (void *arg)
 static void *
 static void *
 tf_recvfrom (void *arg)
 tf_recvfrom (void *arg)
 {
 {
+  int tfd;
   struct sockaddr_un sun;
   struct sockaddr_un sun;
 
 
   tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
   tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
@@ -1230,12 +1237,13 @@ tf_recvfrom (void *arg)
 	}
 	}
 
 
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
-      if (mktemp (sun.sun_path) == NULL)
+      tfd = mkstemp(sun.sun_path);
+      if (tfd < 0)
 	{
 	{
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  exit (1);
 	  exit (1);
 	}
 	}
-
+      close(tfd);
       sun.sun_family = AF_UNIX;
       sun.sun_family = AF_UNIX;
     }
     }
   while (bind (tempfd, (struct sockaddr *) &sun,
   while (bind (tempfd, (struct sockaddr *) &sun,
@@ -1287,6 +1295,7 @@ tf_recvfrom (void *arg)
 static void *
 static void *
 tf_recvmsg (void *arg)
 tf_recvmsg (void *arg)
 {
 {
+  int tfd;
   struct sockaddr_un sun;
   struct sockaddr_un sun;
 
 
   tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
   tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
@@ -1305,12 +1314,13 @@ tf_recvmsg (void *arg)
 	}
 	}
 
 
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
-      if (mktemp (sun.sun_path) == NULL)
+      tfd = mkstemp(sun.sun_path);
+      if (tfd < 0)
 	{
 	{
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  exit (1);
 	  exit (1);
 	}
 	}
-
+      close(tfd);
       sun.sun_family = AF_UNIX;
       sun.sun_family = AF_UNIX;
     }
     }
   while (bind (tempfd, (struct sockaddr *) &sun,
   while (bind (tempfd, (struct sockaddr *) &sun,
@@ -1663,6 +1673,7 @@ tf_msync (void *arg)
 static void *
 static void *
 tf_sendto (void *arg)
 tf_sendto (void *arg)
 {
 {
+  int tfd;
   if (arg == NULL)
   if (arg == NULL)
     // XXX If somebody can provide a portable test case in which sendto()
     // XXX If somebody can provide a portable test case in which sendto()
     // blocks we can enable this test to run in both rounds.
     // blocks we can enable this test to run in both rounds.
@@ -1686,12 +1697,13 @@ tf_sendto (void *arg)
 	}
 	}
 
 
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
-      if (mktemp (sun.sun_path) == NULL)
+      tfd = mkstemp(sun.sun_path);
+      if (tfd < 0)
 	{
 	{
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  exit (1);
 	  exit (1);
 	}
 	}
-
+      close(tfd);
       sun.sun_family = AF_UNIX;
       sun.sun_family = AF_UNIX;
     }
     }
   while (bind (tempfd, (struct sockaddr *) &sun,
   while (bind (tempfd, (struct sockaddr *) &sun,
@@ -1739,6 +1751,7 @@ tf_sendto (void *arg)
 static void *
 static void *
 tf_sendmsg (void *arg)
 tf_sendmsg (void *arg)
 {
 {
+  int tfd;
   if (arg == NULL)
   if (arg == NULL)
     // XXX If somebody can provide a portable test case in which sendmsg()
     // XXX If somebody can provide a portable test case in which sendmsg()
     // blocks we can enable this test to run in both rounds.
     // blocks we can enable this test to run in both rounds.
@@ -1762,12 +1775,13 @@ tf_sendmsg (void *arg)
 	}
 	}
 
 
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
-      if (mktemp (sun.sun_path) == NULL)
+      tfd = mkstemp(sun.sun_path);
+      if (tfd < 0)
 	{
 	{
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  exit (1);
 	  exit (1);
 	}
 	}
-
+      close(tfd);
       sun.sun_family = AF_UNIX;
       sun.sun_family = AF_UNIX;
     }
     }
   while (bind (tempfd, (struct sockaddr *) &sun,
   while (bind (tempfd, (struct sockaddr *) &sun,
@@ -1859,6 +1873,7 @@ tf_creat (void *arg)
 static void *
 static void *
 tf_connect (void *arg)
 tf_connect (void *arg)
 {
 {
+  int tfd;
   if (arg == NULL)
   if (arg == NULL)
     // XXX If somebody can provide a portable test case in which connect()
     // XXX If somebody can provide a portable test case in which connect()
     // blocks we can enable this test to run in both rounds.
     // blocks we can enable this test to run in both rounds.
@@ -1882,12 +1897,13 @@ tf_connect (void *arg)
 	}
 	}
 
 
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
       strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
-      if (mktemp (sun.sun_path) == NULL)
+      tfd = mkstemp(sun.sun_path);
+      if (tfd < 0)
 	{
 	{
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
 	  exit (1);
 	  exit (1);
 	}
 	}
-
+      close(tfd);
       sun.sun_family = AF_UNIX;
       sun.sun_family = AF_UNIX;
     }
     }
   while (bind (tempfd, (struct sockaddr *) &sun,
   while (bind (tempfd, (struct sockaddr *) &sun,

+ 15 - 3
test/stdlib/test-canon2.c

@@ -40,6 +40,7 @@ void
 do_prepare (int argc, char *argv[])
 do_prepare (int argc, char *argv[])
 {
 {
   size_t test_dir_len;
   size_t test_dir_len;
+  int tfd;
 
 
   test_dir_len = strlen (test_dir);
   test_dir_len = strlen (test_dir);
 
 
@@ -48,9 +49,20 @@ do_prepare (int argc, char *argv[])
   mempcpy (mempcpy (name1, test_dir, test_dir_len),
   mempcpy (mempcpy (name1, test_dir, test_dir_len),
 	   "/canonXXXXXX", sizeof ("/canonXXXXXX"));
 	   "/canonXXXXXX", sizeof ("/canonXXXXXX"));
   name2 = strdup (name1);
   name2 = strdup (name1);
-
-  add_temp_file (mktemp (name1));
-  add_temp_file (mktemp (name2));
+  tfd = mkstemp(name1);
+  if (tfd < 0) {
+	  printf("%s: cannot generate temp file name\n", __FUNCTION__);
+	  exit(1);
+  }
+  close(tfd);
+  add_temp_file (name1);
+  tfd = mkstemp(name2);
+  if (tfd < 0) {
+	  printf("%s: cannot generate temp file name\n", __FUNCTION__);
+	  exit(1);
+  }
+  close(tfd);
+  add_temp_file (name2);
 }
 }
 
 
 
 

+ 0 - 22
test/test-skeleton.c

@@ -87,28 +87,6 @@ add_temp_file (const char *name)
     }
     }
 }
 }
 
 
-#if defined __UCLIBC__ && !defined __UCLIBC_SUSV3_LEGACY__
-/* mktemp() isn't available, so fake it with tempnam().
-   We make a lot of assumptions about the format of the
-   "template" name, but we aren't testing that, so eh.  */
-__attribute__ ((unused))
-static char *mktemp(char *template)
-{
-  char *dir, *pfx, *s;
-
-  dir = strdup (template);
-  pfx = strrchr (dir, '/');
-  *pfx++ = '\0';
-  s = strstr (pfx, "XXXXXX");
-  *s = '\0';
-
-  s = tempnam (dir, pfx);
-  strcpy (template, s);
-  free (s);
-  return template;
-}
-#endif
-
 /* Delete all temporary files.  */
 /* Delete all temporary files.  */
 static void
 static void
 delete_temp_files (void)
 delete_temp_files (void)