Properly create db files vs. dbm files.
Obtained from: NetBSD
This commit is contained in:
parent
a1d55890a0
commit
13bcc37c02
@ -38,7 +38,7 @@
|
||||
*
|
||||
* %W% (Berkeley) %G%
|
||||
*
|
||||
* $Id: mk-amd-map.c,v 1.1.1.1 1998/08/23 22:07:21 obrien Exp $
|
||||
* $Id: mk-amd-map.c,v 1.2 1998/08/23 22:52:09 obrien Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -51,7 +51,6 @@
|
||||
#include <am_defs.h>
|
||||
|
||||
/* dummy variables */
|
||||
char *progname;
|
||||
char hostname[MAXHOSTNAMELEN];
|
||||
int orig_umask, foreground, debug_flags;
|
||||
pid_t mypid;
|
||||
@ -219,8 +218,8 @@ main(int argc, char *argv[])
|
||||
int rc = 0;
|
||||
DBM *mapd = NULL;
|
||||
static char maptmp[] = "dbmXXXXXX";
|
||||
char maptpag[16], maptdir[16];
|
||||
char *mappag = (char *) NULL, *mapdir = (char *) NULL;
|
||||
char maptdb[16];
|
||||
char *mapdb = (char *) NULL;
|
||||
int len;
|
||||
char *sl;
|
||||
int printit = 0;
|
||||
@ -259,9 +258,8 @@ main(int argc, char *argv[])
|
||||
|
||||
if (!printit) {
|
||||
len = strlen(map);
|
||||
mappag = (char *) malloc(len + 5);
|
||||
mapdir = (char *) malloc(len + 5);
|
||||
if (!mappag || !mapdir) {
|
||||
mapdb = (char *) malloc(len + 4);
|
||||
if (!mapdb) {
|
||||
perror("mk-amd-map: malloc");
|
||||
exit(1);
|
||||
}
|
||||
@ -277,11 +275,10 @@ main(int argc, char *argv[])
|
||||
#endif /* not HAVE_MKSTEMP */
|
||||
|
||||
/* open DBM files */
|
||||
sprintf(maptpag, "%s.pag", maptmp);
|
||||
sprintf(maptdir, "%s.dir", maptmp);
|
||||
if (remove_file(maptpag) < 0 || remove_file(maptdir) < 0) {
|
||||
fprintf(stderr, "Can't remove existing temporary files; %s and", maptpag);
|
||||
perror(maptdir);
|
||||
sprintf(maptdb, "%s.db", maptmp);
|
||||
if (remove_file(maptdb) < 0) {
|
||||
fprintf(stderr, "Can't remove existing temporary files;");
|
||||
perror(maptdb);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@ -301,7 +298,7 @@ main(int argc, char *argv[])
|
||||
int error = read_file(mapf, map, mapd);
|
||||
(void) close(mapfd);
|
||||
(void) fclose(mapf);
|
||||
dbm_close(mapd);
|
||||
dbm_close(mapd);
|
||||
if (printit) {
|
||||
if (error) {
|
||||
fprintf(stderr, "Error creating ndbm map for %s\n", map);
|
||||
@ -313,33 +310,21 @@ main(int argc, char *argv[])
|
||||
fprintf(stderr, "Error reading source file %s\n", map);
|
||||
rc = 1;
|
||||
} else {
|
||||
sprintf(mappag, "%s.pag", map);
|
||||
sprintf(mapdir, "%s.dir", map);
|
||||
if (rename(maptpag, mappag) < 0) {
|
||||
fprintf(stderr, "Couldn't rename %s to ", maptpag);
|
||||
perror(mappag);
|
||||
sprintf(mapdb, "%s.db", map);
|
||||
if (unlink(mapdb) == 0)
|
||||
fprintf(stderr, "WARNING: existing map \"%s.db\" destroyed\n", map);
|
||||
if (rename(maptdb, mapdb) < 0) {
|
||||
fprintf(stderr, "Couldn't rename %s to ", maptdb);
|
||||
perror(mapdb);
|
||||
/* Throw away the temporary map */
|
||||
unlink(maptpag);
|
||||
unlink(maptdir);
|
||||
rc = 1;
|
||||
|
||||
} else if (rename(maptdir, mapdir) < 0) {
|
||||
fprintf(stderr, "Couldn't rename %s to ", maptdir);
|
||||
perror(mapdir);
|
||||
/* Put the .pag file back */
|
||||
rename(mappag, maptpag);
|
||||
/* Throw away remaining part of original map */
|
||||
unlink(mapdir);
|
||||
fprintf(stderr,
|
||||
"WARNING: existing map \"%s.{dir,pag}\" destroyed\n",
|
||||
map);
|
||||
unlink(maptdb);
|
||||
rc = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
fprintf(stderr, "Can't open \"%s.{dir,pag}\" for ", map);
|
||||
fprintf(stderr, "Can't open \"%s.db\" for ", map);
|
||||
perror("writing");
|
||||
rc = 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user