choose-temp.c (make_temp_file): Accept new argument for the file suffix to use.

* 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.
Should fix irix build problems.

From-SVN: r20812
This commit is contained in:
Jeffrey A Law 1998-06-30 01:41:45 +00:00 committed by Jeff Law
parent af24816977
commit 20f2d03a8e
5 changed files with 60 additions and 26 deletions

View File

@ -1,3 +1,16 @@
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

View File

@ -152,11 +152,12 @@ choose_temp_base ()
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 };
@ -177,19 +178,29 @@ make_temp_file ()
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);
fd = mkstemp (temp_filename);
/* If mkstemp failed, then something bad is happening. Maybe we should
if (suffix)
strcat (temp_filename, suffix);
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 ();

View File

@ -60,7 +60,7 @@ Boston, MA 02111-1307, USA. */
#define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
#endif
extern char *make_temp_file ();
extern char *make_temp_file PROTO ((char *));
/* On certain systems, we have code that works by scanning the object file
directly. But this code uses system-specific header files and library
@ -1129,13 +1129,13 @@ main (argc, argv)
*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";

View File

@ -1276,7 +1276,7 @@ static int argbuf_index;
#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. */
@ -3524,7 +3524,7 @@ do_spec_1 (spec, inswitch, soft_matched_part)
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;

View File

@ -1,5 +1,5 @@
/* 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
@ -43,12 +43,21 @@ typedef unsigned long gcc_uint64_t;
#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";
@ -61,13 +70,14 @@ mkstemp (template)
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. */