aboutsummaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2006-10-13 09:43:29 +0000
committerNick Clifton <nickc@redhat.com>2006-10-13 09:43:29 +0000
commitf9c026a85b129328be8ed9ce74f19fc0065454be (patch)
tree399caa063a9877ae0a03737895cb45214ca6a9d2 /binutils/objcopy.c
parentec6e49f44cf16f200634edd04c6e55ab0e2436b0 (diff)
downloadfsf-binutils-gdb-f9c026a85b129328be8ed9ce74f19fc0065454be.zip
fsf-binutils-gdb-f9c026a85b129328be8ed9ce74f19fc0065454be.tar.gz
fsf-binutils-gdb-f9c026a85b129328be8ed9ce74f19fc0065454be.tar.bz2
PR binutils/2876
* configure.in: Check for the mkstemp and mkdtemp functions. * configure: Regenerate. * config.in (HAVE_MKDTEMP): New potential define. (MAKE_MKSTEMP): Likewise. * bucomm.c (make_tempname): Use mkstemp if it is available. * make_tempdir): New function: Create a temporary directory using mkdtemp, if it is available. * bucomm.h (make_tempdir): New prototype. * objcopy.c (copy_archive): Use make_tempdir if it is available. (strip_main): Produce an warning message if a temporary file could not be (copy_main): Likewise. * ar.c (write_archive): Likewise.
Diffstat (limited to 'binutils/objcopy.c')
-rw-r--r--binutils/objcopy.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 9bfb68d..0b2bada 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1764,12 +1764,14 @@ copy_object (bfd *ibfd, bfd *obfd)
return TRUE;
}
+#if ! defined(HAVE_MKDTEMP)
#undef MKDIR
#if defined (_WIN32) && !defined (__CYGWIN32__)
#define MKDIR(DIR, MODE) mkdir (DIR)
#else
#define MKDIR(DIR, MODE) mkdir (DIR, MODE)
#endif
+#endif
/* Read each archive element in turn from IBFD, copy the
contents to temp file, and keep the temp file handle.
@@ -1789,12 +1791,22 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
} *list, *l;
bfd **ptr = &obfd->archive_head;
bfd *this_element;
- char *dir = make_tempname (bfd_get_filename (obfd));
+ char * dir;
/* Make a temp directory to hold the contents. */
+#if defined(HAVE_MKDTEMP)
+ dir = make_tempdir (bfd_get_filename (obfd));
+
+ if (dir == NULL)
+ fatal (_("cannot create tempdir for archive copying (error: %s)"),
+ strerror (errno));
+#else
+ dir = make_tempname (bfd_get_filename (obfd));
+
if (MKDIR (dir, 0700) != 0)
fatal (_("cannot mkdir %s for archive copying (error: %s)"),
dir, strerror (errno));
+#endif
obfd->has_armap = ibfd->has_armap;
@@ -1821,10 +1833,17 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
/* If the file already exists, make another temp dir. */
if (stat (output_name, &buf) >= 0)
{
+#if defined(HAVE_MKDTEMP)
+ output_name = make_tempdir (output_name);
+ if (output_name == NULL)
+ fatal (_("cannot create temporary dir '%s' for archive copying (error: %s)"),
+ output_name, strerror (errno));
+#else
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));
+#endif
l = xmalloc (sizeof (struct name_list));
l->name = output_name;
@@ -2702,6 +2721,14 @@ strip_main (int argc, char *argv[])
else
tmpname = make_tempname (argv[i]);
+ if (tmpname == NULL)
+ {
+ non_fatal (_("could not create temporary file to hold stripped copy of '%s'"),
+ argv[i]);
+ status = 1;
+ continue;
+ }
+
status = 0;
copy_file (argv[i], tmpname, input_target, output_target);
if (status == 0)
@@ -3302,6 +3329,10 @@ copy_main (int argc, char *argv[])
{
char *tmpname = make_tempname (input_filename);
+ if (tmpname == NULL)
+ fatal (_("warning: could not create temporary file whilst copying '%s', (error: %s)"),
+ input_filename, strerror (errno));
+
copy_file (input_filename, tmpname, input_target, output_target);
if (status == 0)
{