diff options
Diffstat (limited to 'libjava/java/io/natFileWin32.cc')
-rw-r--r-- | libjava/java/io/natFileWin32.cc | 118 |
1 files changed, 46 insertions, 72 deletions
diff --git a/libjava/java/io/natFileWin32.cc b/libjava/java/io/natFileWin32.cc index 1e06832..cee6b00 100644 --- a/libjava/java/io/natFileWin32.cc +++ b/libjava/java/io/natFileWin32.cc @@ -9,15 +9,13 @@ Libgcj License. Please consult the file "LIBGCJ_LICENSE" for details. */ #include <config.h> +#include <platform.h> #include <stdio.h> #include <string.h> -#include <windows.h> #undef STRICT -#include <gcj/cni.h> -#include <jvm.h> #include <java/io/File.h> #include <java/io/IOException.h> #include <java/util/Vector.h> @@ -42,12 +40,9 @@ details. */ jboolean java::io::File::_access (jint query) { - jstring canon = getCanonicalPath(); - if (! canon) + JV_TEMP_UTF_STRING (canon, getCanonicalPath()); + if (!canon) return false; - char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1); - jsize total = JvGetStringUTFRegion (canon, 0, canon->length(), buf); - buf[total] = '\0'; JvAssert (query == READ || query == WRITE || query == EXISTS); @@ -55,7 +50,7 @@ java::io::File::_access (jint query) // If the file exists but cannot be read because of the secuirty attributes // on an NTFS disk this wont work (it reports it can be read but cant) // Could we use something from the security API? - DWORD attributes = GetFileAttributes (buf); + DWORD attributes = GetFileAttributes (canon); if ((query == EXISTS) || (query == READ)) return (attributes == 0xffffffff) ? false : true; else @@ -65,16 +60,13 @@ java::io::File::_access (jint query) jboolean java::io::File::_stat (jint query) { - jstring canon = getCanonicalPath(); - if (! canon) + JV_TEMP_UTF_STRING (canon, getCanonicalPath()); + if (!canon) return false; - char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1); - jsize total = JvGetStringUTFRegion (canon, 0, canon->length(), buf); - buf[total] = '\0'; JvAssert (query == DIRECTORY || query == ISFILE); - DWORD attributes = GetFileAttributes (buf); + DWORD attributes = GetFileAttributes (canon); if (attributes == 0xffffffff) return false; @@ -87,18 +79,15 @@ java::io::File::_stat (jint query) jlong java::io::File::attr (jint query) { - jstring canon = getCanonicalPath(); - if (! canon) + JV_TEMP_UTF_STRING (canon, getCanonicalPath()); + if (!canon) return false; - char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1); - jsize total = JvGetStringUTFRegion (canon, 0, canon->length(), buf); - buf[total] = '\0'; JvAssert (query == MODIFIED || query == LENGTH); WIN32_FIND_DATA info; HANDLE sHandle; - if ( ( sHandle = FindFirstFile( buf, &info)) == INVALID_HANDLE_VALUE) + if ( ( sHandle = FindFirstFile( canon, &info)) == INVALID_HANDLE_VALUE) return 0; FindClose( sHandle); @@ -119,13 +108,11 @@ java::io::File::attr (jint query) jstring java::io::File::getCanonicalPath (void) { - char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1); - jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); - buf[total] = '\0'; + JV_TEMP_UTF_STRING (cpath, path); LPTSTR unused; char buf2[MAX_PATH]; - if(!GetFullPathName(buf, MAX_PATH, buf2, &unused)) + if(!GetFullPathName(cpath, MAX_PATH, buf2, &unused)) throw new IOException (JvNewStringLatin1 ("GetFullPathName failed")); // FIXME: what encoding to assume for file names? This affects many @@ -152,7 +139,7 @@ java::io::File::isAbsolute (void) && (path->charAt(0) < 'A' || path->charAt(0) > 'Z')) return false; return (path->charAt(1) == ':' - && (path->charAt(2) == '/' || path->charAt(2) == '\\')); + && (path->charAt(2) == '/' || path->charAt(2) == '\\')); } void java::io::File::init_native () @@ -163,8 +150,8 @@ void java::io::File::init_native () jobjectArray java::io::File::performList (java::io::FilenameFilter *filter, - java::io::FileFilter *fileFilter, - java::lang::Class *clazz) + java::io::FileFilter *fileFilter, + java::lang::Class *clazz) { jstring canon = getCanonicalPath(); if (! canon) @@ -190,16 +177,16 @@ java::io::File::performList (java::io::FilenameFilter *filter, jstring name = JvNewStringUTF (data.cFileName); if (filter && !filter->accept(this, name)) - continue; + continue; if (clazz == &java::io::File::class$) - { + { java::io::File *file = new java::io::File (this, name); if (fileFilter && !fileFilter->accept(file)) - continue; - vec->addElement (file); - } - else - vec->addElement (name); + continue; + vec->addElement (file); + } + else + vec->addElement (name); } } while (FindNextFile (handle, &data)); @@ -217,53 +204,42 @@ java::io::File::performList (java::io::FilenameFilter *filter, jboolean java::io::File::performMkdir (void) { - char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1); - jsize total = JvGetStringUTFRegion(path, 0, path->length(), buf); - buf[total] = '\0'; - - return (CreateDirectory(buf, NULL)) ? true : false; + JV_TEMP_UTF_STRING (cpath, path); + return (CreateDirectory(cpath, NULL)) ? true : false; } jboolean java::io::File::performRenameTo (File *dest) { - 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'; - - return (MoveFile(buf, buf2)) ? true : false; + JV_TEMP_UTF_STRING (pathFrom, path); + JV_TEMP_UTF_STRING (pathTo, dest->path); + return (MoveFile(pathFrom, pathTo)) ? true : false; } jboolean java::io::File::performDelete () { - jstring canon = getCanonicalPath(); - char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1); - jsize total = JvGetStringUTFRegion(canon, 0, canon->length(), buf); - buf[total] = '\0'; + JV_TEMP_UTF_STRING (canon, getCanonicalPath()); + if (!canon) + return false; - DWORD attributes = GetFileAttributes (buf); + DWORD attributes = GetFileAttributes (canon); if (attributes == 0xffffffff) return false; if (attributes & FILE_ATTRIBUTE_DIRECTORY) - return (RemoveDirectory (buf)) ? true : false; + return (RemoveDirectory (canon)) ? true : false; else - return (DeleteFile (buf)) ? true : false; + return (DeleteFile (canon)) ? true : false; } jboolean java::io::File::performCreate (void) { - jstring canon = getCanonicalPath (); - char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1); - jsize total = JvGetStringUTFRegion (canon, 0, canon->length (), buf); - buf[total] = '\0'; + JV_TEMP_UTF_STRING (canon, getCanonicalPath()); + if (!canon) + return false; - HANDLE h = CreateFile (buf, 0, 0, NULL, CREATE_NEW, + HANDLE h = CreateFile (canon, 0, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if (h != INVALID_HANDLE_VALUE) { @@ -281,15 +257,14 @@ jboolean java::io::File::performCreate (void) jboolean java::io::File::performSetReadOnly () { - jstring canon = getCanonicalPath (); - char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1); - jsize total = JvGetStringUTFRegion (canon, 0, canon->length (), buf); - buf[total] = '\0'; + JV_TEMP_UTF_STRING (canon, getCanonicalPath()); + if (!canon) + return false; - DWORD attrs = GetFileAttributes (buf); + DWORD attrs = GetFileAttributes (canon); if (attrs != INVALID_FILE_ATTRIBUTES) { - if (SetFileAttributes (buf, attrs | FILE_ATTRIBUTE_READONLY) != 0) + if (SetFileAttributes (canon, attrs | FILE_ATTRIBUTE_READONLY) != 0) return true; else return false; @@ -300,10 +275,9 @@ jboolean java::io::File::performSetReadOnly () jboolean java::io::File::performSetLastModified (jlong time) { - jstring canon = getCanonicalPath (); - char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (canon) + 1); - jsize total = JvGetStringUTFRegion (canon, 0, canon->length (), buf); - buf[total] = '\0'; + JV_TEMP_UTF_STRING (canon, getCanonicalPath()); + if (!canon) + return false; FILETIME modTime; long long mTime100ns = ((long long) time /* Ha! */ @@ -313,7 +287,7 @@ jboolean java::io::File::performSetLastModified (jlong time) modTime.dwHighDateTime = (DWORD) (mTime100ns >> 32); jboolean retVal = false; - HANDLE h = CreateFile (buf, FILE_WRITE_ATTRIBUTES, + HANDLE h = CreateFile (canon, FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); |