diff options
author | Alan Modra <amodra@gmail.com> | 2021-04-15 01:33:13 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-04-15 14:16:55 +0930 |
commit | d0ecdcddc363ad7f05fc50cf1eee4028fa7f8964 (patch) | |
tree | 2c075eb545457086b9749fbdeae5d28b9b62cda0 /binutils/rename.c | |
parent | ddfe525f2875e76e0c32ff348fc0d3d6aa5fb4a3 (diff) | |
download | binutils-gdb-d0ecdcddc363ad7f05fc50cf1eee4028fa7f8964.tar.gz |
Make objcopy -p work when an output file is specified
More fallout from the PR27456 fixes.
PR 27456
* rename.c (smart_rename): When TO and FROM are equal, just set
file timestamp.
* objcopy.c (strip_main, copy_main): Always call smart_rename.
Diffstat (limited to 'binutils/rename.c')
-rw-r--r-- | binutils/rename.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/binutils/rename.c b/binutils/rename.c index 9746ef394e1..969acc12b30 100644 --- a/binutils/rename.c +++ b/binutils/rename.c @@ -129,16 +129,19 @@ int smart_rename (const char *from, const char *to, int fromfd, struct stat *target_stat, bool preserve_dates) { - int ret; + int ret = 0; - ret = simple_copy (fromfd, to, target_stat); - if (ret != 0) - non_fatal (_("unable to copy file '%s'; reason: %s"), - to, strerror (errno)); + if (to != from) + { + ret = simple_copy (fromfd, to, target_stat); + if (ret != 0) + non_fatal (_("unable to copy file '%s'; reason: %s"), + to, strerror (errno)); + unlink (from); + } if (preserve_dates) set_times (to, target_stat); - unlink (from); return ret; } |