jcf-write.c (write_classfile): Unlink the temporary file if it cannot be renamed.
authorMark Mitchell <mark@codesourcery.com>
Tue, 14 May 2002 00:04:54 +0000 (00:04 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Tue, 14 May 2002 00:04:54 +0000 (00:04 +0000)
* jcf-write.c (write_classfile): Unlink the temporary file if it
cannot be renamed.  Use concat to build up the name of the
temporary file

From-SVN: r53439

gcc/java/ChangeLog
gcc/java/jcf-write.c

index 502328ebebbded30fc10b431875cf137ed217eb9..2838c43a6b02b063aaf3b046c954c6f7d1e664a9 100644 (file)
@@ -1,6 +1,12 @@
+2002-05-13  Mark Mitchell  <mark@codesourcery.com>
+
+       * jcf-write.c (write_classfile): Unlink the temporary file if it
+       cannot be renamed.  Use concat to build up the name of the
+       temporary file.
+
 2002-05-08  Mark Mitchell  <mark@codesourcery.com>
 
-       * java/jcf-write.c (write_classfile): Write the file to a 
+       * jcf-write.c (write_classfile): Write the file to a 
        temporary file and then rename it.
 
 2002-05-07  Tom Tromey  <tromey@redhat.com>
index 62e3e09d64b3019a1598966ae7b764dbd50c5035..491b561ed050c1b6370587c3e5acffd10634e0e5 100644 (file)
@@ -3380,9 +3380,7 @@ write_classfile (clas)
       /* The .class file is initially written to a ".tmp" file so that
         if multiple instances of the compiler are running at once
         they do not see partially formed class files. */
-      temporary_file_name = xmalloc (strlen (class_file_name) 
-                                    + strlen (".tmp") + 1);
-      sprintf (temporary_file_name, "%s.tmp", class_file_name);
+      temporary_file_name = concat (class_file_name, ".tmp", NULL);
       stream = fopen (temporary_file_name, "wb");
       if (stream == NULL)
        fatal_io_error ("can't open %s for writing", temporary_file_name);
@@ -3394,7 +3392,10 @@ write_classfile (clas)
       if (fclose (stream))
        fatal_io_error ("error closing %s", temporary_file_name);
       if (rename (temporary_file_name, class_file_name) == -1)
-       fatal_io_error ("can't create %s", class_file_name);
+       {
+         remove (temporary_file_name);
+         fatal_io_error ("can't create %s", class_file_name);
+       }
       free (temporary_file_name);
       free (class_file_name);
     }