diff options
author | Mark Mitchell <mark@codesourcery.com> | 2002-05-08 19:24:42 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2002-05-08 19:24:42 +0000 |
commit | 281524f4cb2726320ecd87179f0ab84cd45951c8 (patch) | |
tree | 337247b74438baf7d95c9f73e0bfcf95f4f57cdd /gcc/java | |
parent | a89e49c7242d5013dc8943b09723265af4dbecdf (diff) | |
download | gcc-281524f4cb2726320ecd87179f0ab84cd45951c8.zip gcc-281524f4cb2726320ecd87179f0ab84cd45951c8.tar.gz gcc-281524f4cb2726320ecd87179f0ab84cd45951c8.tar.bz2 |
jcf-write.c (write_classfile): Write the file to a temporary file and then rename it.
* java/jcf-write.c (write_classfile): Write the file to a
temporary file and then rename it.
* libjava/Makefile.am (all_java_source_files): New variable.
(all_java_class_files): Likewise.
.java.class: New rule.
(CLEANFILES): Remove tmp-list.
* libjava/Makefile.in: Regenerated.
From-SVN: r53298
Diffstat (limited to 'gcc/java')
-rw-r--r-- | gcc/java/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/java/jcf-write.c | 18 |
2 files changed, 20 insertions, 3 deletions
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 703658d..502328e 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,8 @@ +2002-05-08 Mark Mitchell <mark@codesourcery.com> + + * java/jcf-write.c (write_classfile): Write the file to a + temporary file and then rename it. + 2002-05-07 Tom Tromey <tromey@redhat.com> * gjavah.c (throwable_p): Use xstrdup, not strdup. diff --git a/gcc/java/jcf-write.c b/gcc/java/jcf-write.c index 2988c47..62e3e09 100644 --- a/gcc/java/jcf-write.c +++ b/gcc/java/jcf-write.c @@ -3374,16 +3374,28 @@ write_classfile (clas) if (class_file_name != NULL) { - FILE *stream = fopen (class_file_name, "wb"); + FILE *stream; + char *temporary_file_name; + + /* 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); + stream = fopen (temporary_file_name, "wb"); if (stream == NULL) - fatal_io_error ("can't open %s for writing", class_file_name); + fatal_io_error ("can't open %s for writing", temporary_file_name); jcf_dependency_add_target (class_file_name); init_jcf_state (state, work); chunks = generate_classfile (clas, state); write_chunks (stream, chunks); if (fclose (stream)) - fatal_io_error ("error closing %s", class_file_name); + 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); + free (temporary_file_name); free (class_file_name); } release_jcf_state (state); |