Commit 39d45901 by Jeffrey A Law Committed by Jeff Law

choose-temp.c (choose_temp_base): Restore original variant of this function for compatibility.

        * choose-temp.c (choose_temp_base): Restore original variant of
        this function for compatibility.
        (make_temp_file): This is the new, preferred interface to create
        temporary files.
        * collect2.c (choose_temp_base): Delete declaration.
        (make_temp_file): Declare.
        (temp_filename_length, temp_filename): Delete.
        (main): Use make_temp_file to get temporary files.  Use --lang-c
        to force the resulting ctort/dtor file to be compiled with the C
        compiler.  Make sure to remove temporary files on all exit paths.
        * gcc.c (make_temp_file): Provide prototype if MKTEMP_EACH_FILE is
        defined.
        (choose_temp_base): Only provide prototype if MKTEMP_EACH_FILE is
        not defined.
        (do_spec): Use make_temp_file if MKTEMP_EACH_FILE is defined.

From-SVN: r20784
parent b0d45b74
Sun Jun 28 20:58:51 1998 Jeffrey A Law (law@cygnus.com)
* choose-temp.c (choose_temp_base): Restore original variant of
this function for compatibility.
(make_temp_file): This is the new, preferred interface to create
temporary files.
* collect2.c (choose_temp_base): Delete declaration.
(make_temp_file): Declare.
(temp_filename_length, temp_filename): Delete.
(main): Use make_temp_file to get temporary files. Use --lang-c
to force the resulting ctort/dtor file to be compiled with the C
compiler. Make sure to remove temporary files on all exit paths.
* gcc.c (make_temp_file): Provide prototype if MKTEMP_EACH_FILE is
defined.
(choose_temp_base): Only provide prototype if MKTEMP_EACH_FILE is
not defined.
(do_spec): Use make_temp_file if MKTEMP_EACH_FILE is defined.
Sun Jun 28 08:57:09 1998 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> Sun Jun 28 08:57:09 1998 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* configure.in (GCC_NEED_DECLARATIONS): Add strerror, getcwd and * configure.in (GCC_NEED_DECLARATIONS): Add strerror, getcwd and
......
...@@ -17,7 +17,7 @@ License along with libiberty; see the file COPYING.LIB. If not, ...@@ -17,7 +17,7 @@ License along with libiberty; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
/* This file exports one function: choose_temp_base. */ /* This file exports two functions: choose_temp_base and make_temp_file. */
/* This file lives in at least two places: libiberty and gcc. /* This file lives in at least two places: libiberty and gcc.
Don't change one without the other. */ Don't change one without the other. */
...@@ -102,7 +102,10 @@ try (dir, base) ...@@ -102,7 +102,10 @@ try (dir, base)
/* Return a prefix for temporary file names or NULL if unable to find one. /* Return a prefix for temporary file names or NULL if unable to find one.
The current directory is chosen if all else fails so the program is The current directory is chosen if all else fails so the program is
exited if a temporary directory can't be found (mktemp fails). exited if a temporary directory can't be found (mktemp fails).
The buffer for the result is obtained with xmalloc. */ The buffer for the result is obtained with xmalloc.
This function is provided for backwards compatability only. It use
is not recommended. */
char * char *
choose_temp_base () choose_temp_base ()
...@@ -110,6 +113,50 @@ choose_temp_base () ...@@ -110,6 +113,50 @@ choose_temp_base ()
char *base = 0; char *base = 0;
char *temp_filename; char *temp_filename;
int len; int len;
static char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 };
static char usrtmp[] = { DIR_SEPARATOR, 'u', 's', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 };
base = try (getenv ("TMPDIR"), base);
base = try (getenv ("TMP"), base);
base = try (getenv ("TEMP"), base);
#ifdef P_tmpdir
base = try (P_tmpdir, base);
#endif
/* Try /usr/tmp, then /tmp. */
base = try (usrtmp, base);
base = try (tmp, base);
/* If all else fails, use the current directory! */
if (base == 0)
base = ".";
len = strlen (base);
temp_filename = xmalloc (len + 1 /*DIR_SEPARATOR*/
+ strlen (TEMP_FILE) + 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);
mktemp (temp_filename);
if (strlen (temp_filename) == 0)
abort ();
return temp_filename;
}
/* Return a temporary file name (as a string) or NULL if unable to create
one. */
char *
make_temp_file ()
{
char *base = 0;
char *temp_filename;
int 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 };
......
...@@ -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 *choose_temp_base (); extern char *make_temp_file ();
/* 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
...@@ -204,8 +204,6 @@ int debug; /* true if -debug */ ...@@ -204,8 +204,6 @@ int debug; /* true if -debug */
static int shared_obj; /* true if -shared */ static int shared_obj; /* true if -shared */
static int temp_filename_length; /* Length of temp_filename */
static char *temp_filename; /* Base of temp filenames */
static char *c_file; /* <xxx>.c for constructor/destructor list. */ static char *c_file; /* <xxx>.c for constructor/destructor list. */
static char *o_file; /* <xxx>.o for constructor/destructor list. */ static char *o_file; /* <xxx>.o for constructor/destructor list. */
#ifdef COLLECT_EXPORT_LIST #ifdef COLLECT_EXPORT_LIST
...@@ -932,7 +930,7 @@ main (argc, argv) ...@@ -932,7 +930,7 @@ main (argc, argv)
char **object_lst = (char **) xcalloc (sizeof (char *), argc); char **object_lst = (char **) xcalloc (sizeof (char *), argc);
char **object = object_lst; char **object = object_lst;
int first_file; int first_file;
int num_c_args = argc+7; int num_c_args = argc+8;
#ifdef DEBUG #ifdef DEBUG
debug = 1; debug = 1;
...@@ -1131,23 +1129,15 @@ main (argc, argv) ...@@ -1131,23 +1129,15 @@ main (argc, argv)
*ld1++ = *ld2++ = ld_file_name; *ld1++ = *ld2++ = ld_file_name;
/* Make temp file names. */ /* Make temp file names. */
temp_filename = choose_temp_base (); c_file = make_temp_file ();
temp_filename_length = strlen (temp_filename); o_file = make_temp_file ();
c_file = xcalloc (temp_filename_length + sizeof (".c"), 1);
o_file = xcalloc (temp_filename_length + sizeof (".o"), 1);
#ifdef COLLECT_EXPORT_LIST #ifdef COLLECT_EXPORT_LIST
export_file = xmalloc (temp_filename_length + sizeof (".x")); export_file = make_temp_file ();
import_file = xmalloc (temp_filename_length + sizeof (".p")); import_file = make_temp_file ();
#endif
ldout = xmalloc (temp_filename_length + sizeof (".ld"));
sprintf (ldout, "%s.ld", temp_filename);
sprintf (c_file, "%s.c", temp_filename);
sprintf (o_file, "%s.o", temp_filename);
#ifdef COLLECT_EXPORT_LIST
sprintf (export_file, "%s.x", temp_filename);
sprintf (import_file, "%s.p", temp_filename);
#endif #endif
ldout = make_temp_file ();
*c_ptr++ = c_file_name; *c_ptr++ = c_file_name;
*c_ptr++ = "-lang-c";
*c_ptr++ = "-c"; *c_ptr++ = "-c";
*c_ptr++ = "-o"; *c_ptr++ = "-o";
*c_ptr++ = o_file; *c_ptr++ = o_file;
...@@ -1435,6 +1425,8 @@ main (argc, argv) ...@@ -1435,6 +1425,8 @@ main (argc, argv)
if (import_file != 0 && import_file[0]) if (import_file != 0 && import_file[0])
maybe_unlink (import_file); maybe_unlink (import_file);
#endif #endif
maybe_unlink (c_file);
maybe_unlink (o_file);
return 0; return 0;
} }
...@@ -1485,6 +1477,8 @@ main (argc, argv) ...@@ -1485,6 +1477,8 @@ main (argc, argv)
maybe_unlink (export_file); maybe_unlink (export_file);
maybe_unlink (import_file); maybe_unlink (import_file);
#endif #endif
maybe_unlink (c_file);
maybe_unlink (o_file);
return 0; return 0;
} }
......
...@@ -121,7 +121,6 @@ static char dir_separator_str[] = {DIR_SEPARATOR, 0}; ...@@ -121,7 +121,6 @@ static char dir_separator_str[] = {DIR_SEPARATOR, 0};
#define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ENV_VALUE = getenv (ENV_NAME) #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ENV_VALUE = getenv (ENV_NAME)
#endif #endif
extern char *choose_temp_base PROTO((void));
extern char *my_strerror PROTO((int)); extern char *my_strerror PROTO((int));
#ifndef HAVE_KILL #ifndef HAVE_KILL
...@@ -1269,6 +1268,9 @@ static int argbuf_index; ...@@ -1269,6 +1268,9 @@ static int argbuf_index;
#define MKTEMP_EACH_FILE #define MKTEMP_EACH_FILE
#ifdef MKTEMP_EACH_FILE #ifdef MKTEMP_EACH_FILE
extern char *make_temp_file PROTO((void));
/* 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. */
...@@ -1280,8 +1282,11 @@ static struct temp_name { ...@@ -1280,8 +1282,11 @@ static struct temp_name {
int filename_length; /* strlen (filename). */ int filename_length; /* strlen (filename). */
struct temp_name *next; struct temp_name *next;
} *temp_names; } *temp_names;
#else
extern char *choose_temp_base PROTO((void));
#endif #endif
/* Number of commands executed so far. */ /* Number of commands executed so far. */
static int execution_count; static int execution_count;
...@@ -3512,7 +3517,7 @@ do_spec_1 (spec, inswitch, soft_matched_part) ...@@ -3512,7 +3517,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 = choose_temp_base (); temp_filename = make_temp_file ();
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;
......
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