OSDN Git Service

* choose-temp.c (choose_temp_base): Restore original variant of
authorlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 28 Jun 1998 20:07:32 +0000 (20:07 +0000)
committerlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 28 Jun 1998 20:07:32 +0000 (20:07 +0000)
        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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@20784 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/choose-temp.c
gcc/collect2.c
gcc/gcc.c

index 3bc9e92..225395a 100644 (file)
@@ -1,3 +1,21 @@
+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>
 
        * configure.in (GCC_NEED_DECLARATIONS): Add strerror, getcwd and
index 1cc933c..e012c6a 100644 (file)
@@ -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,
 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.
    Don't change one without the other.  */
@@ -102,7 +102,10 @@ try (dir, base)
 /* 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
    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 *
 choose_temp_base ()
@@ -110,6 +113,50 @@ choose_temp_base ()
   char *base = 0;
   char *temp_filename;
   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;
   static char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 };
   static char usrtmp[] = { DIR_SEPARATOR, 'u', 's', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 };
index a766bd2..7c6e2b3 100644 (file)
@@ -60,7 +60,7 @@ Boston, MA 02111-1307, USA.  */
 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
 #endif
 
-extern char *choose_temp_base ();
+extern char *make_temp_file ();
 \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
@@ -204,8 +204,6 @@ int debug;                          /* true if -debug */
 
 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 *o_file;                   /* <xxx>.o for constructor/destructor list.  */
 #ifdef COLLECT_EXPORT_LIST
@@ -932,7 +930,7 @@ main (argc, argv)
   char **object_lst    = (char **) xcalloc (sizeof (char *), argc);
   char **object                = object_lst;
   int first_file;
-  int num_c_args       = argc+7;
+  int num_c_args       = argc+8;
 
 #ifdef DEBUG
   debug = 1;
@@ -1131,23 +1129,15 @@ main (argc, argv)
   *ld1++ = *ld2++ = ld_file_name;
 
   /* Make temp file names.  */
-  temp_filename = choose_temp_base ();
-  temp_filename_length = strlen (temp_filename);
-  c_file = xcalloc (temp_filename_length + sizeof (".c"), 1);
-  o_file = xcalloc (temp_filename_length + sizeof (".o"), 1);
+  c_file = make_temp_file ();
+  o_file = make_temp_file ();
 #ifdef COLLECT_EXPORT_LIST
-  export_file = xmalloc (temp_filename_length + sizeof (".x"));
-  import_file = xmalloc (temp_filename_length + sizeof (".p"));
-#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);
+  export_file = make_temp_file ();
+  import_file = make_temp_file ();
 #endif
+  ldout = make_temp_file ();
   *c_ptr++ = c_file_name;
+  *c_ptr++ = "-lang-c";
   *c_ptr++ = "-c";
   *c_ptr++ = "-o";
   *c_ptr++ = o_file;
@@ -1435,6 +1425,8 @@ main (argc, argv)
       if (import_file != 0 && import_file[0])
        maybe_unlink (import_file);
 #endif
+      maybe_unlink (c_file);
+      maybe_unlink (o_file);
       return 0;
     }
 
@@ -1485,6 +1477,8 @@ main (argc, argv)
       maybe_unlink (export_file);
       maybe_unlink (import_file);
 #endif
+      maybe_unlink (c_file);
+      maybe_unlink (o_file);
       return 0;
     }
 
index cc4af8e..09b0332 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -121,7 +121,6 @@ static char dir_separator_str[] = {DIR_SEPARATOR, 0};
 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ENV_VALUE = getenv (ENV_NAME)
 #endif
 
-extern char *choose_temp_base PROTO((void));
 extern char *my_strerror PROTO((int));
 
 #ifndef HAVE_KILL
@@ -1269,6 +1268,9 @@ static int argbuf_index;
 #define 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
    temp file.  */
 
@@ -1280,8 +1282,11 @@ static struct temp_name {
   int filename_length; /* strlen (filename).  */
   struct temp_name *next;
 } *temp_names;
+#else
+extern char *choose_temp_base PROTO((void));
 #endif
 
+
 /* Number of commands executed so far.  */
 
 static int execution_count;
@@ -3512,7 +3517,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 = choose_temp_base ();
+                   temp_filename = make_temp_file ();
                    temp_filename_length = strlen (temp_filename);
                    t->filename = temp_filename;
                    t->filename_length = temp_filename_length;