aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-04-15 01:33:13 +0930
committerAlan Modra <amodra@gmail.com>2021-04-15 14:16:55 +0930
commitd0ecdcddc363ad7f05fc50cf1eee4028fa7f8964 (patch)
tree2c075eb545457086b9749fbdeae5d28b9b62cda0 /binutils
parentddfe525f2875e76e0c32ff348fc0d3d6aa5fb4a3 (diff)
downloadfsf-binutils-gdb-d0ecdcddc363ad7f05fc50cf1eee4028fa7f8964.zip
fsf-binutils-gdb-d0ecdcddc363ad7f05fc50cf1eee4028fa7f8964.tar.gz
fsf-binutils-gdb-d0ecdcddc363ad7f05fc50cf1eee4028fa7f8964.tar.bz2
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')
-rw-r--r--binutils/ChangeLog7
-rw-r--r--binutils/objcopy.c13
-rw-r--r--binutils/rename.c15
3 files changed, 22 insertions, 13 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index b109e3e..f8a74d1 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,10 @@
+2021-04-15 Alan Modra <amodra@gmail.com>
+
+ 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.
+
2021-04-14 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/27708
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 3b6a7e5..946802e 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -4864,10 +4864,9 @@ strip_main (int argc, char *argv[])
output_target, NULL);
if (status == 0)
{
- if (output_file != tmpname)
- status = smart_rename (tmpname,
- output_file ? output_file : argv[i],
- copyfd, &statbuf, preserve_dates) != 0;
+ const char *oname = output_file ? output_file : argv[i];
+ status = smart_rename (tmpname, oname, copyfd,
+ &statbuf, preserve_dates) != 0;
if (status == 0)
status = hold_status;
}
@@ -5949,9 +5948,9 @@ copy_main (int argc, char *argv[])
output_target, input_arch);
if (status == 0)
{
- if (tmpname != output_filename)
- status = smart_rename (tmpname, input_filename, copyfd,
- &statbuf, preserve_dates) != 0;
+ const char *oname = output_filename ? output_filename : input_filename;
+ status = smart_rename (tmpname, oname, copyfd,
+ &statbuf, preserve_dates) != 0;
}
else
{
diff --git a/binutils/rename.c b/binutils/rename.c
index 9746ef3..969acc1 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;
}