jcf-write.c (write_classfile): Remove target class file...
authorRanjit Mathew <rmathew@hotmail.com>
Fri, 22 Nov 2002 21:01:24 +0000 (21:01 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Fri, 22 Nov 2002 21:01:24 +0000 (21:01 +0000)
2002-11-22  Ranjit Mathew <rmathew@hotmail.com>
    Andrew Haley <aph@redhat.com>

* gcc/java/jcf-write.c (write_classfile): Remove target
class file, if it exists, before renaming the temporary
class file to it.

Co-Authored-By: Andrew Haley <aph@redhat.com>
From-SVN: r59386

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

index 31379a17134bcf9070f64bd86428aaa24fd0c525..0a2f1dc447bb871a1bfc8313e35d92a18a381102 100644 (file)
@@ -1,3 +1,10 @@
+2002-11-22  Ranjit Mathew <rmathew@hotmail.com>
+           Andrew Haley <aph@redhat.com>
+
+       * gcc/java/jcf-write.c (write_classfile): Remove target
+       class file, if it exists, before renaming the temporary
+       class file to it.
+
 2002-11-19  Jason Thorpe  <thorpej@wasabisystems.com>
 
        * jvspec.c (lang_specific_spec_functions): New.
index 1a9f1075e232c4770dd76d1e950e814f46287f05..47cfd11be8a7200b412027c15cf146cee67f545e 100644 (file)
@@ -3422,6 +3422,15 @@ write_classfile (clas)
       write_chunks (stream, chunks);
       if (fclose (stream))
        fatal_io_error ("error closing %s", temporary_file_name);
+
+      /* If a file named by the string pointed to by `new' exists
+         prior to the call to the `rename' function, the bahaviour
+         is implementation-defined.  ISO 9899-1990 7.9.4.2.
+
+         For example, on Win32 with MSVCRT, it is an error. */
+
+      unlink (class_file_name);
+
       if (rename (temporary_file_name, class_file_name) == -1)
        {
          remove (temporary_file_name);