projects
/
u
/
mdw
/
catacomb
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d7e6bc6
)
Fix segfault in retagging.
author
mdw
<mdw>
Wed, 5 Oct 2005 09:40:35 +0000
(09:40 +0000)
committer
mdw
<mdw>
Wed, 5 Oct 2005 09:40:35 +0000
(09:40 +0000)
keyutil.c
patch
|
blob
|
blame
|
history
diff --git
a/keyutil.c
b/keyutil.c
index
6146ae4
..
269a85d
100644
(file)
--- a/
keyutil.c
+++ b/
keyutil.c
@@
-1166,7
+1166,9
@@
static int cmd_add(int argc, char *argv[])
int err;
key *kk;
if (k.f & f_retag) {
int err;
key *kk;
if (k.f & f_retag) {
- if ((kk = key_bytag(&f, tag)) != 0 && strcmp(kk->tag, tag) == 0)
+ if ((kk = key_bytag(&f, tag)) != 0 &&
+ kk->tag &&
+ strcmp(kk->tag, tag) == 0)
key_settag(&f, kk, 0);
}
if ((err = key_settag(&f, k.k, tag)) != 0)
key_settag(&f, kk, 0);
}
if ((err = key_settag(&f, k.k, tag)) != 0)
@@
-1929,6
+1931,8
@@
static int cmd_extract(int argc, char *argv[])
int i;
int rc = 0;
key_filter kf = { 0, 0 };
int i;
int rc = 0;
key_filter kf = { 0, 0 };
+ dstr d = DSTR_INIT;
+ const char *outfile = 0;
FILE *fp;
for (;;) {
FILE *fp;
for (;;) {
@@
-1957,9
+1961,13
@@
static int cmd_extract(int argc, char *argv[])
die(EXIT_FAILURE, "Usage: extract [-f FILTER] FILE [TAG...]");
if (strcmp(*argv, "-") == 0)
fp = stdout;
die(EXIT_FAILURE, "Usage: extract [-f FILTER] FILE [TAG...]");
if (strcmp(*argv, "-") == 0)
fp = stdout;
- else if (!(fp = fopen(*argv, "w"))) {
- die(EXIT_FAILURE, "couldn't open `%s' for writing: %s",
- *argv, strerror(errno));
+ else {
+ outfile = *argv;
+ dstr_putf(&d, "%s.new", outfile);
+ if (!(fp = fopen(d.buf, "w"))) {
+ die(EXIT_FAILURE, "couldn't open `%s' for writing: %s",
+ d.buf, strerror(errno));
+ }
}
doopen(&f, KOPEN_READ);
}
doopen(&f, KOPEN_READ);
@@
-1978,8
+1986,9
@@
static int cmd_extract(int argc, char *argv[])
}
}
}
}
}
}
- if (fclose(fp))
+ if (fclose(fp)
|| (outfile && rename(d.buf, outfile))
)
die(EXIT_FAILURE, "error writing file: %s", strerror(errno));
die(EXIT_FAILURE, "error writing file: %s", strerror(errno));
+ dstr_destroy(&d);
doclose(&f);
return (rc);
}
doclose(&f);
return (rc);
}