Use tmpfile instead of tmpnam

Andreas Jaeger aj@suse.de
Mon Mar 22 09:04:00 GMT 2004


This is some cosmetic to avoid getting a warning about dangerous use
of tmpnam...

Ok to commit?

Andreas

2004-03-21  Andreas Jaeger  <aj@suse.de>

	* misc/tst-mntent.c (main): Use tmpfile instead of tmpnam.

============================================================
Index: misc/tst-mntent.c
--- misc/tst-mntent.c	26 Jul 1999 01:45:55 -0000	1.3
+++ misc/tst-mntent.c	21 Mar 2004 06:43:07 -0000
@@ -11,7 +11,6 @@ main (int argc, char *argv[])
   int result = 0;
   struct mntent mef;
   struct mntent *mnt = &mef;
-  char *name;
   FILE *fp;
 
   mef.mnt_fsname = strdupa ("/dev/hda1");
@@ -29,8 +28,7 @@ main (int argc, char *argv[])
       result = 1;
     }
 
-  name = tmpnam (NULL);
-  fp = fopen (name, "w+");
+  fp = tmpfile ();
   if (fp == NULL)
     {
       printf ("Cannot open temporary file: %m\n");
@@ -75,8 +73,6 @@ main (int argc, char *argv[])
 	  puts ("Error while reading written entry back in");
 	  result = 1;
 	}
-
-      remove (name);
     }
 
   return result;

-- 
 Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj
  SuSE Linux AG, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-hacker/attachments/20040322/f5673924/attachment.sig>


More information about the Libc-hacker mailing list