1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-04 09:09:56 +00:00

Remove old output file, if any, before creating the output file, in

case the file is a stale link.

Reviewed by:	wollman
This commit is contained in:
Bruce Evans 1997-03-13 18:56:18 +00:00
parent 5cf816c239
commit 45d1562d43
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=23859

View File

@ -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);