aboutsummaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2002-02-11 02:34:14 +0000
committerAlan Modra <amodra@gmail.com>2002-02-11 02:34:14 +0000
commit4c168fa3f717c107ee6c2927e4adadf513db808c (patch)
tree7d398e8d95c45434eb123b3b6be9ceef463c7396 /binutils/objcopy.c
parent20ae00985d69195b9f777f19fe0c113672ba2f1c (diff)
downloadgdb-4c168fa3f717c107ee6c2927e4adadf513db808c.zip
gdb-4c168fa3f717c107ee6c2927e4adadf513db808c.tar.gz
gdb-4c168fa3f717c107ee6c2927e4adadf513db808c.tar.bz2
* objcopy.c (MKDIR): Define.
(copy_archive): Make name_list.name const. Use MKDIR. Handle duplicate files in archives by making more temp dirs.
Diffstat (limited to 'binutils/objcopy.c')
-rw-r--r--binutils/objcopy.c53
1 files changed, 41 insertions, 12 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 1a819e8..ebdbcca 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1268,6 +1268,13 @@ copy_object (ibfd, obfd)
}
}
+#undef MKDIR
+#if defined (_WIN32) && !defined (__CYGWIN32__)
+#define MKDIR(DIR, MODE) mkdir (DIR)
+#else
+#define MKDIR(DIR, MODE) mkdir (DIR, MODE)
+#endif
+
/* Read each archive element in turn from IBFD, copy the
contents to temp file, and keep the temp file handle. */
@@ -1280,7 +1287,7 @@ copy_archive (ibfd, obfd, output_target)
struct name_list
{
struct name_list *next;
- char *name;
+ const char *name;
bfd *obfd;
} *list, *l;
bfd **ptr = &obfd->archive_head;
@@ -1288,11 +1295,7 @@ copy_archive (ibfd, obfd, output_target)
char *dir = make_tempname (bfd_get_filename (obfd));
/* Make a temp directory to hold the contents. */
-#if defined (_WIN32) && !defined (__CYGWIN32__)
- if (mkdir (dir) != 0)
-#else
- if (mkdir (dir, 0700) != 0)
-#endif
+ if (MKDIR (dir, 0700) != 0)
{
fatal (_("cannot mkdir %s for archive copying (error: %s)"),
dir, strerror (errno));
@@ -1308,14 +1311,35 @@ copy_archive (ibfd, obfd, output_target)
while (!status && this_element != (bfd *) NULL)
{
- /* Create an output file for this member. */
- char *output_name = concat (dir, "/", bfd_get_filename (this_element),
- (char *) NULL);
- bfd *output_bfd = bfd_openw (output_name, output_target);
+ char *output_name;
+ bfd *output_bfd;
bfd *last_element;
struct stat buf;
int stat_status = 0;
+ /* Create an output file for this member. */
+ output_name = concat (dir, "/",
+ bfd_get_filename (this_element), (char *) 0);
+
+ /* If the file already exists, make another temp dir. */
+ if (stat (output_name, &buf) >= 0)
+ {
+ output_name = make_tempname (output_name);
+ if (MKDIR (output_name, 0700) != 0)
+ {
+ fatal (_("cannot mkdir %s for archive copying (error: %s)"),
+ output_name, strerror (errno));
+ }
+ l = (struct name_list *) xmalloc (sizeof (struct name_list));
+ l->name = output_name;
+ l->next = list;
+ l->obfd = NULL;
+ list = l;
+ output_name = concat (output_name, "/",
+ bfd_get_filename (this_element), (char *) 0);
+ }
+
+ output_bfd = bfd_openw (output_name, output_target);
if (preserve_dates)
{
stat_status = bfd_stat_arch_elt (this_element, &buf);
@@ -1371,8 +1395,13 @@ copy_archive (ibfd, obfd, output_target)
/* Delete all the files that we opened. */
for (l = list; l != NULL; l = l->next)
{
- bfd_close (l->obfd);
- unlink (l->name);
+ if (l->obfd == NULL)
+ rmdir (l->name);
+ else
+ {
+ bfd_close (l->obfd);
+ unlink (l->name);
+ }
}
rmdir (dir);
}