Index: java/io/File.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/File.java,v
retrieving revision 1.42
diff -u -r1.42 File.java
--- java/io/File.java 20 Apr 2004 16:29:11 -0000 1.42
+++ java/io/File.java 26 Apr 2004 20:48:23 -0000
@@ -41,7 +41,7 @@
import java.net.MalformedURLException;
import java.net.URL;
-import gnu.classpath.Configuration;
+
import gnu.java.io.PlatformHelper;
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
@@ -92,49 +92,12 @@
*/
public static final char pathSeparatorChar = pathSeparator.charAt(0);
- static boolean caseSensitive;
-
- static
- {
- if (Configuration.INIT_LOAD_LIBRARY)
- {
- System.loadLibrary("javaio");
- }
-
- // FIXME: We support only caseSensitive filesystems currently.
- caseSensitive = true;
- }
-
/**
* This is the path to the file set when the object is created. It
* may be an absolute or relative path name.
*/
private String path;
- /*
- * This native method does the actual check of whether or not a file
- * is a plain file or not. It also handles the existence check to
- * eliminate the overhead of a call to exists()
- */
- private native boolean isFileInternal(String path);
-
- /*
- * This method does the actual check of whether or not a file is a
- * directory or not. It also handle the existence check to eliminate
- * the overhead of a call to exists()
- */
- private native boolean isDirectoryInternal(String path);
-
- /**
- * This native method checks file permissions for reading
- */
- private synchronized native boolean canReadInternal(String path);
-
- /**
- * This native method checks file permissions for writing
- */
- private synchronized native boolean canWriteInternal(String path);
-
/**
* This method tests whether or not the current thread is allowed to
* to read the file pointed to by this object. This will be true if and
@@ -154,7 +117,7 @@
if (!exists())
return false;
- return canReadInternal(path);
+ return VMFile.canRead(path);
}
/**
@@ -177,11 +140,11 @@
checkWrite();
// Test for existence. This is required by the spec
- if (!existsInternal(path))
+ if (! VMFile.exists(path))
return false;
- if (!isDirectoryInternal(path))
- return canWriteInternal(path);
+ if (!VMFile.isDirectory(path))
+ return VMFile.canWrite(path);
else
try
{
@@ -221,14 +184,8 @@
public boolean createNewFile() throws IOException
{
checkWrite();
- return createInternal(path);
+ return VMFile.create(path);
}
-
- /*
- * This native method handles the actual deleting of the file
- */
- private native boolean deleteInternal(String path);
-
/**
* This method deletes the file represented by this object. If this file
* is a directory, it must be empty in order for the delete to succeed.
@@ -245,7 +202,7 @@
if (s != null)
s.checkDelete(path);
- return deleteInternal(path);
+ return VMFile.delete(path);
}
/**
@@ -270,17 +227,12 @@
File other = (File) obj;
- if (caseSensitive)
+ if (VMFile.caseSensitive)
return path.equals(other.path);
else
return path.equalsIgnoreCase(other.path);
}
- /*
- * This native method does the actual checking of file existence.
- */
- private native boolean existsInternal(String path);
-
/**
* This method tests whether or not the file represented by the object
* actually exists on the filesystem.
@@ -292,7 +244,7 @@
public boolean exists()
{
checkRead();
- return existsInternal(path);
+ return VMFile.exists(path);
}
/**
@@ -439,14 +391,7 @@
*/
public String getName()
{
- int pos = PlatformHelper.lastIndexOfSeparator(path);
- if (pos == -1)
- return path;
-
- if (PlatformHelper.endWithSeparator(path))
- return "";
-
- return path.substring(pos + separator.length());
+ return VMFile.getName(path);
}
/**
@@ -506,7 +451,7 @@
*/
public int hashCode()
{
- if (caseSensitive)
+ if (VMFile.caseSensitive)
return path.hashCode() ^ 1234321;
else
return path.toLowerCase().hashCode() ^ 1234321;
@@ -539,7 +484,7 @@
public boolean isDirectory()
{
checkRead();
- return isDirectoryInternal(path);
+ return VMFile.isDirectory(path);
}
/**
@@ -555,7 +500,7 @@
public boolean isFile()
{
checkRead();
- return isFileInternal(path);
+ return VMFile.isFile(path);
}
/**
@@ -571,17 +516,9 @@
*/
public boolean isHidden()
{
- // FIXME: this only works on UNIX
- return getName().startsWith(".");
+ return VMFile.isHidden(path);
}
- /*
- * This native method does the actual work of getting the last file
- * modification time. It also does the existence check to avoid the
- * overhead of a call to exists()
- */
- private native long lastModifiedInternal(String path);
-
/**
* This method returns the last modification time of this file. The
* time value returned is an abstract value that should not be interpreted
@@ -598,15 +535,9 @@
public long lastModified()
{
checkRead();
- return lastModifiedInternal(path);
+ return VMFile.lastModified(path);
}
- /*
- * This native method actually determines the length of the file and
- * handles the existence check
- */
- private native long lengthInternal(String path);
-
/**
* This method returns the length of the file represented by this object,
* or 0 if the specified file does not exist.
@@ -618,15 +549,9 @@
public long length()
{
checkRead();
- return lengthInternal(path);
+ return VMFile.length(path);
}
- /*
- * This native function actually produces the list of file in this
- * directory
- */
- private native String[] listInternal(String dirname);
-
/**
* This method returns a array of String
's representing the
* list of files is then directory represented by this object. If this
@@ -665,7 +590,7 @@
if (! dir.exists() || ! dir.isDirectory())
return null;
- String files[] = listInternal(list_path);
+ String files[] = VMFile.list(list_path);
// Check if an error occured in listInternal().
if (files == null)
@@ -864,11 +789,6 @@
return new URL("file", "", abspath.replace(separatorChar, '/'));
}
- /*
- * This native method actually creates the directory
- */
- private native boolean mkdirInternal(String path);
-
/**
* This method creates a directory for the path represented by this object.
*
@@ -880,7 +800,7 @@
public boolean mkdir()
{
checkWrite();
- return mkdirInternal(PlatformHelper.removeTailSeparator(path));
+ return VMFile.mkdir(PlatformHelper.removeTailSeparator(path));
}
/**
@@ -912,11 +832,6 @@
}
/**
- * This method is used to create a temporary file
- */
- private static native boolean createInternal(String name) throws IOException;
-
- /**
* This method creates a temporary file in the specified directory. If
* the directory name is null, then this method uses the system temporary
* directory. The files created are guaranteed not to currently exist and
@@ -958,10 +873,10 @@
throw new IOException("Cannot determine system temporary directory");
directory = new File(dirname);
- if (!directory.existsInternal(directory.path))
+ if (! VMFile.exists(directory.path))
throw new IOException("System temporary directory "
+ directory.getName() + " does not exist.");
- if (!directory.isDirectoryInternal(directory.path))
+ if (! VMFile.isDirectory(directory.path))
throw new IOException("System temporary directory "
+ directory.getName()
+ " is not really a directory.");
@@ -991,7 +906,7 @@
String filename = prefix + System.currentTimeMillis() + suffix;
file = new File(directory, filename);
}
- while (file.existsInternal(file.path));
+ while (VMFile.exists(file.path));
}
else
{
@@ -1008,7 +923,7 @@
String filename = prefix + java.lang.Integer.toHexString(n) + suffix;
file = new File(directory, filename);
}
- while (file.existsInternal(file.path));
+ while (VMFile.exists(file.path));
}
// Verify that we are allowed to create this file
@@ -1018,15 +933,10 @@
// Now create the file and return our file object
// XXX - FIXME race condition.
- createInternal(file.getAbsolutePath());
+ VMFile.create(file.getAbsolutePath());
return file;
}
- /*
- * This native method sets the permissions to make the file read only.
- */
- private native boolean setReadOnlyInternal(String path);
-
/**
* This method sets the file represented by this object to be read only.
* A read only file or directory cannot be modified. Please note that
@@ -1047,10 +957,10 @@
checkWrite();
// Test for existence.
- if (!existsInternal(path))
+ if (! VMFile.exists(path))
return false;
- return setReadOnlyInternal(path);
+ return VMFile.setReadOnly(path);
}
/**
@@ -1066,9 +976,7 @@
*/
public static File[] listRoots()
{
- File[] roots = new File[1];
- roots[0] = new File("/");
- return roots;
+ return VMFile.listRoots();
}
/**
@@ -1138,7 +1046,7 @@
return 0;
}
- if (caseSensitive)
+ if (VMFile.caseSensitive)
return p1.compareTo(p2);
else
return p1.compareToIgnoreCase(p2);
@@ -1170,11 +1078,6 @@
return compareTo((File) obj);
}
- /*
- * This native method actually performs the rename.
- */
- private native boolean renameToInternal(String target, String dest);
-
/**
* This method renames the file represented by this object to the path
* of the file represented by the argument File
.
@@ -1192,14 +1095,9 @@
checkWrite();
dest.checkWrite();
// Call our native rename method
- return renameToInternal(path, dest.path);
+ return VMFile.renameTo(path, dest.path);
}
- /*
- * This method does the actual setting of the modification time.
- */
- private native boolean setLastModifiedInternal(String path, long time);
-
/**
* This method sets the modification time on the file to the specified
* value. This is specified as the number of seconds since midnight
@@ -1222,7 +1120,7 @@
throw new IllegalArgumentException("Negative modification time: " + time);
checkWrite();
- return setLastModifiedInternal(path, time);
+ return VMFile.setLastModified(path, time);
}
private void checkWrite()
Index: vm/reference/java/io/VMFile.java
===================================================================
RCS file: vm/reference/java/io/VMFile.java
diff -N vm/reference/java/io/VMFile.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ vm/reference/java/io/VMFile.java 26 Apr 2004 20:48:23 -0000
@@ -0,0 +1,194 @@
+/* VMFile.java -- Class for methods natively accessing files
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.io;
+
+import gnu.classpath.Configuration;
+import gnu.java.io.PlatformHelper;
+
+
+/**
+ * @author Michael Koch (address@hidden)
+ */
+final class VMFile
+{
+ static boolean caseSensitive;
+
+ static
+ {
+ if (Configuration.INIT_LOAD_LIBRARY)
+ {
+ System.loadLibrary("javaio");
+ }
+
+ // FIXME: We support only caseSensitive filesystems currently.
+ caseSensitive = true;
+ }
+
+ /*
+ * This native method does the actual work of getting the last file
+ * modification time. It also does the existence check to avoid the
+ * overhead of a call to exists()
+ */
+ static native long lastModified(String path);
+
+ /*
+ * This native method sets the permissions to make the file read only.
+ */
+ static native boolean setReadOnly(String path);
+
+ /**
+ * This method is used to create a temporary file
+ */
+ static native boolean create(String path) throws IOException;
+
+ /*
+ * This native function actually produces the list of file in this
+ * directory
+ */
+ static native String[] list(String dirpath);
+
+ /*
+ * This native method actually performs the rename.
+ */
+ static native boolean renameTo(String targetpath, String destpath);
+
+ /*
+ * This native method actually determines the length of the file and
+ * handles the existence check
+ */
+ static native long length(String path);
+
+ /*
+ * This native method does the actual checking of file existence.
+ */
+ static native boolean exists(String path);
+
+ /*
+ * This native method handles the actual deleting of the file
+ */
+ static native boolean delete(String path);
+
+ /*
+ * This method does the actual setting of the modification time.
+ */
+ static native boolean setLastModified(String path, long time);
+
+ /*
+ * This native method actually creates the directory
+ */
+ static native boolean mkdir(String dirpath);
+
+ /*
+ * This native method does the actual check of whether or not a file
+ * is a plain file or not. It also handles the existence check to
+ * eliminate the overhead of a call to exists()
+ */
+ static native boolean isFile(String path);
+
+ /**
+ * This native method checks file permissions for writing
+ */
+ static synchronized native boolean canWrite(String path);
+
+ /**
+ * This native method checks file permissions for reading
+ */
+ static synchronized native boolean canRead(String path);
+
+ /*
+ * This method does the actual check of whether or not a file is a
+ * directory or not. It also handle the existence check to eliminate
+ * the overhead of a call to exists()
+ */
+ static native boolean isDirectory(String dirpath);
+
+ /**
+ * This method returns an array of filesystem roots. Some operating systems
+ * have volume oriented filesystem. This method provides a mechanism for
+ * determining which volumes exist. GNU systems use a single hierarchical
+ * filesystem, so will have only one "/" filesystem root.
+ *
+ * @return An array of File
objects for each filesystem root
+ * available.
+ *
+ * @since 1.2
+ */
+ static File[] listRoots()
+ {
+ File[] roots = new File[1];
+ roots[0] = new File("/");
+ return roots;
+ }
+
+ /**
+ * This method tests whether or not this file represents a "hidden" file.
+ * On GNU systems, a file is hidden if its name begins with a "."
+ * character. Files with these names are traditionally not shown with
+ * directory listing tools.
+ *
+ * @return true
if the file is hidden, false
+ * otherwise.
+ *
+ * @since 1.2
+ */
+ static boolean isHidden(String path)
+ {
+ // FIXME: this only works on UNIX
+ return getName(path).startsWith(".");
+ }
+
+ /**
+ * This method returns the name of the file. This is everything in the
+ * complete path of the file after the last instance of the separator
+ * string.
+ *
+ * @return The file name
+ */
+ static String getName(String path)
+ {
+ int pos = PlatformHelper.lastIndexOfSeparator(path);
+ if (pos == -1)
+ return path;
+
+ if (PlatformHelper.endWithSeparator(path))
+ return "";
+
+ return path.substring(pos + File.separator.length());
+ }
+}
Index: vm/reference/java/io/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/io/Makefile.am,v
retrieving revision 1.1
diff -u -r1.1 Makefile.am
--- vm/reference/java/io/Makefile.am 17 Jan 2003 16:45:29 -0000 1.1
+++ vm/reference/java/io/Makefile.am 26 Apr 2004 20:48:23 -0000
@@ -1,4 +1,5 @@
# used by automake to generate Makefile.in
EXTRA_DIST = \
+VMFile.java \
VMObjectStreamClass.java
Index: include/java_io_File.h
===================================================================
RCS file: include/java_io_File.h
diff -N include/java_io_File.h
--- include/java_io_File.h 30 Jul 2003 16:47:19 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,32 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-
-#ifndef __java_io_File__
-#define __java_io_File__
-
-#include
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_isFileInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_isDirectoryInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_canReadInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_canWriteInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_deleteInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_existsInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jlong JNICALL Java_java_io_File_lastModifiedInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jlong JNICALL Java_java_io_File_lengthInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jobjectArray JNICALL Java_java_io_File_listInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_mkdirInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_createInternal (JNIEnv *env, jclass, jstring);
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_setReadOnlyInternal (JNIEnv *env, jobject, jstring);
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_renameToInternal (JNIEnv *env, jobject, jstring, jstring);
-extern JNIEXPORT jboolean JNICALL Java_java_io_File_setLastModifiedInternal (JNIEnv *env, jobject, jstring, jlong);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __java_io_File__ */
Index: include/java_io_VMFile.h
===================================================================
RCS file: include/java_io_VMFile.h
diff -N include/java_io_VMFile.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ include/java_io_VMFile.h 26 Apr 2004 20:48:23 -0000
@@ -0,0 +1,32 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+
+#ifndef __java_io_VMFile__
+#define __java_io_VMFile__
+
+#include
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+extern JNIEXPORT jlong JNICALL Java_java_io_VMFile_lastModified (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_setReadOnly (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_create (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jobjectArray JNICALL Java_java_io_VMFile_list (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_renameTo (JNIEnv *env, jclass, jstring, jstring);
+extern JNIEXPORT jlong JNICALL Java_java_io_VMFile_length (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_exists (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_delete (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_setLastModified (JNIEnv *env, jclass, jstring, jlong);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_mkdir (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_isFile (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_canWrite (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_canRead (JNIEnv *env, jclass, jstring);
+extern JNIEXPORT jboolean JNICALL Java_java_io_VMFile_isDirectory (JNIEnv *env, jclass, jstring);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __java_io_VMFile__ */
Index: include/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/include/Makefile.am,v
retrieving revision 1.15
diff -u -r1.15 Makefile.am
--- include/Makefile.am 18 Apr 2004 15:41:17 -0000 1.15
+++ include/Makefile.am 26 Apr 2004 20:48:23 -0000
@@ -42,8 +42,8 @@
$(top_srcdir)/include/gnu_java_nio_PipeImpl.h \
$(top_srcdir)/include/gnu_java_nio_SelectorImpl.h \
$(top_srcdir)/include/gnu_java_nio_channels_FileChannelImpl.h \
-$(top_srcdir)/include/java_io_File.h \
$(top_srcdir)/include/java_io_ObjectInputStream.h \
+$(top_srcdir)/include/java_io_VMFile.h \
$(top_srcdir)/include/java_io_VMObjectStreamClass.h \
$(top_srcdir)/include/java_lang_Double.h \
$(top_srcdir)/include/java_lang_Math.h \
@@ -137,10 +137,10 @@
$(JAVAH) -o $@ gnu.java.nio.PipeImpl
$(top_srcdir)/include/gnu_java_nio_SelectorImpl.h: $(top_srcdir)/gnu/java/nio/SelectorImpl.java
$(JAVAH) -o $@ gnu.java.nio.SelectorImpl
-$(top_srcdir)/include/java_io_File.h: $(top_srcdir)/java/io/File.java
- $(JAVAH) -o $@ java.io.File
$(top_srcdir)/include/java_io_ObjectInputStream.h: $(top_srcdir)/java/io/ObjectInputStream.java
$(JAVAH) -o $@ java.io.ObjectInputStream
+$(top_srcdir)/include/java_io_VMFile.h: ../vm/current/java/io/VMFile.java
+ $(JAVAH) -o $@ java.io.VMFile
$(top_srcdir)/include/java_io_VMObjectStreamClass.h: ../vm/current/java/io/VMObjectStreamClass.java
$(JAVAH) -o $@ java.io.VMObjectStreamClass
$(top_srcdir)/include/java_lang_Double.h: $(top_srcdir)/java/lang/Double.java
Index: native/jni/java-io/java_io_File.c
===================================================================
RCS file: native/jni/java-io/java_io_File.c
diff -N native/jni/java-io/java_io_File.c
--- native/jni/java-io/java_io_File.c 9 Apr 2004 14:04:50 -0000 1.13
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,702 +0,0 @@
-/* File.c - Native methods for java.io.File class
- Copyright (C) 1998, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-/* do not move; needed here because of some macro definitions */
-#include
-
-#include
-#include
-
-#include
-#include
-
-#include "target_native.h"
-#ifndef WITHOUT_FILESYSTEM
- #include "target_native_file.h"
-#endif
-#include "target_native_math_int.h"
-
-#include "javaio.h"
-
-#include "java_io_File.h"
-
-/*************************************************************************/
-
-/*
- * Method to create an empty file.
- *
- * Class: java_io_File
- * Method: createInternal
- * Signature: (Ljava/lang/String;)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_createInternal(JNIEnv *env, jclass clazz, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- int fd;
- int result;
-
- filename = JCL_jstring_to_cstring(env, name);
- if (filename == NULL)
- {
- return(0);
- }
-
- TARGET_NATIVE_FILE_OPEN_CREATE(filename,fd,result);
- if (result != TARGET_NATIVE_OK)
- {
- /* XXX ??? NYI */
- if (errno != EEXIST)
- JCL_ThrowException(env,
- "java/io/IOException",
- TARGET_NATIVE_LAST_ERROR_STRING());
- return(0);
- }
- TARGET_NATIVE_FILE_CLOSE(fd,result);
-
- return(1);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method checks to see if we have read permission on a file.
- *
- * Class: java_io_File
- * Method: canReadInternal
- * Signature: (Ljava/lang/String;)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_canReadInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- int fd;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- filename = (*env)->GetStringUTFChars(env, name, 0);
- if (filename == NULL)
- {
- return(0);
- }
-
- /* The lazy man's way out. We actually do open the file for reading
- briefly to verify it can be done */
- TARGET_NATIVE_FILE_OPEN_READ(filename,fd,result);
- (*env)->ReleaseStringUTFChars(env, name, filename);
- if (result != TARGET_NATIVE_OK)
- {
- return(0);
- }
- TARGET_NATIVE_FILE_CLOSE(fd,result);
-
- return(1);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method checks to see if we have write permission on a file.
- *
- * Class: java_io_File
- * Method: canWriteInternal
- * Signature: (Ljava/lang/String;)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_canWriteInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- int fd;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- filename = (*env)->GetStringUTFChars(env, name, 0);
- if (filename == NULL)
- {
- return(0);
- }
-
- /* The lazy man's way out. We actually do open the file for writing
- briefly to verify it can be done */
- TARGET_NATIVE_FILE_OPEN_READWRITE(filename,fd,result);
- (*env)->ReleaseStringUTFChars(env, name, filename);
- if (result != TARGET_NATIVE_OK)
- {
- return(0);
- }
- TARGET_NATIVE_FILE_CLOSE(fd,result);
-
- return(1);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method makes a file read only.
- *
- * Class: java_io_File
- * Method: setReadOnlyInternal
- * Signature: (Ljava/lang/String;)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_setReadOnlyInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- filename = (*env)->GetStringUTFChars(env, name, 0);
- if (filename == NULL)
- {
- return(0);
- }
-
- TARGET_NATIVE_FILE_SET_MODE_READONLY(filename,result);
- (*env)->ReleaseStringUTFChars(env, name, filename);
-
- return ((result == TARGET_NATIVE_OK)?1:0);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method checks to see if a file exists.
- *
- * Class: java_io_File
- * Method: existsInternal
- * Signature: (Ljava/lang/String;)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_existsInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- filename = (*env)->GetStringUTFChars(env, name, 0);
- if (filename == NULL)
- {
- return(0);
- }
-
- TARGET_NATIVE_FILE_EXISTS(filename,result);
- (*env)->ReleaseStringUTFChars(env, name, filename);
-
- return ((result == TARGET_NATIVE_OK)?1:0);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method checks to see if a file is a "plain" file; that is, not
- * a directory, pipe, etc.
- *
- * Class: java_io_File
- * Method: isFileInternal
- * Signature: (Ljava/lang/String;)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_isFileInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- filename = (*env)->GetStringUTFChars(env, name, 0);
- if (filename == NULL)
- {
- return(0);
- }
-
- TARGET_NATIVE_FILE_IS_FILE(filename,result);
- (*env)->ReleaseStringUTFChars(env, name, filename);
-
- return ((result == TARGET_NATIVE_OK)?1:0);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method checks to see if a file is a directory or not.
- *
- * Class: java_io_File
- * Method: isDirectoryInternal
- * Signature: (Ljava/lang/String;)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_isDirectoryInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- filename = (*env)->GetStringUTFChars(env, name, 0);
- if (filename == NULL)
- {
- return(0);
- }
-
- TARGET_NATIVE_FILE_IS_DIRECTORY(filename,result);
- (*env)->ReleaseStringUTFChars(env, name, filename);
-
- return ((result == TARGET_NATIVE_OK)?1:0);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method returns the length of the file.
- *
- * Class: java_io_File
- * Method: lengthInternal
- * Signature: (Ljava/lang/String;)J
- */
-
-JNIEXPORT jlong JNICALL
-Java_java_io_File_lengthInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- int tmpfd;
- jlong length;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- filename = (*env)->GetStringUTFChars(env, name, 0);
- if (filename == NULL)
- {
- return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
- }
-
- /* open file for reading, get size and close file */
- TARGET_NATIVE_FILE_OPEN_READ(filename,tmpfd,result);
- if (result != TARGET_NATIVE_OK)
- {
- return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
- }
- TARGET_NATIVE_FILE_SIZE(tmpfd,length,result);
- if (result != TARGET_NATIVE_OK)
- {
- TARGET_NATIVE_FILE_CLOSE(tmpfd,result);
- return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
- }
- TARGET_NATIVE_FILE_CLOSE(tmpfd,result);
- (*env)->ReleaseStringUTFChars(env, name, filename);
-
- return ((result == TARGET_NATIVE_OK)?length:TARGET_NATIVE_MATH_INT_INT64_CONST_0);
-#else /* not WITHOUT_FILESYSTEM */
- return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method returns the modification date of the file.
- *
- * Class: java_io_File
- * Method: lastModifiedInternal
- * Signature: (Ljava/lang/String;)J
- */
-
-JNIEXPORT jlong JNICALL
-Java_java_io_File_lastModifiedInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- jlong mtime;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- filename = (*env)->GetStringUTFChars(env, name, 0);
- if (filename == NULL)
- {
- return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
- }
-
- TARGET_NATIVE_FILE_GET_LAST_MODIFIED(filename,mtime,result);
- (*env)->ReleaseStringUTFChars(env, name, filename);
-
- return ((result == TARGET_NATIVE_OK)?mtime:TARGET_NATIVE_MATH_INT_INT64_CONST_0);
-#else /* not WITHOUT_FILESYSTEM */
- return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method sets the modification date of the file.
- *
- * Class: java_io_File
- * Method: setLastModifiedInternal
- * Signature: (Ljava/lang/String;J)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_setLastModifiedInternal(JNIEnv *env, jobject obj,
- jstring name, jlong newtime)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- filename = (*env)->GetStringUTFChars(env, name, 0);
- if (filename == NULL)
- {
- return(0);
- }
-
- TARGET_NATIVE_FILE_SET_LAST_MODIFIED(filename,newtime,result);
- (*env)->ReleaseStringUTFChars(env, name, filename);
-
- return ((result == TARGET_NATIVE_OK)?1:0);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method deletes a file (actually a name for a file - additional
- * links could exist).
- *
- * Class: java_io_File
- * Method: deleteInternal
- * Signature: (Ljava/lang/String;)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_deleteInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *filename;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- filename = (*env)->GetStringUTFChars(env, name, 0);
- if (filename == NULL)
- {
- return(0);
- }
-
- TARGET_NATIVE_FILE_DELETE(filename,result);
- (*env)->ReleaseStringUTFChars(env, name, filename);
-
- return ((result == TARGET_NATIVE_OK)?1:0);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method creates a directory.
- *
- * Class: java_io_File
- * Method: mkdirInternal
- * Signature: (Ljava/lang/String;)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_mkdirInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *pathname;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- pathname = (*env)->GetStringUTFChars(env, name, 0);
- if (pathname == NULL)
- {
- return(0);
- }
-
- TARGET_NATIVE_FILE_MAKE_DIR(pathname,result);
- (*env)->ReleaseStringUTFChars(env, name, pathname);
-
- return ((result == TARGET_NATIVE_OK)?1:0);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method renames a (link to a) file.
- *
- * Class: java_io_File
- * Method: renameToInternal
- * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
- */
-
-JNIEXPORT jboolean JNICALL
-Java_java_io_File_renameToInternal(JNIEnv *env, jobject obj, jstring t, jstring d)
-{
-#ifndef WITHOUT_FILESYSTEM
- const char *old_filename, *new_filename;
- int result;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- old_filename = (*env)->GetStringUTFChars(env, t, 0);
- if (old_filename == NULL)
- {
- return(0);
- }
-
- new_filename = (*env)->GetStringUTFChars(env, d, 0);
- if (new_filename == NULL)
- {
- (*env)->ReleaseStringUTFChars(env, t, old_filename);
- return(0);
- }
-
- TARGET_NATIVE_FILE_RENAME(old_filename,new_filename,result);
- (*env)->ReleaseStringUTFChars(env, d, new_filename);
- (*env)->ReleaseStringUTFChars(env, t, old_filename);
-
- return ((result == TARGET_NATIVE_OK)?1:0);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
-/*************************************************************************/
-
-/*
- * This method returns an array of String representing all the files
- * in a directory except "." and "..".
- *
- * Class: java_io_File
- * Method: listInternal
- * Signature: (Ljava/lang/String;)[Ljava/lang/String;
- */
-
-JNIEXPORT jobjectArray JNICALL
-Java_java_io_File_listInternal(JNIEnv *env, jobject obj, jstring name)
-{
-#ifndef WITHOUT_FILESYSTEM
- const int REALLOC_SIZE = 10;
-
- const char *dirname;
- int result;
- char **filelist;
- void *handle;
- const char *filename;
- unsigned long int filelist_count,max_filelist_count;
- char **tmp_filelist;
- jclass str_clazz;
- jobjectArray filearray;
- unsigned long int i;
- jstring str;
-
- /* Don't use the JCL convert function because it throws an exception
- on failure */
- dirname = (*env)->GetStringUTFChars(env, name, 0);
- if (dirname == NULL)
- {
- return(0);
- }
-
- /* open directory for reading */
- TARGET_NATIVE_FILE_OPEN_DIR(dirname,handle,result);
-
- (*env)->ReleaseStringUTFChars(env, name, dirname);
-
- if (result != TARGET_NATIVE_OK)
- {
- return(0);
- }
-
- /* allocate filelist */
- filelist = (char **)JCL_malloc(env, sizeof(char *) * REALLOC_SIZE);
- if (filelist==NULL)
- {
- TARGET_NATIVE_FILE_CLOSE_DIR(handle,result);
- return(0);
- }
- filelist_count=0;
- max_filelist_count=REALLOC_SIZE;
-
- /* read the files from the directory */
- TARGET_NATIVE_FILE_READ_DIR(handle,filename,result);
- while (result == TARGET_NATIVE_OK)
- {
- if ((strcmp(filename, ".")!=0) && (strcmp(filename, "..")!=0))
- {
- /* allocate more memory if necessary */
- if (filelist_count >= max_filelist_count)
- {
- tmp_filelist = (char**)JCL_realloc(env,
- filelist,
- (max_filelist_count + REALLOC_SIZE) * sizeof(char*));
- if (tmp_filelist==NULL)
- {
- for (i = 0; i < filelist_count; i++)
- {
- JCL_free(env,filelist[i]);
- }
- JCL_free(env,filelist);
- TARGET_NATIVE_FILE_CLOSE_DIR(handle,result);
- return(0);
- }
- filelist = tmp_filelist;
- max_filelist_count += REALLOC_SIZE;
- }
-
- /* save entry in list (avoid strdup, because it is not ANSI C, thus difficult to port) */
- filelist[filelist_count]=(char*)JCL_malloc(env,strlen(filename)+1);
- assert(filelist[filelist_count]!=NULL);
- strcpy(filelist[filelist_count],filename);
- filelist_count++;
- }
-
- /* read next directory entry */
- TARGET_NATIVE_FILE_READ_DIR(handle,filename,result);
- }
-
- /* close directory */
- TARGET_NATIVE_FILE_CLOSE_DIR(handle,result);
-
- /* put the list of files into a Java String array and return it */
- str_clazz = (*env)->FindClass(env, "java/lang/String");
- if (str_clazz==NULL)
- {
- for (i = 0; i < filelist_count; i++)
- {
- JCL_free(env,filelist[i]);
- }
- JCL_free(env,filelist);
- return(0);
- }
- filearray = (*env)->NewObjectArray(env, filelist_count, str_clazz, 0);
- if (filearray==NULL)
- {
- for (i = 0; i < filelist_count; i++)
- {
- JCL_free(env,filelist[i]);
- }
- JCL_free(env,filelist);
- return(0);
- }
- for (i = 0; i < filelist_count; i++)
- {
- /* create new string */
- str = (*env)->NewStringUTF(env, filelist[i]);
- if (str==NULL)
- {
- /* We don't clean up everything here, but if this failed,
- something serious happened anyway */
- for (i = 0; i < filelist_count; i++)
- {
- JCL_free(env,filelist[i]);
- }
- JCL_free(env,filelist);
- return(0);
- }
-
- /* save into array */
- (*env)->SetObjectArrayElement(env, filearray, i, str);
-
- /* delete local reference */
- (*env)->DeleteLocalRef(env, str);
- }
-
- /* free resources */
- for (i = 0; i < filelist_count; i++)
- {
- JCL_free(env,filelist[i]);
- }
- JCL_free(env,filelist);
-
- return(filearray);
-#else /* not WITHOUT_FILESYSTEM */
- return(0);
-#endif /* not WITHOUT_FILESYSTEM */
-}
-
Index: native/jni/java-io/java_io_VMFile.c
===================================================================
RCS file: native/jni/java-io/java_io_VMFile.c
diff -N native/jni/java-io/java_io_VMFile.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ native/jni/java-io/java_io_VMFile.c 26 Apr 2004 20:48:23 -0000
@@ -0,0 +1,702 @@
+/* java_io_VMFile.c - Native methods for java.io.File class
+ Copyright (C) 1998, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+/* do not move; needed here because of some macro definitions */
+#include
+
+#include
+#include
+
+#include
+#include
+
+#include "target_native.h"
+#ifndef WITHOUT_FILESYSTEM
+ #include "target_native_file.h"
+#endif
+#include "target_native_math_int.h"
+
+#include "javaio.h"
+
+#include "java_io_VMFile.h"
+
+/*************************************************************************/
+
+/*
+ * Method to create an empty file.
+ *
+ * Class: java_io_VMFile
+ * Method: create
+ * Signature: (Ljava/lang/String;)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_create(JNIEnv *env, jclass clazz, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ int fd;
+ int result;
+
+ filename = JCL_jstring_to_cstring(env, name);
+ if (filename == NULL)
+ {
+ return(0);
+ }
+
+ TARGET_NATIVE_FILE_OPEN_CREATE(filename,fd,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ /* XXX ??? NYI */
+ if (errno != EEXIST)
+ JCL_ThrowException(env,
+ "java/io/IOException",
+ TARGET_NATIVE_LAST_ERROR_STRING());
+ return(0);
+ }
+ TARGET_NATIVE_FILE_CLOSE(fd,result);
+
+ return(1);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method checks to see if we have read permission on a file.
+ *
+ * Class: java_io_VMFile
+ * Method: canRead
+ * Signature: (Ljava/lang/String;)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_canRead(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ int fd;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ filename = (*env)->GetStringUTFChars(env, name, 0);
+ if (filename == NULL)
+ {
+ return(0);
+ }
+
+ /* The lazy man's way out. We actually do open the file for reading
+ briefly to verify it can be done */
+ TARGET_NATIVE_FILE_OPEN_READ(filename,fd,result);
+ (*env)->ReleaseStringUTFChars(env, name, filename);
+ if (result != TARGET_NATIVE_OK)
+ {
+ return(0);
+ }
+ TARGET_NATIVE_FILE_CLOSE(fd,result);
+
+ return(1);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method checks to see if we have write permission on a file.
+ *
+ * Class: java_io_VMFile
+ * Method: canWrite
+ * Signature: (Ljava/lang/String;)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_canWrite(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ int fd;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ filename = (*env)->GetStringUTFChars(env, name, 0);
+ if (filename == NULL)
+ {
+ return(0);
+ }
+
+ /* The lazy man's way out. We actually do open the file for writing
+ briefly to verify it can be done */
+ TARGET_NATIVE_FILE_OPEN_READWRITE(filename,fd,result);
+ (*env)->ReleaseStringUTFChars(env, name, filename);
+ if (result != TARGET_NATIVE_OK)
+ {
+ return(0);
+ }
+ TARGET_NATIVE_FILE_CLOSE(fd,result);
+
+ return(1);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method makes a file read only.
+ *
+ * Class: java_io_VMFile
+ * Method: setReadOnly
+ * Signature: (Ljava/lang/String;)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_setReadOnly(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ filename = (*env)->GetStringUTFChars(env, name, 0);
+ if (filename == NULL)
+ {
+ return(0);
+ }
+
+ TARGET_NATIVE_FILE_SET_MODE_READONLY(filename,result);
+ (*env)->ReleaseStringUTFChars(env, name, filename);
+
+ return ((result == TARGET_NATIVE_OK)?1:0);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method checks to see if a file exists.
+ *
+ * Class: java_io_VMFile
+ * Method: exists
+ * Signature: (Ljava/lang/String;)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_exists(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ filename = (*env)->GetStringUTFChars(env, name, 0);
+ if (filename == NULL)
+ {
+ return(0);
+ }
+
+ TARGET_NATIVE_FILE_EXISTS(filename,result);
+ (*env)->ReleaseStringUTFChars(env, name, filename);
+
+ return ((result == TARGET_NATIVE_OK)?1:0);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method checks to see if a file is a "plain" file; that is, not
+ * a directory, pipe, etc.
+ *
+ * Class: java_io_VMFile
+ * Method: isFile
+ * Signature: (Ljava/lang/String;)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_isFile(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ filename = (*env)->GetStringUTFChars(env, name, 0);
+ if (filename == NULL)
+ {
+ return(0);
+ }
+
+ TARGET_NATIVE_FILE_IS_FILE(filename,result);
+ (*env)->ReleaseStringUTFChars(env, name, filename);
+
+ return ((result == TARGET_NATIVE_OK)?1:0);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method checks to see if a file is a directory or not.
+ *
+ * Class: java_io_VMFile
+ * Method: isDirectory
+ * Signature: (Ljava/lang/String;)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_isDirectory(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ filename = (*env)->GetStringUTFChars(env, name, 0);
+ if (filename == NULL)
+ {
+ return(0);
+ }
+
+ TARGET_NATIVE_FILE_IS_DIRECTORY(filename,result);
+ (*env)->ReleaseStringUTFChars(env, name, filename);
+
+ return ((result == TARGET_NATIVE_OK)?1:0);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method returns the length of the file.
+ *
+ * Class: java_io_VMFile
+ * Method: length
+ * Signature: (Ljava/lang/String;)J
+ */
+
+JNIEXPORT jlong JNICALL
+Java_java_io_VMFile_length(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ int tmpfd;
+ jlong length;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ filename = (*env)->GetStringUTFChars(env, name, 0);
+ if (filename == NULL)
+ {
+ return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
+ }
+
+ /* open file for reading, get size and close file */
+ TARGET_NATIVE_FILE_OPEN_READ(filename,tmpfd,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
+ }
+ TARGET_NATIVE_FILE_SIZE(tmpfd,length,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ TARGET_NATIVE_FILE_CLOSE(tmpfd,result);
+ return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
+ }
+ TARGET_NATIVE_FILE_CLOSE(tmpfd,result);
+ (*env)->ReleaseStringUTFChars(env, name, filename);
+
+ return ((result == TARGET_NATIVE_OK)?length:TARGET_NATIVE_MATH_INT_INT64_CONST_0);
+#else /* not WITHOUT_FILESYSTEM */
+ return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method returns the modification date of the file.
+ *
+ * Class: java_io_VMFile
+ * Method: lastModified
+ * Signature: (Ljava/lang/String;)J
+ */
+
+JNIEXPORT jlong JNICALL
+Java_java_io_VMFile_lastModified(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ jlong mtime;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ filename = (*env)->GetStringUTFChars(env, name, 0);
+ if (filename == NULL)
+ {
+ return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
+ }
+
+ TARGET_NATIVE_FILE_GET_LAST_MODIFIED(filename,mtime,result);
+ (*env)->ReleaseStringUTFChars(env, name, filename);
+
+ return ((result == TARGET_NATIVE_OK)?mtime:TARGET_NATIVE_MATH_INT_INT64_CONST_0);
+#else /* not WITHOUT_FILESYSTEM */
+ return(TARGET_NATIVE_MATH_INT_INT64_CONST_0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method sets the modification date of the file.
+ *
+ * Class: java_io_VMFile
+ * Method: setLastModified
+ * Signature: (Ljava/lang/String;J)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_setLastModified(JNIEnv *env, jobject obj,
+ jstring name, jlong newtime)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ filename = (*env)->GetStringUTFChars(env, name, 0);
+ if (filename == NULL)
+ {
+ return(0);
+ }
+
+ TARGET_NATIVE_FILE_SET_LAST_MODIFIED(filename,newtime,result);
+ (*env)->ReleaseStringUTFChars(env, name, filename);
+
+ return ((result == TARGET_NATIVE_OK)?1:0);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method deletes a file (actually a name for a file - additional
+ * links could exist).
+ *
+ * Class: java_io_VMFile
+ * Method: delete
+ * Signature: (Ljava/lang/String;)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_delete(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *filename;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ filename = (*env)->GetStringUTFChars(env, name, 0);
+ if (filename == NULL)
+ {
+ return(0);
+ }
+
+ TARGET_NATIVE_FILE_DELETE(filename,result);
+ (*env)->ReleaseStringUTFChars(env, name, filename);
+
+ return ((result == TARGET_NATIVE_OK)?1:0);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method creates a directory.
+ *
+ * Class: java_io_VMFile
+ * Method: mkdir
+ * Signature: (Ljava/lang/String;)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_mkdir(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *pathname;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ pathname = (*env)->GetStringUTFChars(env, name, 0);
+ if (pathname == NULL)
+ {
+ return(0);
+ }
+
+ TARGET_NATIVE_FILE_MAKE_DIR(pathname,result);
+ (*env)->ReleaseStringUTFChars(env, name, pathname);
+
+ return ((result == TARGET_NATIVE_OK)?1:0);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method renames a (link to a) file.
+ *
+ * Class: java_io_VMFile
+ * Method: renameTo
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
+ */
+
+JNIEXPORT jboolean JNICALL
+Java_java_io_VMFile_renameTo(JNIEnv *env, jobject obj, jstring t, jstring d)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const char *old_filename, *new_filename;
+ int result;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ old_filename = (*env)->GetStringUTFChars(env, t, 0);
+ if (old_filename == NULL)
+ {
+ return(0);
+ }
+
+ new_filename = (*env)->GetStringUTFChars(env, d, 0);
+ if (new_filename == NULL)
+ {
+ (*env)->ReleaseStringUTFChars(env, t, old_filename);
+ return(0);
+ }
+
+ TARGET_NATIVE_FILE_RENAME(old_filename,new_filename,result);
+ (*env)->ReleaseStringUTFChars(env, d, new_filename);
+ (*env)->ReleaseStringUTFChars(env, t, old_filename);
+
+ return ((result == TARGET_NATIVE_OK)?1:0);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
+/*************************************************************************/
+
+/*
+ * This method returns an array of String representing all the files
+ * in a directory except "." and "..".
+ *
+ * Class: java_io_VMFile
+ * Method: list
+ * Signature: (Ljava/lang/String;)[Ljava/lang/String;
+ */
+
+JNIEXPORT jobjectArray JNICALL
+Java_java_io_VMFile_list(JNIEnv *env, jobject obj, jstring name)
+{
+#ifndef WITHOUT_FILESYSTEM
+ const int REALLOC_SIZE = 10;
+
+ const char *dirname;
+ int result;
+ char **filelist;
+ void *handle;
+ const char *filename;
+ unsigned long int filelist_count,max_filelist_count;
+ char **tmp_filelist;
+ jclass str_clazz;
+ jobjectArray filearray;
+ unsigned long int i;
+ jstring str;
+
+ /* Don't use the JCL convert function because it throws an exception
+ on failure */
+ dirname = (*env)->GetStringUTFChars(env, name, 0);
+ if (dirname == NULL)
+ {
+ return(0);
+ }
+
+ /* open directory for reading */
+ TARGET_NATIVE_FILE_OPEN_DIR(dirname,handle,result);
+
+ (*env)->ReleaseStringUTFChars(env, name, dirname);
+
+ if (result != TARGET_NATIVE_OK)
+ {
+ return(0);
+ }
+
+ /* allocate filelist */
+ filelist = (char **)JCL_malloc(env, sizeof(char *) * REALLOC_SIZE);
+ if (filelist==NULL)
+ {
+ TARGET_NATIVE_FILE_CLOSE_DIR(handle,result);
+ return(0);
+ }
+ filelist_count=0;
+ max_filelist_count=REALLOC_SIZE;
+
+ /* read the files from the directory */
+ TARGET_NATIVE_FILE_READ_DIR(handle,filename,result);
+ while (result == TARGET_NATIVE_OK)
+ {
+ if ((strcmp(filename, ".")!=0) && (strcmp(filename, "..")!=0))
+ {
+ /* allocate more memory if necessary */
+ if (filelist_count >= max_filelist_count)
+ {
+ tmp_filelist = (char**)JCL_realloc(env,
+ filelist,
+ (max_filelist_count + REALLOC_SIZE) * sizeof(char*));
+ if (tmp_filelist==NULL)
+ {
+ for (i = 0; i < filelist_count; i++)
+ {
+ JCL_free(env,filelist[i]);
+ }
+ JCL_free(env,filelist);
+ TARGET_NATIVE_FILE_CLOSE_DIR(handle,result);
+ return(0);
+ }
+ filelist = tmp_filelist;
+ max_filelist_count += REALLOC_SIZE;
+ }
+
+ /* save entry in list (avoid strdup, because it is not ANSI C, thus difficult to port) */
+ filelist[filelist_count]=(char*)JCL_malloc(env,strlen(filename)+1);
+ assert(filelist[filelist_count]!=NULL);
+ strcpy(filelist[filelist_count],filename);
+ filelist_count++;
+ }
+
+ /* read next directory entry */
+ TARGET_NATIVE_FILE_READ_DIR(handle,filename,result);
+ }
+
+ /* close directory */
+ TARGET_NATIVE_FILE_CLOSE_DIR(handle,result);
+
+ /* put the list of files into a Java String array and return it */
+ str_clazz = (*env)->FindClass(env, "java/lang/String");
+ if (str_clazz==NULL)
+ {
+ for (i = 0; i < filelist_count; i++)
+ {
+ JCL_free(env,filelist[i]);
+ }
+ JCL_free(env,filelist);
+ return(0);
+ }
+ filearray = (*env)->NewObjectArray(env, filelist_count, str_clazz, 0);
+ if (filearray==NULL)
+ {
+ for (i = 0; i < filelist_count; i++)
+ {
+ JCL_free(env,filelist[i]);
+ }
+ JCL_free(env,filelist);
+ return(0);
+ }
+ for (i = 0; i < filelist_count; i++)
+ {
+ /* create new string */
+ str = (*env)->NewStringUTF(env, filelist[i]);
+ if (str==NULL)
+ {
+ /* We don't clean up everything here, but if this failed,
+ something serious happened anyway */
+ for (i = 0; i < filelist_count; i++)
+ {
+ JCL_free(env,filelist[i]);
+ }
+ JCL_free(env,filelist);
+ return(0);
+ }
+
+ /* save into array */
+ (*env)->SetObjectArrayElement(env, filearray, i, str);
+
+ /* delete local reference */
+ (*env)->DeleteLocalRef(env, str);
+ }
+
+ /* free resources */
+ for (i = 0; i < filelist_count; i++)
+ {
+ JCL_free(env,filelist[i]);
+ }
+ JCL_free(env,filelist);
+
+ return(filearray);
+#else /* not WITHOUT_FILESYSTEM */
+ return(0);
+#endif /* not WITHOUT_FILESYSTEM */
+}
+
Index: native/jni/java-io/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-io/Makefile.am,v
retrieving revision 1.15
diff -u -r1.15 Makefile.am
--- native/jni/java-io/Makefile.am 12 Apr 2004 14:38:55 -0000 1.15
+++ native/jni/java-io/Makefile.am 26 Apr 2004 20:48:23 -0000
@@ -2,8 +2,8 @@
libjavaio_la_SOURCES = javaio.h \
javaio.c \
- java_io_File.c \
java_io_ObjectInputStream.c \
+ java_io_VMFile.c \
java_io_VMObjectStreamClass.c
libjavaio_la_LDFLAGS = @CLASSPATH_MODULE@