Commit 20f2d03a by Jeffrey A Law Committed by Jeff Law

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
parent af248169
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> Tue Jun 30 00:56:19 1998 Bruno Haible <haible@ilog.fr>
* invoke.texi: Document new implicit structure initialization * invoke.texi: Document new implicit structure initialization
......
...@@ -152,11 +152,12 @@ choose_temp_base () ...@@ -152,11 +152,12 @@ choose_temp_base ()
one. */ one. */
char * char *
make_temp_file () make_temp_file (suffix)
char *suffix;
{ {
char *base = 0; char *base = 0;
char *temp_filename; char *temp_filename;
int len; int base_len, suffix_len;
int fd; int fd;
static char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 }; static char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 };
static char usrtmp[] = { DIR_SEPARATOR, 'u', 's', 'r', 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 () ...@@ -177,19 +178,29 @@ make_temp_file ()
if (base == 0) if (base == 0)
base = "."; base = ".";
len = strlen (base); base_len = strlen (base);
temp_filename = xmalloc (len + 1 /*DIR_SEPARATOR*/
+ strlen (TEMP_FILE) + 1); 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); strcpy (temp_filename, base);
if (len != 0 if (base_len != 0
&& temp_filename[len-1] != '/' && temp_filename[base_len-1] != '/'
&& temp_filename[len-1] != DIR_SEPARATOR) && temp_filename[base_len-1] != DIR_SEPARATOR)
temp_filename[len++] = DIR_SEPARATOR; temp_filename[base_len++] = DIR_SEPARATOR;
strcpy (temp_filename + len, TEMP_FILE); strcpy (temp_filename + base_len, TEMP_FILE);
if (suffix)
strcat (temp_filename, suffix);
fd = mkstemp (temp_filename); fd = mkstemps (temp_filename, suffix_len);
/* If mkstemp failed, then something bad is happening. Maybe we should /* If mkstemps failed, then something bad is happening. Maybe we should
issue a message about a possible security attack in progress? */ issue a message about a possible security attack in progress? */
if (fd == -1) if (fd == -1)
abort (); abort ();
......
...@@ -60,7 +60,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -60,7 +60,7 @@ Boston, MA 02111-1307, USA. */
#define WEXITSTATUS(S) (((S) & 0xff00) >> 8) #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
#endif #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 /* On certain systems, we have code that works by scanning the object file
directly. But this code uses system-specific header files and library directly. But this code uses system-specific header files and library
...@@ -1129,13 +1129,13 @@ main (argc, argv) ...@@ -1129,13 +1129,13 @@ main (argc, argv)
*ld1++ = *ld2++ = ld_file_name; *ld1++ = *ld2++ = ld_file_name;
/* Make temp file names. */ /* Make temp file names. */
c_file = make_temp_file (); c_file = make_temp_file (".c");
o_file = make_temp_file (); o_file = make_temp_file (".o");
#ifdef COLLECT_EXPORT_LIST #ifdef COLLECT_EXPORT_LIST
export_file = make_temp_file (); export_file = make_temp_file (".x");
import_file = make_temp_file (); import_file = make_temp_file (".p");
#endif #endif
ldout = make_temp_file (); ldout = make_temp_file (".ld");
*c_ptr++ = c_file_name; *c_ptr++ = c_file_name;
*c_ptr++ = "-lang-c"; *c_ptr++ = "-lang-c";
*c_ptr++ = "-c"; *c_ptr++ = "-c";
......
...@@ -1276,7 +1276,7 @@ static int argbuf_index; ...@@ -1276,7 +1276,7 @@ static int argbuf_index;
#ifdef MKTEMP_EACH_FILE #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 /* This is the list of suffixes and codes (%g/%u/%U) and the associated
temp file. */ temp file. */
...@@ -3524,7 +3524,7 @@ do_spec_1 (spec, inswitch, soft_matched_part) ...@@ -3524,7 +3524,7 @@ do_spec_1 (spec, inswitch, soft_matched_part)
t->length = p - suffix; t->length = p - suffix;
t->suffix = save_string (suffix, p - suffix); t->suffix = save_string (suffix, p - suffix);
t->unique = (c != 'g'); t->unique = (c != 'g');
temp_filename = make_temp_file (); temp_filename = make_temp_file (suffix);
temp_filename_length = strlen (temp_filename); temp_filename_length = strlen (temp_filename);
t->filename = temp_filename; t->filename = temp_filename;
t->filename_length = temp_filename_length; t->filename_length = temp_filename_length;
......
/* Copyright (C) 1991, 1992, 1996, 1998 Free Software Foundation, Inc. /* 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 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 modify it under the terms of the GNU Library General Public License as
...@@ -43,12 +43,21 @@ typedef unsigned long gcc_uint64_t; ...@@ -43,12 +43,21 @@ typedef unsigned long gcc_uint64_t;
#endif #endif
/* Generate a unique temporary file name from TEMPLATE. /* 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. they are replaced with a string that makes the filename unique.
Returns a file descriptor open on the file for reading and writing. */ Returns a file descriptor open on the file for reading and writing. */
int int
mkstemp (template) mkstemps (template, suffix_len)
char *template; char *template;
int suffix_len;
{ {
static const char letters[] static const char letters[]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
...@@ -61,13 +70,14 @@ mkstemp (template) ...@@ -61,13 +70,14 @@ mkstemp (template)
int count; int count;
len = strlen (template); 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; return -1;
} }
/* This is where the Xs start. */ XXXXXX = &template[len - 6 - suffix_len];
XXXXXX = &template[len - 6];
#ifdef HAVE_GETTIMEOFDAY #ifdef HAVE_GETTIMEOFDAY
/* Get some more or less random data. */ /* Get some more or less random data. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment