From 2f9a2cd769e940b7d6e7d256c6b24f314d6d00ae Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Tue, 14 May 2002 00:04:54 +0000 Subject: [PATCH] jcf-write.c (write_classfile): Unlink the temporary file if it cannot be renamed. * 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 | 8 +++++++- gcc/java/jcf-write.c | 9 +++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 502328ebebb..2838c43a6b0 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,6 +1,12 @@ +2002-05-13 Mark Mitchell + + * 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 - * 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 diff --git a/gcc/java/jcf-write.c b/gcc/java/jcf-write.c index 62e3e09d64b..491b561ed05 100644 --- a/gcc/java/jcf-write.c +++ b/gcc/java/jcf-write.c @@ -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); } -- 2.30.2