Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/cap_mkdb PR/32591: JuanRP: Also remove the file we a...
details: https://anonhg.NetBSD.org/src/rev/4c9777239de4
branches: trunk
changeset: 785716:4c9777239de4
user: christos <christos%NetBSD.org@localhost>
date: Tue Mar 26 20:58:35 2013 +0000
description:
PR/32591: JuanRP: Also remove the file we are going to be building to prevent
it from being used as input.
diffstat:
usr.bin/cap_mkdb/cap_mkdb.c | 23 ++++++++++++-----------
1 files changed, 12 insertions(+), 11 deletions(-)
diffs (69 lines):
diff -r a57c3ec91ac8 -r 4c9777239de4 usr.bin/cap_mkdb/cap_mkdb.c
--- a/usr.bin/cap_mkdb/cap_mkdb.c Tue Mar 26 20:56:54 2013 +0000
+++ b/usr.bin/cap_mkdb/cap_mkdb.c Tue Mar 26 20:58:35 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cap_mkdb.c,v 1.28 2013/01/23 20:27:01 riastradh Exp $ */
+/* $NetBSD: cap_mkdb.c,v 1.29 2013/03/26 20:58:35 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)cap_mkdb.c 8.2 (Berkeley) 4/27/95";
#endif
-__RCSID("$NetBSD: cap_mkdb.c,v 1.28 2013/01/23 20:27:01 riastradh Exp $");
+__RCSID("$NetBSD: cap_mkdb.c,v 1.29 2013/03/26 20:58:35 christos Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -63,7 +63,7 @@
static DB *capdbp;
static int verbose;
-static char *capname, buf[8 * 1024];
+static char *capname, outfile[MAXPATHLEN];
static HASHINFO openinfo = {
4096, /* bsize */
@@ -126,13 +126,17 @@
* The database file is the first argument if no name is specified.
* Make arrangements to unlink it if exit badly.
*/
- (void)snprintf(buf, sizeof(buf), "%s.db.tmp",
+ (void)snprintf(outfile, sizeof(outfile), "%s.db.tmp",
capname ? capname : *argv);
- if ((capname = strdup(buf)) == NULL)
+ if ((capname = strdup(outfile)) == NULL)
err(1, "strdup");
+ p = strrchr(outfile, '.');
+ assert(p != NULL);
+ *p = '\0';
+ (void)unlink(outfile);
if ((capdbp = dbopen(capname, O_CREAT | O_TRUNC | O_RDWR,
DEFFILEMODE, DB_HASH, &openinfo)) == NULL)
- err(1, "%s", buf);
+ err(1, "%s", outfile);
if (atexit(dounlink))
err(1, "atexit");
@@ -141,10 +145,7 @@
if (capdbp->close(capdbp) < 0)
err(1, "%s", capname);
- p = strrchr(buf, '.');
- assert(p != NULL);
- *p = '\0';
- if (rename(capname, buf) == -1)
+ if (rename(capname, outfile) == -1)
err(1, "rename");
free(capname);
capname = NULL;
@@ -155,7 +156,7 @@
dounlink(void)
{
if (capname != NULL)
- (void)unlink(capname);
+ unlink(capname);
}
/*
Home |
Main Index |
Thread Index |
Old Index