This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: Moving native methods fo java.io.File into java.io.VMFile
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 15 Sep 2004 15:02:32 +0200
- Subject: Patch: Moving native methods fo java.io.File into java.io.VMFile
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I have written the attached patch to move the native methods from
java.io.File to java.ioVMFile. This allows us merging java.io.File
with GNU classpath. This is important to merge fixes fast in both
directions. GNU classpath has some fixes (security and file
truncation) which are still not completely merge because of the
current differences.
Mohan Embar has helped with the Win32 part of the code. He bugfixed
and tested my changes to it.
Andreas Tobler has tested the patch on his multiple platforms with
mauve. Some Mauve tests are sometimes failing and sometimes passes
(Even before this patch). I will investigate this when the patch is
in.
Okay to commit to trunk ?
Michael
2004-09-15 Michael Koch <konqueror@gmx.de>
Mohan Embar <gnustuff@thisiscool.com>
* java/io/File.java: Moved all native methods to VMFile.
* java/io/VMFile.java: New file.
* gcj/javaprims.h: Added java.io.VMFile class.
* java/io/natFilePosix.cc, java/io/natFileWin32.cc:
Moved all methods to java.io.VMFile class.
* Makefile.am: Added java/io/VMFile.java.
* Makefile.in: Regenerated.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBSD1sWSOgCCdjSDsRAvkXAJwJ9xx989YNgBFoaVXneysCkivDdgCggPs5
bT1LXEa0hhUlQX5eF2RQGTo=
=/6rM
-----END PGP SIGNATURE-----
Index: gcj/javaprims.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gcj/javaprims.h,v
retrieving revision 1.52
diff -u -r1.52 javaprims.h
--- gcj/javaprims.h 12 Aug 2004 16:20:09 -0000 1.52
+++ gcj/javaprims.h 15 Sep 2004 12:48:34 -0000
@@ -121,6 +121,7 @@
class SyncFailedException;
class UTFDataFormatException;
class UnsupportedEncodingException;
+ class VMFile;
class VMObjectStreamClass;
class ValidatorAndPriority;
class WriteAbortedException;
Index: java/io/File.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/File.java,v
retrieving revision 1.42
diff -u -r1.42 File.java
--- java/io/File.java 9 Sep 2004 09:43:33 -0000 1.42
+++ java/io/File.java 15 Sep 2004 12:48:34 -0000
@@ -43,7 +43,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import gnu.classpath.Configuration;
import gnu.gcj.runtime.FileDeleter;
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
@@ -63,27 +62,6 @@
public class File implements Serializable, Comparable
{
private static final long serialVersionUID = 301077366599181567L;
-
- // QUERY arguments to access function.
- private final static int READ = 0;
- private final static int WRITE = 1;
- private final static int EXISTS = 2;
-
- // QUERY arguments to stat function.
- private final static int DIRECTORY = 0;
- private final static int ISFILE = 1;
- private final static int ISHIDDEN = 2;
-
- // QUERY arguments to attr function.
- private final static int MODIFIED = 0;
- private final static int LENGTH = 1;
-
- private final native long attr (int query);
- // On OSF1 V5.0, `stat' is a macro. It is easiest to use the name
- // `_stat' instead. We do the same thing for `_access' just in
- // case.
- private final native boolean _access (int query);
- private final native boolean _stat (int query);
/**
* This is the path separator string for the current host. This field
@@ -116,24 +94,6 @@
*/
public static final char pathSeparatorChar = pathSeparator.charAt(0);
- static final String tmpdir = System.getProperty("java.io.tmpdir");
- static int maxPathLen;
- static boolean caseSensitive;
-
- static
- {
- if (Configuration.INIT_LOAD_LIBRARY)
- {
- System.loadLibrary("javaio");
- }
-
- init_native();
- }
-
- // Native function called at class initialization. This should should
- // set the maxPathLen and caseSensitive variables.
- private static native void init_native();
-
/**
* This is the path to the file set when the object is created. It
* may be an absolute or relative path name.
@@ -159,8 +119,11 @@
*/
public boolean canRead()
{
- checkRead();
- return _access (READ);
+ // Test for existence. This also does the SecurityManager check
+ if (!exists())
+ return false;
+
+ return VMFile.canRead(path);
}
/**
@@ -179,11 +142,33 @@
*/
public boolean canWrite()
{
+ // First do a SecurityCheck before doing anything else.
checkWrite();
- return _access (WRITE);
+
+ // Test for existence. This is required by the spec
+ if (! VMFile.exists(path))
+ return false;
+
+ if (!VMFile.isDirectory(path))
+ return VMFile.canWrite(path);
+ else
+ try
+ {
+ /* If the separator is '\' a DOS-style-filesystem is assumed
+ and a short name is used, otherwise use a long name.
+ WARNING: some implementation of DOS-style-filesystems also
+ accept '/' as separator. In that case the following code
+ will fail.
+ */
+ String filename = (separatorChar!='\\')?"test-dir-write":"tst";
+ File test = createTempFile(filename, null, this);
+ return (test != null && test.delete());
+ }
+ catch (IOException ioe)
+ {
+ return false;
+ }
}
-
- private native boolean performCreate() throws IOException;
/**
* This method creates a new file of zero length with the same name as
@@ -205,14 +190,8 @@
public boolean createNewFile() throws IOException
{
checkWrite();
- return performCreate();
+ return VMFile.create(path);
}
-
- /*
- * This native method handles the actual deleting of the file
- */
- private native boolean performDelete();
-
/**
* 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.
@@ -229,7 +208,7 @@
if (s != null)
s.checkDelete(path);
- return performDelete();
+ return VMFile.deleteFile(path);
}
/**
@@ -254,7 +233,7 @@
File other = (File) obj;
- if (caseSensitive)
+ if (VMFile.caseSensitive)
return path.equals(other.path);
else
return path.equalsIgnoreCase(other.path);
@@ -271,7 +250,7 @@
public boolean exists()
{
checkRead();
- return _access (EXISTS);
+ return VMFile.exists(path);
}
/**
@@ -515,7 +494,10 @@
*
* @exception IOException If an error occurs
*/
- public native String getCanonicalPath() throws IOException;
+ public String getCanonicalPath() throws IOException
+ {
+ return VMFile.getCanonicalPath(path);
+ }
/**
* This method returns a <code>File</code> object representing the
@@ -665,7 +647,7 @@
*/
public int hashCode()
{
- if (caseSensitive)
+ if (VMFile.caseSensitive)
return path.hashCode() ^ 1234321;
else
return path.toLowerCase().hashCode() ^ 1234321;
@@ -680,7 +662,10 @@
* @return <code>true</code> if this object represents an absolute
* file name, <code>false</code> otherwise.
*/
- public native boolean isAbsolute();
+ public boolean isAbsolute()
+ {
+ return VMFile.isAbsolute(path);
+ }
/**
* This method tests whether or not the file represented by this object
@@ -695,7 +680,7 @@
public boolean isDirectory()
{
checkRead();
- return _stat (DIRECTORY);
+ return VMFile.isDirectory(path);
}
/**
@@ -711,7 +696,7 @@
public boolean isFile()
{
checkRead();
- return _stat (ISFILE);
+ return VMFile.isFile(path);
}
/**
@@ -728,7 +713,7 @@
public boolean isHidden()
{
checkRead();
- return _stat (ISHIDDEN);
+ return VMFile.isHidden(path);
}
/**
@@ -747,7 +732,7 @@
public long lastModified()
{
checkRead();
- return attr (MODIFIED);
+ return VMFile.lastModified(path);
}
/**
@@ -761,17 +746,9 @@
public long length()
{
checkRead();
- return attr (LENGTH);
+ return VMFile.length(path);
}
- /*
- * This native function actually produces the list of file in this
- * directory
- */
- private final native Object[] performList (FilenameFilter filter,
- FileFilter fileFilter,
- Class result_type);
-
/**
* This method returns a array of <code>String</code>'s representing the
* list of files is then directory represented by this object. If this
@@ -802,7 +779,7 @@
public String[] list(FilenameFilter filter)
{
checkRead();
- return (String[]) performList (filter, null, String.class);
+ return (String[]) VMFile.list(this, filter, null, String.class);
}
/**
@@ -825,8 +802,7 @@
*/
public String[] list()
{
- checkRead();
- return (String[]) performList (null, null, String.class);
+ return list(null);
}
/**
@@ -849,8 +825,7 @@
*/
public File[] listFiles()
{
- checkRead();
- return (File[]) performList (null, null, File.class);
+ return listFiles((FilenameFilter) null);
}
/**
@@ -880,7 +855,7 @@
public File[] listFiles(FilenameFilter filter)
{
checkRead();
- return (File[]) performList (filter, null, File.class);
+ return (File[]) VMFile.list(this, filter, null, File.class);
}
/**
@@ -910,7 +885,7 @@
public File[] listFiles(FileFilter filter)
{
checkRead();
- return (File[]) performList (null, filter, File.class);
+ return (File[]) VMFile.list(this, null, filter, File.class);
}
/**
@@ -967,11 +942,6 @@
+ (isDirectory() ? "/" : ""));
}
- /*
- * This native method actually creates the directory
- */
- private final native boolean performMkdir();
-
/**
* This method creates a directory for the path represented by this object.
*
@@ -983,7 +953,7 @@
public boolean mkdir()
{
checkWrite();
- return performMkdir();
+ return VMFile.mkdir(path);
}
private static boolean mkdirs (File x)
@@ -1061,15 +1031,15 @@
// Grab the system temp directory if necessary
if (directory == null)
{
- String dirname = tmpdir;
+ String dirname = VMFile.tmpdir;
if (dirname == null)
throw new IOException("Cannot determine system temporary directory");
directory = new File(dirname);
- if (!directory.exists())
+ if (! VMFile.exists(directory.path))
throw new IOException("System temporary directory "
+ directory.getName() + " does not exist.");
- if (!directory.isDirectory())
+ if (! VMFile.isDirectory(directory.path))
throw new IOException("System temporary directory "
+ directory.getName()
+ " is not really a directory.");
@@ -1085,14 +1055,14 @@
// Truncation rules.
// `6' is the number of characters we generate.
- if (prefix.length() + 6 + suffix.length() > maxPathLen)
+ if (prefix.length() + 6 + suffix.length() > VMFile.maxPathLen)
{
int suf_len = 0;
if (suffix.charAt(0) == '.')
suf_len = 4;
suffix = suffix.substring(0, suf_len);
- if (prefix.length() + 6 + suf_len > maxPathLen)
- prefix = prefix.substring(0, maxPathLen - 6 - suf_len);
+ if (prefix.length() + 6 + suf_len > VMFile.maxPathLen)
+ prefix = prefix.substring(0, VMFile.maxPathLen - 6 - suf_len);
}
File f;
@@ -1117,11 +1087,6 @@
throw new IOException ("cannot create temporary file");
}
- /*
- * This native method sets the permissions to make the file read only.
- */
- private native boolean performSetReadOnly();
-
/**
* 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
@@ -1140,10 +1105,13 @@
{
// Do a security check before trying to do anything else.
checkWrite();
- return performSetReadOnly();
- }
- private static native File[] performListRoots();
+ // Test for existence.
+ if (! VMFile.exists(path))
+ return false;
+
+ return VMFile.setReadOnly(path);
+ }
/**
* This method returns an array of filesystem roots. Some operating systems
@@ -1158,7 +1126,7 @@
*/
public static File[] listRoots()
{
- File[] roots = performListRoots();
+ File[] roots = VMFile.listRoots();
SecurityManager s = System.getSecurityManager();
if (s != null)
@@ -1243,7 +1211,7 @@
*/
public int compareTo(File other)
{
- if (caseSensitive)
+ if (VMFile.caseSensitive)
return path.compareTo (other.path);
else
return path.compareToIgnoreCase (other.path);
@@ -1275,11 +1243,6 @@
return compareTo((File) obj);
}
- /*
- * This native method actually performs the rename.
- */
- private native boolean performRenameTo (File dest);
-
/**
* This method renames the file represented by this object to the path
* of the file represented by the argument <code>File</code>.
@@ -1294,22 +1257,12 @@
*/
public synchronized boolean renameTo(File dest)
{
- SecurityManager s = System.getSecurityManager();
- String sname = getName();
- String dname = dest.getName();
- if (s != null)
- {
- s.checkWrite (sname);
- s.checkWrite (dname);
- }
- return performRenameTo (dest);
+ checkWrite();
+ dest.checkWrite();
+ // Call our native rename method
+ return VMFile.renameTo(path, dest.path);
}
- /*
- * This method does the actual setting of the modification time.
- */
- private native boolean performSetLastModified(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
@@ -1332,7 +1285,7 @@
throw new IllegalArgumentException("Negative modification time: " + time);
checkWrite();
- return performSetLastModified(time);
+ return VMFile.setLastModified(path, time);
}
private void checkWrite()
Index: java/io/VMFile.java
===================================================================
RCS file: java/io/VMFile.java
diff -N java/io/VMFile.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/io/VMFile.java 15 Sep 2004 12:48:34 -0000
@@ -0,0 +1,235 @@
+/* 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;
+
+
+/**
+ * @author Michael Koch (konqueror@gmx.de)
+ */
+final class VMFile
+{
+ // QUERY arguments to access function.
+ private static int READ = 0;
+ private static int WRITE = 1;
+ private static int EXISTS = 2;
+
+ // QUERY arguments to stat function.
+ private static int DIRECTORY = 0;
+ private static int ISFILE = 1;
+ private static int ISHIDDEN = 2;
+
+ // QUERY arguments to attr function.
+ private static int MODIFIED = 0;
+ private static int LENGTH = 1;
+
+ private static native long attr (String path, int query);
+ // On OSF1 V5.0, `stat' is a macro. It is easiest to use the name
+ // `_stat' instead. We do the same thing for `_access' just in
+ // case.
+ private static native boolean _access (String path, int query);
+ private static native boolean _stat (String path, int query);
+
+ static String tmpdir = System.getProperty("java.io.tmpdir");
+ static int maxPathLen;
+ static boolean caseSensitive;
+
+ static
+ {
+ if (Configuration.INIT_LOAD_LIBRARY)
+ {
+ System.loadLibrary("javaio");
+ }
+
+ init_native();
+ }
+
+ // Native function called at class initialization. This should should
+ // set the maxPathLen and caseSensitive variables.
+ private static native void init_native();
+
+ /*
+ * 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 long lastModified(String path)
+ {
+ return attr(path, MODIFIED);
+ }
+
+ /*
+ * 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 Object[] list(File file,
+ FilenameFilter filter,
+ FileFilter fileFilter,
+ Class result_type);
+
+ /*
+ * 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 long length(String path)
+ {
+ return attr(path, LENGTH);
+ }
+
+ /*
+ * This native method does the actual checking of file existence.
+ */
+ static boolean exists(String path)
+ {
+ return _access(path, EXISTS);
+ }
+
+ /*
+ * This native method handles the actual deleting of the file
+ */
+ static native boolean deleteFile(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 boolean isFile(String path)
+ {
+ return _stat(path, ISFILE);
+ }
+
+ /**
+ * This native method checks file permissions for writing
+ */
+ static boolean canWrite(String path)
+ {
+ return _access(path, WRITE);
+ }
+
+ /**
+ * This native method checks file permissions for reading
+ */
+ static boolean canRead(String path)
+ {
+ return _access(path, READ);
+ }
+
+ /*
+ * 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 boolean isDirectory(String path)
+ {
+ return _stat(path, DIRECTORY);
+ }
+
+ /**
+ * 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 <code>File</code> objects for each filesystem root
+ * available.
+ *
+ * @since 1.2
+ */
+ static native File[] listRoots();
+
+ /**
+ * 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 <code>true</code> if the file is hidden, <code>false</code>
+ * otherwise.
+ *
+ * @since 1.2
+ */
+ static boolean isHidden(String path)
+ {
+ return _stat(path, ISHIDDEN);
+ }
+
+ /**
+ * This method returns a canonical representation of the pathname of
+ * the given path. The actual form of the canonical representation is
+ * different. On the GNU system, the canonical form differs from the
+ * absolute form in that all relative file references to "." and ".."
+ * are resolved and removed.
+ * <p>
+ * Note that this method, unlike the other methods which return path
+ * names, can throw an IOException. This is because native method
+ * might be required in order to resolve the canonical path
+ *
+ * @exception IOException If an error occurs
+ */
+ static native String getCanonicalPath(String path) throws IOException;
+
+ static native boolean isAbsolute(String path);
+}
Index: java/io/natFilePosix.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/natFilePosix.cc,v
retrieving revision 1.5
diff -u -r1.5 natFilePosix.cc
--- java/io/natFilePosix.cc 12 Sep 2003 01:08:18 -0000 1.5
+++ java/io/natFilePosix.cc 15 Sep 2004 12:48:34 -0000
@@ -28,6 +28,7 @@
#include <gcj/cni.h>
#include <jvm.h>
+#include <java/io/VMFile.h>
#include <java/io/File.h>
#include <java/io/IOException.h>
#include <java/util/ArrayList.h>
@@ -37,11 +38,9 @@
#include <java/lang/System.h>
jboolean
-java::io::File::_access (jint query)
+java::io::VMFile::_access (jstring path, jint query)
{
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
- buf[total] = '\0';
+ JV_TEMP_UTF_STRING(utfstr, path);
JvAssert (query == READ || query == WRITE || query == EXISTS);
#ifdef HAVE_ACCESS
int mode;
@@ -51,25 +50,23 @@
mode = W_OK;
else
mode = F_OK;
- return ::access (buf, mode) == 0;
+ return ::access (utfstr.buf(), mode) == 0;
#else
return false;
#endif
}
jboolean
-java::io::File::_stat (jint query)
+java::io::VMFile::_stat (jstring path, jint query)
{
+ JV_TEMP_UTF_STRING(utfstr, path);
+
if (query == ISHIDDEN)
- return getName()->charAt(0) == '.';
+ return utfstr.buf()[0] == '.';
#ifdef HAVE_STAT
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
- buf[total] = '\0';
-
struct stat sb;
- if (::stat (buf, &sb))
+ if (::stat (utfstr.buf(), &sb))
return false;
JvAssert (query == DIRECTORY || query == ISFILE);
@@ -81,16 +78,14 @@
}
jlong
-java::io::File::attr (jint query)
+java::io::VMFile::attr (jstring path, jint query)
{
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
- buf[total] = '\0';
+ JV_TEMP_UTF_STRING(utfstr, path);
#ifdef HAVE_STAT
struct stat sb;
// FIXME: not sure about return value here.
- if (::stat (buf, &sb))
+ if (::stat (utfstr.buf(), &sb))
return 0;
JvAssert (query == MODIFIED || query == LENGTH);
@@ -102,7 +97,7 @@
}
jstring
-java::io::File::getCanonicalPath (void)
+java::io::VMFile::getCanonicalPath (jstring path)
{
// We use `+2' here because we might need to use `.' for our special
// case.
@@ -192,31 +187,31 @@
}
jboolean
-java::io::File::isAbsolute (void)
+java::io::VMFile::isAbsolute (jstring path)
{
return path->length() > 0 && path->charAt(0) == '/';
}
jobjectArray
-java::io::File::performList (java::io::FilenameFilter *filter,
- java::io::FileFilter *fileFilter,
- java::lang::Class *result_type)
+java::io::VMFile::list (java::io::File *file,
+ java::io::FilenameFilter *filter,
+ java::io::FileFilter *fileFilter,
+ java::lang::Class *result_type)
{
/* Some systems have dirent.h, but no directory reading functions like
opendir. */
#if defined(HAVE_DIRENT_H) && defined(HAVE_OPENDIR)
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
- buf[total] = '\0';
+ jstring path = file->getPath();
+ JV_TEMP_UTF_STRING(utfstr, path);
- DIR *dir = opendir (buf);
+ DIR *dir = opendir (utfstr.buf());
if (! dir)
return NULL;
java::util::ArrayList *list = new java::util::ArrayList ();
struct dirent *d;
#ifdef HAVE_READDIR_R
- int name_max = pathconf (buf, _PC_NAME_MAX);
+ int name_max = pathconf (utfstr.buf(), _PC_NAME_MAX);
char dbuf[sizeof (struct dirent) + name_max + 1];
while (readdir_r (dir, (struct dirent *) dbuf, &d) == 0 && d != NULL)
#else /* HAVE_READDIR_R */
@@ -230,12 +225,12 @@
continue;
jstring name = JvNewStringUTF (d->d_name);
- if (filter && ! filter->accept(this, name))
+ if (filter && ! filter->accept(file, name))
continue;
if (result_type == &java::io::File::class$)
{
- java::io::File *file = new java::io::File (this, name);
+ java::io::File *file = new java::io::File (path, name);
if (fileFilter && ! fileFilter->accept(file))
continue;
@@ -256,32 +251,28 @@
}
jboolean
-java::io::File::performMkdir (void)
+java::io::VMFile::mkdir (jstring path)
{
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
- buf[total] = '\0';
+ JV_TEMP_UTF_STRING(utfstr, path);
#ifdef HAVE_MKDIR
- return ::mkdir (buf, 0755) == 0;
+ return ::mkdir (utfstr.buf(), 0755) == 0;
#else
return false;
#endif
}
jboolean
-java::io::File::performSetReadOnly (void)
+java::io::VMFile::setReadOnly (jstring path)
{
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
- buf[total] = '\0';
+ JV_TEMP_UTF_STRING(utfstr, path);
#if defined (HAVE_STAT) && defined (HAVE_CHMOD)
struct stat sb;
- if (::stat (buf, &sb))
+ if (::stat (utfstr.buf(), &sb))
return false;
- if (::chmod(buf, sb.st_mode & 0555))
+ if (::chmod(utfstr.buf(), sb.st_mode & 0555))
return false;
return true;
#else
@@ -290,7 +281,7 @@
}
JArray< ::java::io::File *>*
-java::io::File::performListRoots ()
+java::io::VMFile::listRoots ()
{
::java::io::File *f = new ::java::io::File (JvNewStringLatin1 ("/"));
JArray<java::io::File *> *unixroot
@@ -301,49 +292,40 @@
}
jboolean
-java::io::File::performRenameTo (File *dest)
+java::io::VMFile::renameTo (jstring path, jstring destpath)
{
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
- buf[total] = '\0';
- char *buf2
- = (char *) __builtin_alloca (JvGetStringUTFLength (dest->path) + 1);
- total = JvGetStringUTFRegion (dest->path, 0, dest->path->length(), buf2);
- buf2[total] = '\0';
+ JV_TEMP_UTF_STRING(utfstr, path);
+ JV_TEMP_UTF_STRING(utfstr2, destpath);
#ifdef HAVE_RENAME
- return ::rename (buf, buf2) == 0;
+ return ::rename (utfstr.buf(), utfstr2.buf()) == 0;
#else
return false;
#endif
}
jboolean
-java::io::File::performSetLastModified (jlong time)
+java::io::VMFile::setLastModified (jstring path, jlong time)
{
#ifdef HAVE_UTIME
utimbuf tb;
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
- buf[total] = '\0';
+ JV_TEMP_UTF_STRING(utfstr, path);
tb.actime = time / 1000;
tb.modtime = time / 1000;
- return ::utime (buf, &tb);
+ return ::utime (utfstr.buf(), &tb);
#else
return false;
#endif
}
jboolean
-java::io::File::performCreate (void)
+java::io::VMFile::create (jstring path)
{
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
- buf[total] = '\0';
+ JV_TEMP_UTF_STRING(utfstr, path);
- int fd = ::open (buf, O_CREAT | O_EXCL, 0644);
+ int fd = ::open (utfstr.buf(), O_CREAT | O_EXCL, 0644);
if (fd < 0)
{
@@ -359,25 +341,23 @@
}
jboolean
-java::io::File::performDelete (void)
+java::io::VMFile::deleteFile (jstring path)
{
- char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
- jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
- buf[total] = '\0';
+ JV_TEMP_UTF_STRING(utfstr, path);
#ifdef HAVE_UNLINK
#ifdef HAVE_RMDIR
- if (! ::rmdir (buf))
+ if (! ::rmdir (utfstr.buf()))
return true;
if (errno == ENOTDIR)
#endif // HAVE_RMDIR
- return ::unlink (buf) == 0;
+ return ::unlink (utfstr.buf()) == 0;
#endif // HAVE_UNLINK
return false;
}
void
-java::io::File::init_native ()
+java::io::VMFile::init_native ()
{
maxPathLen = MAXPATHLEN;
caseSensitive = true;
Index: java/io/natFileWin32.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/natFileWin32.cc,v
retrieving revision 1.19
diff -u -r1.19 natFileWin32.cc
--- java/io/natFileWin32.cc 2 Dec 2003 22:26:49 -0000 1.19
+++ java/io/natFileWin32.cc 15 Sep 2004 12:48:34 -0000
@@ -17,6 +17,7 @@
#undef STRICT
#include <java/io/File.h>
+#include <java/io/VMFile.h>
#include <java/io/IOException.h>
#include <java/util/Vector.h>
#include <java/lang/String.h>
@@ -38,9 +39,9 @@
#define WIN32_EPOCH_MILLIS 11644473600000LL
jboolean
-java::io::File::_access (jint query)
+java::io::VMFile::_access (jstring path, jint query)
{
- JV_TEMP_STRING_WIN32 (canon, getCanonicalPath());
+ JV_TEMP_STRING_WIN32 (canon, getCanonicalPath(path));
if (!canon)
return false;
@@ -59,9 +60,9 @@
}
jboolean
-java::io::File::_stat (jint query)
+java::io::VMFile::_stat (jstring path, jint query)
{
- JV_TEMP_STRING_WIN32 (canon, getCanonicalPath());
+ JV_TEMP_STRING_WIN32 (canon, getCanonicalPath(path));
if (!canon)
return false;
@@ -78,9 +79,9 @@
}
jlong
-java::io::File::attr (jint query)
+java::io::VMFile::attr (jstring path, jint query)
{
- JV_TEMP_STRING_WIN32 (canon, getCanonicalPath());
+ JV_TEMP_STRING_WIN32 (canon, getCanonicalPath(path));
if (!canon)
return false;
@@ -107,7 +108,7 @@
}
jstring
-java::io::File::getCanonicalPath (void)
+java::io::VMFile::getCanonicalPath (jstring path)
{
JV_TEMP_STRING_WIN32 (cpath, path);
@@ -125,7 +126,7 @@
}
jboolean
-java::io::File::isAbsolute (void)
+java::io::VMFile::isAbsolute (jstring path)
{
// See if the path represents a Windows UNC network path.
if (path->length () > 2
@@ -146,18 +147,19 @@
&& (path->charAt(2) == '/' || path->charAt(2) == '\\'));
}
-void java::io::File::init_native ()
+void java::io::VMFile::init_native ()
{
maxPathLen = MAX_PATH;
caseSensitive = false;
}
jobjectArray
-java::io::File::performList (java::io::FilenameFilter *filter,
+java::io::VMFile::list (java::io::File *file,
+ java::io::FilenameFilter *filter,
java::io::FileFilter *fileFilter,
java::lang::Class *clazz)
{
- jstring canon = getCanonicalPath();
+ jstring canon = getCanonicalPath(file->getPath());
if (! canon)
return NULL;
@@ -186,14 +188,14 @@
{
jstring name = _Jv_Win32NewString (data.cFileName);
- if (filter && !filter->accept(this, name))
+ if (filter && !filter->accept(file, name))
continue;
if (clazz == &java::io::File::class$)
{
- java::io::File *file = new java::io::File (this, name);
- if (fileFilter && !fileFilter->accept(file))
+ java::io::File *child = new java::io::File (file, name);
+ if (fileFilter && !fileFilter->accept(child))
continue;
- vec->addElement (file);
+ vec->addElement (child);
}
else
vec->addElement (name);
@@ -212,24 +214,24 @@
}
jboolean
-java::io::File::performMkdir (void)
+java::io::VMFile::mkdir (jstring path)
{
JV_TEMP_STRING_WIN32 (cpath, path);
return (CreateDirectory(cpath, NULL)) ? true : false;
}
jboolean
-java::io::File::performRenameTo (File *dest)
+java::io::VMFile::renameTo (jstring path, jstring destpath)
{
JV_TEMP_STRING_WIN32 (pathFrom, path);
- JV_TEMP_STRING_WIN32 (pathTo, dest->path);
+ JV_TEMP_STRING_WIN32 (pathTo, destpath);
return (MoveFile(pathFrom, pathTo)) ? true : false;
}
jboolean
-java::io::File::performDelete ()
+java::io::VMFile::deleteFile (jstring path)
{
- JV_TEMP_STRING_WIN32 (canon, getCanonicalPath());
+ JV_TEMP_STRING_WIN32 (canon, getCanonicalPath(path));
if (!canon)
return false;
@@ -243,9 +245,9 @@
return (DeleteFile (canon)) ? true : false;
}
-jboolean java::io::File::performCreate (void)
+jboolean java::io::VMFile::create (jstring path)
{
- JV_TEMP_STRING_WIN32 (canon, getCanonicalPath());
+ JV_TEMP_STRING_WIN32 (canon, getCanonicalPath(path));
if (!canon)
return false;
@@ -265,9 +267,9 @@
}
}
-jboolean java::io::File::performSetReadOnly ()
+jboolean java::io::VMFile::setReadOnly (jstring path)
{
- JV_TEMP_STRING_WIN32 (canon, getCanonicalPath());
+ JV_TEMP_STRING_WIN32 (canon, getCanonicalPath(path));
if (!canon)
return false;
@@ -283,9 +285,9 @@
return false;
}
-jboolean java::io::File::performSetLastModified (jlong time)
+jboolean java::io::VMFile::setLastModified (jstring path, jlong time)
{
- JV_TEMP_STRING_WIN32 (canon, getCanonicalPath());
+ JV_TEMP_STRING_WIN32 (canon, getCanonicalPath(path));
if (!canon)
return false;
@@ -312,7 +314,7 @@
return retVal;
}
-JArray<java::io::File*>* java::io::File::performListRoots ()
+JArray<java::io::File*>* java::io::VMFile::listRoots ()
{
DWORD drivesBitmap = GetLogicalDrives ();
DWORD mask;
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.409
diff -u -r1.409 Makefile.am
--- Makefile.am 10 Sep 2004 08:22:58 -0000 1.409
+++ Makefile.am 15 Sep 2004 12:48:35 -0000
@@ -2212,6 +2212,7 @@
java/io/SyncFailedException.java \
java/io/UTFDataFormatException.java \
java/io/UnsupportedEncodingException.java \
+java/io/VMFile.java \
java/io/VMObjectStreamClass.java \
java/io/WriteAbortedException.java \
java/io/Writer.java \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.436
diff -u -r1.436 Makefile.in
--- Makefile.in 10 Sep 2004 09:36:28 -0000 1.436
+++ Makefile.in 15 Sep 2004 12:48:42 -0000
@@ -513,7 +513,7 @@
java/io/StringBufferInputStream.java java/io/StringReader.java \
java/io/StringWriter.java java/io/SyncFailedException.java \
java/io/UTFDataFormatException.java \
- java/io/UnsupportedEncodingException.java \
+ java/io/UnsupportedEncodingException.java java/io/VMFile.java \
java/io/VMObjectStreamClass.java \
java/io/WriteAbortedException.java java/io/Writer.java \
java/util/AbstractCollection.java java/util/AbstractList.java \
@@ -2275,7 +2275,7 @@
java/io/StringBufferInputStream.lo java/io/StringReader.lo \
java/io/StringWriter.lo java/io/SyncFailedException.lo \
java/io/UTFDataFormatException.lo \
- java/io/UnsupportedEncodingException.lo \
+ java/io/UnsupportedEncodingException.lo java/io/VMFile.lo \
java/io/VMObjectStreamClass.lo \
java/io/WriteAbortedException.lo java/io/Writer.lo \
java/util/AbstractCollection.lo java/util/AbstractList.lo \
@@ -5788,6 +5788,7 @@
java/io/SyncFailedException.java \
java/io/UTFDataFormatException.java \
java/io/UnsupportedEncodingException.java \
+java/io/VMFile.java \
java/io/VMObjectStreamClass.java \
java/io/WriteAbortedException.java \
java/io/Writer.java \
@@ -7998,6 +7999,8 @@
java/io/$(DEPDIR)/$(am__dirstamp)
java/io/UnsupportedEncodingException.lo: java/io/$(am__dirstamp) \
java/io/$(DEPDIR)/$(am__dirstamp)
+java/io/VMFile.lo: java/io/$(am__dirstamp) \
+ java/io/$(DEPDIR)/$(am__dirstamp)
java/io/VMObjectStreamClass.lo: java/io/$(am__dirstamp) \
java/io/$(DEPDIR)/$(am__dirstamp)
java/io/WriteAbortedException.lo: java/io/$(am__dirstamp) \
@@ -15103,6 +15106,8 @@
-rm -f java/io/UTFDataFormatException.lo
-rm -f java/io/UnsupportedEncodingException.$(OBJEXT)
-rm -f java/io/UnsupportedEncodingException.lo
+ -rm -f java/io/VMFile.$(OBJEXT)
+ -rm -f java/io/VMFile.lo
-rm -f java/io/VMObjectStreamClass.$(OBJEXT)
-rm -f java/io/VMObjectStreamClass.lo
-rm -f java/io/WriteAbortedException.$(OBJEXT)
@@ -18858,6 +18863,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@java/io/$(DEPDIR)/SyncFailedException.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/io/$(DEPDIR)/UTFDataFormatException.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/io/$(DEPDIR)/UnsupportedEncodingException.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@java/io/$(DEPDIR)/VMFile.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/io/$(DEPDIR)/VMObjectStreamClass.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/io/$(DEPDIR)/WriteAbortedException.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/io/$(DEPDIR)/Writer.Plo@am__quote@