choose-temp.c (make_temp_file): Accept new argument for the file suffix to use.
authorJeffrey A Law <law@cygnus.com>
Tue, 30 Jun 1998 01:41:45 +0000 (01:41 +0000)
committerJeff Law <law@gcc.gnu.org>
Tue, 30 Jun 1998 01:41:45 +0000 (19:41 -0600)
        * 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

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

index 2db51d336bbf859493d0407233333b6388bacd2e..07d38952125a6012aea78733f215807155fd956a 100644 (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
index e012c6a4b798fd1755a5890ed7852fcd10d59e85..46293367613b5ac18f4bb8a0faca3e82abc76852 100644 (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);
+
+  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 ();
index 7c6e2b3adc0f94c748860dcb26e1e5ad4e38d6a4..442af243459f7df88e12dcca54cfb2d833fef1ac 100644 (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 *));
 \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
@@ -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";
index 7117d60381405dd1375aa2b72ccdc543fc377c8b..bb33edf4039b76737a408396fbb5060fdba09859 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -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;
index d4d4b2bddbc7af7e5afda991aa1eabb02c006b29..d55e5837f15883491012a948a3678e8b3806872e 100644 (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.  */