From: tholo Date: Tue, 24 Dec 1996 03:44:13 +0000 (+0000) Subject: Use mkstemp(3) for temporary files X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d1e563742d67b0c45627579be4624ca4092548b7;p=openbsd Use mkstemp(3) for temporary files --- diff --git a/bin/pax/tables.c b/bin/pax/tables.c index 9a7d6dba430..ec9b8ae08bf 100644 --- a/bin/pax/tables.c +++ b/bin/pax/tables.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tables.c,v 1.4 1996/08/27 03:53:16 tholo Exp $ */ +/* $OpenBSD: tables.c,v 1.5 1996/12/24 03:44:13 tholo Exp $ */ /* $NetBSD: tables.c,v 1.4 1995/03/21 09:07:45 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)tables.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: tables.c,v 1.4 1996/08/27 03:53:16 tholo Exp $"; +static char rcsid[] = "$OpenBSD: tables.c,v 1.5 1996/12/24 03:44:13 tholo Exp $"; #endif #endif /* not lint */ @@ -377,16 +377,15 @@ ftime_start() * get random name and create temporary scratch file, unlink name * so it will get removed on exit */ - if ((pt = tempnam((char *)NULL, (char *)NULL)) == NULL) - return(-1); - (void)unlink(pt); - - if ((ffd = open(pt, O_RDWR | O_CREAT, S_IRWXU)) < 0) { - syswarn(1, errno, "Unable to open temporary file: %s", pt); + pt = strdup("/tmp/paxXXXXXX"); + if ((ffd = mkstemp(pt)) < 0) { + syswarn(1, errno, "Unable to create temporary file: %s", pt); + free(pt); return(-1); } - (void)unlink(pt); + free(pt); + return(0); } @@ -1218,18 +1217,18 @@ dir_start() if (dirfd != -1) return(0); - if ((pt = tempnam((char *)NULL, (char *)NULL)) == NULL) - return(-1); /* * unlink the file so it goes away at termination by itself */ - (void)unlink(pt); - if ((dirfd = open(pt, O_RDWR|O_CREAT, 0600)) >= 0) { + pt = strdup("/tmp/paxXXXXXX"); + if ((dirfd = mkstemp(pt)) >= 0) { (void)unlink(pt); + free(pt); return(0); } paxwarn(1, "Unable to create temporary file for directory times: %s", pt); + free(pt); return(-1); }