This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[Patch] Objcopy deletes source file on Windows
- From: Michael Eager <eager at mvista dot com>
- To: binutils at sources dot redhat dot com
- Date: Mon, 12 May 2003 15:28:25 -0700
- Subject: [Patch] Objcopy deletes source file on Windows
- Organization: MontaVista Software, Inc.
When objcopy on Windows is invoked with a single file name, or with two
different file names, it works exactly as on Linux. When invoked with the
same name for source and destination, the source file is deleted.
When objcopy has two file names, it first opens the source file for
reading and the destination file for writing. This implicitly unlinks
the destination file, if it exists. On Linux, an unlink of an open
file doesn't actually remove the file until it is closed. On Windows,
an unlink removes the file immediately.
This patch checks to see if the source and destination have the same
name and, if they are the same, continues as if only one file name was entered.
2003-05-12 Michael Eager <eager@mvista.com>
* objcopy.c: Treat identical src/dst file names as if only one entered.
Index: objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.46
diff -u -r1.46 objcopy.c
--- objcopy.c 24 Mar 2003 16:11:46 -0000 1.46
+++ objcopy.c 12 May 2003 21:35:00 -0000
@@ -2733,9 +2733,10 @@
if (stat (input_filename, & statbuf) < 0)
fatal (_("Cannot stat: %s: %s"), input_filename, strerror (errno));
- /* If there is no destination file then create a temp and rename
- the result into the input. */
- if (output_filename == (char *) NULL)
+ /* If there is no destination file, or the source and destination files
+ are the same, then create a temp and rename the result into the input. */
+ if ((output_filename == (char *) NULL) ||
+ (strcmp(input_filename, output_filename) == 0))
{
char *tmpname = make_tempname (input_filename);
--
Michael Eager eager@mvista.com 408-328-8426
MontaVista Software, Inc. 1237 E. Arques Ave., Sunnyvale, CA 94085