}
}
+#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. */
struct name_list
{
struct name_list *next;
- char *name;
+ const char *name;
bfd *obfd;
} *list, *l;
bfd **ptr = &obfd->archive_head;
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));
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);
/* 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);
}