Why is GCJ shy of overwriting a .class file?
Ranjit Mathew
rmathew@hotmail.com
Fri Nov 8 04:03:00 GMT 2002
Ranjit Mathew wrote:
> Andrew Haley wrote:
>>> Ranjit Mathew writes:
>> > > gcj happily overwrites object files, executables,
>> > etc. after compilation, but it complains if a class
>> > file already exists.
>>>> Not to me. Please give an example of this behaviour.
>> On Windows, I get:
> ------------------------ 8< ----------------------------
> C:\src\tmp>gcj -C T.java
>> C:\src\tmp>gcj -C T.java
> jc1.exe: File exists: can't create ./T.class
> ------------------------ 8< ----------------------------
>> Strangely however, on Solaris I *don't* get the error.
I read the MSDN documentation and found that MSVCRT
would return an error for rename( ) if the file
already exists, unlike Unix.
How does the following look?
--------------------------- 8< -----------------------------------
--- jcf-write.c Fri Nov 8 17:00:02 2002
+++ jcf-write.c Fri Nov 8 17:02:34 2002
@@ -3423,4 +3423,8 @@
if (fclose (stream))
fatal_io_error ("error closing %s", temporary_file_name);
+
+ /* On Win32, renaming to an existing file is an error */
+ remove (class_file_name);
+
if (rename (temporary_file_name, class_file_name) == -1)
{
--------------------------- 8< -----------------------------------
Note that remove( ) will return an error if:
1. The file exists, but is read-only. In this case, the
rename( ) further down will also give an error.
2. The file does not exist.
Thus it is safe to ignore the return value of remove( ).
Or so I think.
Sincerely Yours,
Ranjit.
--
Ranjit Mathew Email: rmathew AT hotmail DOT com
Bangalore, INDIA. Web: http://ranjitmathew.tripod.com/
More information about the Java
mailing list