summaryrefslogtreecommitdiff
path: root/gnu/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin')
-rw-r--r--gnu/usr.bin/binutils/binutils/ar.c2
-rw-r--r--gnu/usr.bin/binutils/binutils/bucomm.c40
-rw-r--r--gnu/usr.bin/binutils/binutils/bucomm.h2
-rw-r--r--gnu/usr.bin/binutils/binutils/objcopy.c16
4 files changed, 43 insertions, 17 deletions
diff --git a/gnu/usr.bin/binutils/binutils/ar.c b/gnu/usr.bin/binutils/binutils/ar.c
index d67f4b37929..7bc03d5fe24 100644
--- a/gnu/usr.bin/binutils/binutils/ar.c
+++ b/gnu/usr.bin/binutils/binutils/ar.c
@@ -1064,7 +1064,7 @@ write_archive (iarch)
old_name = xmalloc (strlen (bfd_get_filename (iarch)) + 1);
strcpy (old_name, bfd_get_filename (iarch));
- new_name = make_tempname (old_name);
+ new_name = make_tempname (old_name, 0);
output_filename = new_name;
diff --git a/gnu/usr.bin/binutils/binutils/bucomm.c b/gnu/usr.bin/binutils/binutils/bucomm.c
index 76ffa60a172..09f29b7bd0e 100644
--- a/gnu/usr.bin/binutils/binutils/bucomm.c
+++ b/gnu/usr.bin/binutils/binutils/bucomm.c
@@ -208,17 +208,20 @@ print_arelt_descr (file, abfd, verbose)
/* Return the name of a temporary file in the same directory as FILENAME. */
char *
-make_tempname (filename)
+make_tempname (filename, isdir)
char *filename;
+ int isdir;
{
static char template[] = "stXXXXXX";
char *tmpname;
char *slash = strrchr (filename, '/');
+ char c;
#ifdef HAVE_DOS_BASED_FILE_SYSTEM
{
/* We could have foo/bar\\baz, or foo\\bar, or d:bar. */
char *bslash = strrchr (filename, '\\');
+
if (bslash > slash)
slash = bslash;
if (slash == NULL && filename[0] != '\0' && filename[1] == ':')
@@ -228,8 +231,6 @@ make_tempname (filename)
if (slash != (char *) NULL)
{
- char c;
-
c = *slash;
*slash = 0;
tmpname = xmalloc (strlen (filename) + sizeof (template) + 2);
@@ -243,15 +244,44 @@ make_tempname (filename)
#endif
strcat (tmpname, "/");
strcat (tmpname, template);
- mktemp (tmpname);
- *slash = c;
}
else
{
tmpname = xmalloc (sizeof (template));
strcpy (tmpname, template);
+ }
+
+ if (isdir)
+ {
+#ifdef HAVE_MKDTEMP
+ if (mkdtemp (tmpname) != (char *) NULL)
+#else
+ mktemp (tmpname);
+#if defined (_WIN32) && !defined (__CYGWIN32__)
+ if (mkdir (tmpname) != 0)
+#else
+ if (mkdir (tmpname, 0700) != 0)
+#endif
+#endif
+ tmpname = NULL;
+ }
+ else
+ {
+ int fd;
+
+#ifdef HAVE_MKSTEMP
+ fd = mkstemp (tmpname);
+ if (fd == -1)
+ tmpname = NULL;
+ else
+ close (fd);
+#else
mktemp (tmpname);
+#endif
}
+ if (slash != (char *) NULL)
+ *slash = c;
+
return tmpname;
}
diff --git a/gnu/usr.bin/binutils/binutils/bucomm.h b/gnu/usr.bin/binutils/binutils/bucomm.h
index c6dc26a1f09..fd6a1516adf 100644
--- a/gnu/usr.bin/binutils/binutils/bucomm.h
+++ b/gnu/usr.bin/binutils/binutils/bucomm.h
@@ -167,7 +167,7 @@ void list_supported_targets PARAMS ((const char *, FILE *));
void print_arelt_descr PARAMS ((FILE *file, bfd *abfd, boolean verbose));
-char *make_tempname PARAMS ((char *));
+char *make_tempname PARAMS ((char *, int));
bfd_vma parse_vma PARAMS ((const char *, const char *));
diff --git a/gnu/usr.bin/binutils/binutils/objcopy.c b/gnu/usr.bin/binutils/binutils/objcopy.c
index 10b20e4b81d..72704096a9b 100644
--- a/gnu/usr.bin/binutils/binutils/objcopy.c
+++ b/gnu/usr.bin/binutils/binutils/objcopy.c
@@ -1071,17 +1071,13 @@ copy_archive (ibfd, obfd, output_target)
} *list, *l;
bfd **ptr = &obfd->archive_head;
bfd *this_element;
- char *dir = make_tempname (bfd_get_filename (obfd));
+ char *dir = make_tempname (bfd_get_filename (obfd), 1);
/* 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 (dir == (char *) NULL)
{
- fatal (_("cannot mkdir %s for archive copying (error: %s)"),
- dir, strerror (errno));
+ fatal (_("cannot make temp directory for archive copying (error: %s)"),
+ strerror (errno));
}
obfd->has_armap = ibfd->has_armap;
@@ -1760,7 +1756,7 @@ strip_main (argc, argv)
if (output_file != NULL)
tmpname = output_file;
else
- tmpname = make_tempname (argv[i]);
+ tmpname = make_tempname (argv[i], 0);
status = 0;
copy_file (argv[i], tmpname, input_target, output_target);
@@ -2165,7 +2161,7 @@ copy_main (argc, argv)
if (output_filename == (char *) NULL)
{
- char *tmpname = make_tempname (input_filename);
+ char *tmpname = make_tempname (input_filename, 0);
copy_file (input_filename, tmpname, input_target, output_target);
if (status == 0)