+Tue Jun 30 02:34:02 1998 Jeffrey A Law (law@cygnus.com)
+
+ * choose-temp.c (make_temp_file): Accept new argument for the
+ file suffix to use. Allocate space for it and add it to the
+ template.
+ * mkstemp.c (mkstemps): Renamed from mkstemp. Accept new argument
+ for the length of the suffix. Update template struture checks
+ to handle optinal suffix.
+ * collect2.c (make_temp_file): Update prototype.
+ (main): Put proper suffixes on temporary files.
+ * gcc.c (make_temp_file): Update prototype.
+ (do_spec_1): Put proper suffixes on temporary files.
+
Tue Jun 30 00:56:19 1998 Bruno Haible <haible@ilog.fr>
* invoke.texi: Document new implicit structure initialization
one. */
char *
-make_temp_file ()
+make_temp_file (suffix)
+ char *suffix;
{
char *base = 0;
char *temp_filename;
- int len;
+ int base_len, suffix_len;
int fd;
static char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 };
static char usrtmp[] = { DIR_SEPARATOR, 'u', 's', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 };
if (base == 0)
base = ".";
- len = strlen (base);
- temp_filename = xmalloc (len + 1 /*DIR_SEPARATOR*/
- + strlen (TEMP_FILE) + 1);
+ base_len = strlen (base);
+
+ if (suffix)
+ suffix_len = strlen (suffix);
+ else
+ suffix_len = 0;
+
+ temp_filename = xmalloc (base_len + 1 /*DIR_SEPARATOR*/
+ + strlen (TEMP_FILE)
+ + suffix_len + 1);
strcpy (temp_filename, base);
- if (len != 0
- && temp_filename[len-1] != '/'
- && temp_filename[len-1] != DIR_SEPARATOR)
- temp_filename[len++] = DIR_SEPARATOR;
- strcpy (temp_filename + len, TEMP_FILE);
+ if (base_len != 0
+ && temp_filename[base_len-1] != '/'
+ && temp_filename[base_len-1] != DIR_SEPARATOR)
+ temp_filename[base_len++] = DIR_SEPARATOR;
+ strcpy (temp_filename + base_len, TEMP_FILE);
+
+ if (suffix)
+ strcat (temp_filename, suffix);
- fd = mkstemp (temp_filename);
- /* If mkstemp failed, then something bad is happening. Maybe we should
+ fd = mkstemps (temp_filename, suffix_len);
+ /* If mkstemps failed, then something bad is happening. Maybe we should
issue a message about a possible security attack in progress? */
if (fd == -1)
abort ();
#define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
#endif
-extern char *make_temp_file ();
+extern char *make_temp_file PROTO ((char *));
\f
/* On certain systems, we have code that works by scanning the object file
directly. But this code uses system-specific header files and library
*ld1++ = *ld2++ = ld_file_name;
/* Make temp file names. */
- c_file = make_temp_file ();
- o_file = make_temp_file ();
+ c_file = make_temp_file (".c");
+ o_file = make_temp_file (".o");
#ifdef COLLECT_EXPORT_LIST
- export_file = make_temp_file ();
- import_file = make_temp_file ();
+ export_file = make_temp_file (".x");
+ import_file = make_temp_file (".p");
#endif
- ldout = make_temp_file ();
+ ldout = make_temp_file (".ld");
*c_ptr++ = c_file_name;
*c_ptr++ = "-lang-c";
*c_ptr++ = "-c";
#ifdef MKTEMP_EACH_FILE
-extern char *make_temp_file PROTO((void));
+extern char *make_temp_file PROTO((char *));
/* This is the list of suffixes and codes (%g/%u/%U) and the associated
temp file. */
t->length = p - suffix;
t->suffix = save_string (suffix, p - suffix);
t->unique = (c != 'g');
- temp_filename = make_temp_file ();
+ temp_filename = make_temp_file (suffix);
temp_filename_length = strlen (temp_filename);
t->filename = temp_filename;
t->filename_length = temp_filename_length;
/* Copyright (C) 1991, 1992, 1996, 1998 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
+ This file is derived from mkstemp.c from the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
#endif
/* Generate a unique temporary file name from TEMPLATE.
- The last six characters of TEMPLATE must be "XXXXXX";
+
+ TEMPLATE has the form:
+
+ <path>/ccXXXXXX<suffix>
+
+ SUFFIX_LEN tells us how long <suffix> is (it can be zero length).
+
+ The last six characters of TEMPLATE before <suffix> must be "XXXXXX";
they are replaced with a string that makes the filename unique.
+
Returns a file descriptor open on the file for reading and writing. */
int
-mkstemp (template)
+mkstemps (template, suffix_len)
char *template;
+ int suffix_len;
{
static const char letters[]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int count;
len = strlen (template);
- if (len < 6 || strcmp (&template[len - 6], "XXXXXX"))
+
+ if (len < 6 + suffix_len
+ || strncmp (&template[len - 6 - suffix_len], "XXXXXX", 6))
{
return -1;
}
- /* This is where the Xs start. */
- XXXXXX = &template[len - 6];
+ XXXXXX = &template[len - 6 - suffix_len];
#ifdef HAVE_GETTIMEOFDAY
/* Get some more or less random data. */