diff --git a/libjava/Makefile.am b/libjava/Makefile.am index b29636842e9..db05b63aea2 100644 --- a/libjava/Makefile.am +++ b/libjava/Makefile.am @@ -733,6 +733,7 @@ gnu/gcj/protocol/http/Connection.java \ gnu/gcj/protocol/http/Handler.java \ gnu/gcj/protocol/jar/Connection.java \ gnu/gcj/protocol/jar/Handler.java \ +gnu/gcj/runtime/FileDeleter.java \ gnu/gcj/runtime/FirstThread.java \ gnu/gcj/runtime/VMClassLoader.java \ gnu/gcj/text/BaseBreakIterator.java \ diff --git a/libjava/Makefile.in b/libjava/Makefile.in index 5da8d91c5e7..84385b83a8a 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -521,6 +521,7 @@ gnu/gcj/protocol/http/Connection.java \ gnu/gcj/protocol/http/Handler.java \ gnu/gcj/protocol/jar/Connection.java \ gnu/gcj/protocol/jar/Handler.java \ +gnu/gcj/runtime/FileDeleter.java \ gnu/gcj/runtime/FirstThread.java \ gnu/gcj/runtime/VMClassLoader.java \ gnu/gcj/text/BaseBreakIterator.java \ @@ -1084,7 +1085,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/gnu/gcj/protocol/http/Handler.P \ .deps/gnu/gcj/protocol/jar/Connection.P \ .deps/gnu/gcj/protocol/jar/Handler.P \ -.deps/gnu/gcj/runtime/FirstThread.P \ +.deps/gnu/gcj/runtime/FileDeleter.P .deps/gnu/gcj/runtime/FirstThread.P \ .deps/gnu/gcj/runtime/VMClassLoader.P \ .deps/gnu/gcj/text/BaseBreakIterator.P \ .deps/gnu/gcj/text/CharacterBreakIterator.P \ diff --git a/libjava/gnu/gcj/runtime/FileDeleter.java b/libjava/gnu/gcj/runtime/FileDeleter.java new file mode 100644 index 00000000000..cc7aa9d50b7 --- /dev/null +++ b/libjava/gnu/gcj/runtime/FileDeleter.java @@ -0,0 +1,38 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.runtime; + +import java.io.*; +import java.util.*; + +public final class FileDeleter +{ + public synchronized static void add (File f) + { + if (deleteOnExitStack == null) + deleteOnExitStack = new Stack (); + + deleteOnExitStack.push (f); + } + + // Helper method called by java.lang.Runtime.exit() to perform + // pending deletions. + public static void deleteOnExitNow () + { + while (!deleteOnExitStack.empty ()) + ((File)(deleteOnExitStack.pop ())).delete (); + } + + // A stack of files to delete upon normal termination. + private static Stack deleteOnExitStack; +} + + + + diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java index b9ff9ff23f2..9043660be38 100644 --- a/libjava/java/io/File.java +++ b/libjava/java/io/File.java @@ -10,6 +10,9 @@ details. */ package java.io; +import java.util.*; +import gnu.gcj.runtime.FileDeleter; + /** * @author Tom Tromey * @date September 24, 1998 @@ -42,7 +45,7 @@ public class File implements Serializable return access (p, WRITE); } - private final native boolean performDelete (String canon); + private final native static boolean performDelete (String canon); public boolean delete () { SecurityManager s = System.getSecurityManager(); @@ -347,6 +350,17 @@ public class File implements Serializable return p; } + // Add this File to the set of files to be deleted upon normal + // termination. + public void deleteOnExit () + { + SecurityManager sm = System.getSecurityManager (); + if (sm != null) + sm.checkDelete (getName ()); + + FileDeleter.add (this); + } + // QUERY arguments to access function. private final static int READ = 0; private final static int WRITE = 1; diff --git a/libjava/java/lang/natRuntime.cc b/libjava/java/lang/natRuntime.cc index ad45066c261..93771651afe 100644 --- a/libjava/java/lang/natRuntime.cc +++ b/libjava/java/lang/natRuntime.cc @@ -17,6 +17,7 @@ details. */ #include #include #include +#include #include @@ -85,6 +86,9 @@ java::lang::Runtime::exit (jint status) if (finalize_on_exit) _Jv_RunAllFinalizers (); + // Delete all files registered with File.deleteOnExit() + gnu::gcj::runtime::FileDeleter::deleteOnExitNow (); + ::exit (status); }