summaryrefslogtreecommitdiffstats
path: root/usr.sbin/zic
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1997-03-13 18:56:18 +0000
committerbde <bde@FreeBSD.org>1997-03-13 18:56:18 +0000
commitfa9f3fde24d7f306c0508fb89788b286caa3329e (patch)
tree065f00f275474b4f25230fb75848ccf773a2448c /usr.sbin/zic
parent6299b067d045b0a710fe6e9e1d134f1028679c7f (diff)
downloadFreeBSD-src-fa9f3fde24d7f306c0508fb89788b286caa3329e.zip
FreeBSD-src-fa9f3fde24d7f306c0508fb89788b286caa3329e.tar.gz
Remove old output file, if any, before creating the output file, in
case the file is a stale link. Reviewed by: wollman
Diffstat (limited to 'usr.sbin/zic')
-rw-r--r--usr.sbin/zic/zic.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/usr.sbin/zic/zic.c b/usr.sbin/zic/zic.c
index d1b7760..6034b6b 100644
--- a/usr.sbin/zic/zic.c
+++ b/usr.sbin/zic/zic.c
@@ -1423,6 +1423,17 @@ const char * const name;
fullname = erealloc(fullname,
(int) (strlen(directory) + 1 + strlen(name) + 1));
(void) sprintf(fullname, "%s/%s", directory, name);
+
+ /*
+ * Remove old file, if any, to snap links.
+ */
+ if (!itsdir(fullname) && remove(fullname) != 0 && errno != ENOENT) {
+ const char *e = strerror(errno);
+ (void) fprintf(stderr, _("%s: Can't remove %s: %s\n"),
+ progname, fullname, e);
+ (void) exit(EXIT_FAILURE);
+ }
+
if ((fp = fopen(fullname, "wb")) == NULL) {
if (mkdirs(fullname) != 0)
(void) exit(EXIT_FAILURE);
OpenPOWER on IntegriCloud