version 1.72, 2019/05/09 22:44:53 |
version 1.73, 2019/06/28 13:35:05 |
|
|
} |
} |
|
|
if (!devnull) { |
if (!devnull) { |
if ((from_fd = open(from_name, O_RDONLY, 0)) < 0) |
if ((from_fd = open(from_name, O_RDONLY, 0)) == -1) |
err(1, "%s", from_name); |
err(1, "%s", from_name); |
} |
} |
|
|
|
|
* that does not work in-place -- like gnu binutils strip. |
* that does not work in-place -- like gnu binutils strip. |
*/ |
*/ |
close(to_fd); |
close(to_fd); |
if ((to_fd = open(tempfile, O_RDONLY, 0)) < 0) |
if ((to_fd = open(tempfile, O_RDONLY, 0)) == -1) |
err(1, "stripping %s", to_name); |
err(1, "stripping %s", to_name); |
} |
} |
|
|
|
|
struct stat temp_sb; |
struct stat temp_sb; |
|
|
/* Re-open to_fd using the real target name. */ |
/* Re-open to_fd using the real target name. */ |
if ((to_fd = open(to_name, O_RDONLY, 0)) < 0) |
if ((to_fd = open(to_name, O_RDONLY, 0)) == -1) |
err(1, "%s", to_name); |
err(1, "%s", to_name); |
|
|
if (fstat(temp_fd, &temp_sb)) { |
if (fstat(temp_fd, &temp_sb)) { |
|
|
(void)snprintf(backup, PATH_MAX, "%s%s", to_name, |
(void)snprintf(backup, PATH_MAX, "%s%s", to_name, |
suffix); |
suffix); |
/* It is ok for the target file not to exist. */ |
/* It is ok for the target file not to exist. */ |
if (rename(to_name, backup) < 0 && errno != ENOENT) { |
if (rename(to_name, backup) == -1 && errno != ENOENT) { |
serrno = errno; |
serrno = errno; |
unlink(tempfile); |
unlink(tempfile); |
errx(1, "rename: %s to %s: %s", to_name, |
errx(1, "rename: %s to %s: %s", to_name, |
backup, strerror(serrno)); |
backup, strerror(serrno)); |
} |
} |
} |
} |
if (rename(tempfile, to_name) < 0 ) { |
if (rename(tempfile, to_name) == -1 ) { |
serrno = errno; |
serrno = errno; |
unlink(tempfile); |
unlink(tempfile); |
errx(1, "rename: %s to %s: %s", tempfile, |
errx(1, "rename: %s to %s: %s", tempfile, |
|
|
/* |
/* |
* skip, buf is empty so far |
* skip, buf is empty so far |
*/ |
*/ |
if (lseek(fd, (off_t)wcnt, SEEK_CUR) < 0) { |
if (lseek(fd, (off_t)wcnt, SEEK_CUR) == -1) { |
warn("lseek"); |
warn("lseek"); |
return(-1); |
return(-1); |
} |
} |
|
|
/* |
/* |
* move back one byte and write a zero |
* move back one byte and write a zero |
*/ |
*/ |
if (lseek(fd, (off_t)-1, SEEK_CUR) < 0) { |
if (lseek(fd, (off_t)-1, SEEK_CUR) == -1) { |
warn("Failed seek on file"); |
warn("Failed seek on file"); |
return; |
return; |
} |
} |
|
|
if (write(fd, blnk, 1) < 0) |
if (write(fd, blnk, 1) == -1) |
warn("Failed write to file"); |
warn("Failed write to file"); |
return; |
return; |
} |
} |