From c0632db132497d13e1e9e01c3e49252f7a8aa339 Mon Sep 17 00:00:00 2001 From: tromey Date: Thu, 7 Feb 2002 19:18:35 +0000 Subject: [PATCH] * java/io/natFile.cc (_access): Don't stack-allocate buffer. Size buffer based on real size of string. (_stat): Likewise. (attr): Likewise. (getCanonicalPath): Likewise. (performList): Likewise. (performMkdir): Likewise. (performSetReadOnly): Likewise. (unixroot): Removed. (performRenameTo): Likewise. (performSetLastModified): Likewise. (performCreate): Likewise. (performDelete): Likewise. (performListRoots): Always return new array. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@49584 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/ChangeLog | 15 +++++++++++++++ libjava/java/io/natFile.cc | 42 +++++++++++++++++++----------------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index d0ca38e..ea1677d 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,20 @@ 2002-02-07 Tom Tromey + * java/io/natFile.cc (_access): Don't stack-allocate buffer. + Size buffer based on real size of string. + (_stat): Likewise. + (attr): Likewise. + (getCanonicalPath): Likewise. + (performList): Likewise. + (performMkdir): Likewise. + (performSetReadOnly): Likewise. + (unixroot): Removed. + (performRenameTo): Likewise. + (performSetLastModified): Likewise. + (performCreate): Likewise. + (performDelete): Likewise. + (performListRoots): Always return new array. + * prims.cc (_Jv_CreateJavaVM): Call _Jv_platform_initialize. * win32.cc (win32_exception_handler): Now static. * include/win32.h (_Jv_platform_initialize): Declare. diff --git a/libjava/java/io/natFile.cc b/libjava/java/io/natFile.cc index 0d2afb6..82fab1c 100644 --- a/libjava/java/io/natFile.cc +++ b/libjava/java/io/natFile.cc @@ -39,7 +39,7 @@ details. */ jboolean java::io::File::_access (jint query) { - char buf[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; JvAssert (query == READ || query == WRITE || query == EXISTS); @@ -60,7 +60,7 @@ java::io::File::_access (jint query) jboolean java::io::File::_stat (jint query) { - char buf[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; @@ -83,7 +83,7 @@ java::io::File::_stat (jint query) jlong java::io::File::attr (jint query) { - char buf[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; @@ -104,7 +104,8 @@ java::io::File::attr (jint query) jstring java::io::File::getCanonicalPath (void) { - char buf[MAXPATHLEN], buf2[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); + char buf2[MAXPATHLEN]; jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; @@ -134,7 +135,7 @@ java::io::File::performList (java::io::FilenameFilter *filter, /* Some systems have dirent.h, but no directory reading functions like opendir. */ #if defined(HAVE_DIRENT_H) && defined(HAVE_OPENDIR) - char buf[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; @@ -142,7 +143,6 @@ java::io::File::performList (java::io::FilenameFilter *filter, if (! dir) return NULL; - java::util::ArrayList *list = new java::util::ArrayList (); struct dirent *d; #ifdef HAVE_READDIR_R @@ -162,7 +162,7 @@ java::io::File::performList (java::io::FilenameFilter *filter, jstring name = JvNewStringUTF (d->d_name); if (filter && ! filter->accept(this, name)) continue; - + if (result_type == &java::io::File::class$) { java::io::File *file = new java::io::File (this, name); @@ -188,7 +188,7 @@ java::io::File::performList (java::io::FilenameFilter *filter, jboolean java::io::File::performMkdir (void) { - char buf[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; @@ -202,7 +202,7 @@ java::io::File::performMkdir (void) jboolean java::io::File::performSetReadOnly (void) { - char buf[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; @@ -219,28 +219,24 @@ java::io::File::performSetReadOnly (void) #endif } -static JArray *unixroot; - JArray< ::java::io::File *>* java::io::File::performListRoots () { - if (unixroot == NULL) - { - ::java::io::File *f = new ::java::io::File (JvNewStringLatin1 ("/")); - unixroot = reinterpret_cast *> - (JvNewObjectArray (1, &java::io::File::class$, f)); - elements (unixroot) [0] = f; - } + ::java::io::File *f = new ::java::io::File (JvNewStringLatin1 ("/")); + JArray *unixroot + = reinterpret_cast *> + (JvNewObjectArray (1, &java::io::File::class$, f)); + elements (unixroot) [0] = f; return unixroot; } jboolean java::io::File::performRenameTo (File *dest) { - char buf[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; - char buf2[MAXPATHLEN]; + char *buf2 = (char *) _Jv_AllocBytes (JvGetStringUTFLength (dest->path) + 1); total = JvGetStringUTFRegion (dest->path, 0, dest->path->length(), buf2); buf2[total] = '\0'; @@ -257,7 +253,7 @@ java::io::File::performSetLastModified (jlong time) #ifdef HAVE_UTIME utimbuf tb; - char buf[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; @@ -272,7 +268,7 @@ java::io::File::performSetLastModified (jlong time) jboolean java::io::File::performCreate (void) { - char buf[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; @@ -294,7 +290,7 @@ java::io::File::performCreate (void) jboolean java::io::File::performDelete (void) { - char buf[MAXPATHLEN]; + char *buf = (char *) _Jv_AllocBytes (JvGetStringUTFLength (path) + 1); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); buf[total] = '\0'; -- 2.7.4