diff options
author | Marc Espie <espie@cvs.openbsd.org> | 1999-09-14 14:20:13 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 1999-09-14 14:20:13 +0000 |
commit | 515b8955925db61fc4fa757cb0d21097fcb584d7 (patch) | |
tree | 375ce3fa7148700229d3bb4fb82c92740929434d | |
parent | 77d8dc8883c5762fdca86d89abafc3576c340357 (diff) |
Kill remaining instances of mktemp, direct and indirect.
-rw-r--r-- | gnu/usr.bin/binutils/binutils/bucomm.c | 44 | ||||
-rw-r--r-- | gnu/usr.bin/binutils/binutils/bucomm.h | 1 | ||||
-rw-r--r-- | gnu/usr.bin/binutils/binutils/nlmconv.c | 8 | ||||
-rw-r--r-- | gnu/usr.bin/binutils/binutils/objcopy.c | 8 | ||||
-rw-r--r-- | gnu/usr.bin/binutils/binutils/objdump.c | 4 | ||||
-rw-r--r-- | gnu/usr.bin/binutils/include/libiberty.h | 5 |
6 files changed, 52 insertions, 18 deletions
diff --git a/gnu/usr.bin/binutils/binutils/bucomm.c b/gnu/usr.bin/binutils/binutils/bucomm.c index 59b13229ffb..cc156bea650 100644 --- a/gnu/usr.bin/binutils/binutils/bucomm.c +++ b/gnu/usr.bin/binutils/binutils/bucomm.c @@ -165,13 +165,15 @@ print_arelt_descr (file, abfd, verbose) fprintf (file, "%s\n", bfd_get_filename (abfd)); } -/* Return the name of a temporary file in the same directory as FILENAME. */ +/* Return the name of a created temporary file in the same directory as + FILENAME. */ char * make_tempname (filename) char *filename; { - static char template[] = "stXXXXXX"; + static char template[] = "stXXXXXXXXXX"; + int fd; char *tmpname; char *slash = strrchr (filename, '/'); @@ -182,14 +184,48 @@ make_tempname (filename) strcpy (tmpname, filename); strcat (tmpname, "/"); strcat (tmpname, template); - mktemp (tmpname); + fd = mkstemp (tmpname); *slash = '/'; } else { tmpname = xmalloc (sizeof (template)); strcpy (tmpname, template); - mktemp (tmpname); + fd = mkstemp (tmpname); + } + if (fd == -1) + return NULL; + else + close(fd); + return tmpname; +} + +/* Return the name of a created temporary dir in the same directory as + FILENAME. */ + +char * +make_tempdir (filename) + char *filename; +{ + static char template[] = "stXXXXXXXXXX"; + char *tmpname; + char *slash = strrchr (filename, '/'); + + if (slash != (char *) NULL) + { + *slash = 0; + tmpname = xmalloc (strlen (filename) + sizeof (template) + 1); + strcpy (tmpname, filename); + strcat (tmpname, "/"); + strcat (tmpname, template); + mkdtemp (tmpname); + *slash = '/'; + } + else + { + tmpname = xmalloc (sizeof (template)); + strcpy (tmpname, template); + mkdtemp (tmpname); } return tmpname; } diff --git a/gnu/usr.bin/binutils/binutils/bucomm.h b/gnu/usr.bin/binutils/binutils/bucomm.h index 5b19cd1bb16..4a1698c97f1 100644 --- a/gnu/usr.bin/binutils/binutils/bucomm.h +++ b/gnu/usr.bin/binutils/binutils/bucomm.h @@ -106,6 +106,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_tempdir PARAMS ((char *)); bfd_vma parse_vma PARAMS ((const char *, const char *)); diff --git a/gnu/usr.bin/binutils/binutils/nlmconv.c b/gnu/usr.bin/binutils/binutils/nlmconv.c index a06ffc8d76a..05894d24c11 100644 --- a/gnu/usr.bin/binutils/binutils/nlmconv.c +++ b/gnu/usr.bin/binutils/binutils/nlmconv.c @@ -2096,9 +2096,6 @@ powerpc_mangle_relocs (outbfd, insec, relocs_ptr, reloc_count_ptr, contents, #define LD_NAME "ld" #endif -/* Temporary file name base. */ -static char *temp_filename; - /* The user has specified several input files. Invoke the linker to link them all together, and convert and delete the resulting output file. */ @@ -2145,10 +2142,7 @@ link_inputs (inputs, ld) if (ld == NULL) ld = (char *) LD_NAME; - temp_filename = choose_temp_base (); - - unlink_on_exit = xmalloc (strlen (temp_filename) + 3); - sprintf (unlink_on_exit, "%s.O", temp_filename); + unlink_on_exit = choose_temp_file (".O"); argv[0] = ld; argv[1] = (char *) "-Ur"; diff --git a/gnu/usr.bin/binutils/binutils/objcopy.c b/gnu/usr.bin/binutils/binutils/objcopy.c index 365f55d174f..204f2d29ffb 100644 --- a/gnu/usr.bin/binutils/binutils/objcopy.c +++ b/gnu/usr.bin/binutils/binutils/objcopy.c @@ -881,13 +881,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_tempdir (bfd_get_filename (obfd)); /* Make a temp directory to hold the contents. */ - if (mkdir (dir, 0700) != 0) + if (dir == 0) { - fatal ("cannot mkdir %s for archive copying (error: %s)", - dir, strerror (errno)); + fatal ("cannot create tempdir for archive copying (error: %s)", + strerror (errno)); } obfd->has_armap = ibfd->has_armap; diff --git a/gnu/usr.bin/binutils/binutils/objdump.c b/gnu/usr.bin/binutils/binutils/objdump.c index d35d154325f..ceea64c13be 100644 --- a/gnu/usr.bin/binutils/binutils/objdump.c +++ b/gnu/usr.bin/binutils/binutils/objdump.c @@ -2169,7 +2169,7 @@ display_target_list () char *dummy_name; int t; - dummy_name = choose_temp_base (); + dummy_name = make_temp_file (NULL); for (t = 0; bfd_target_vector[t]; t++) { bfd_target *p = bfd_target_vector[t]; @@ -2221,7 +2221,7 @@ display_info_table (first, last) printf ("%s ", bfd_target_vector[t]->name); putchar ('\n'); - dummy_name = choose_temp_base (); + dummy_name = make_temp_file (NULL); for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++) if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0) { diff --git a/gnu/usr.bin/binutils/include/libiberty.h b/gnu/usr.bin/binutils/include/libiberty.h index a39480a2c8d..6579db9681a 100644 --- a/gnu/usr.bin/binutils/include/libiberty.h +++ b/gnu/usr.bin/binutils/include/libiberty.h @@ -41,10 +41,13 @@ extern int fdmatch PARAMS ((int fd1, int fd2)); extern long get_run_time PARAMS ((void)); -/* Choose a temporary directory to use for scratch files. */ +/* Choose a temporary directory to use for scratch files. OBSOLETE */ extern char *choose_temp_base PARAMS ((void)); +/* Replacement... */ +extern char *make_temp_file PARAMS ((char *suffix)); + /* Allocate memory filled with spaces. Allocates using malloc. */ extern const char *spaces PARAMS ((int count)); |