diff options
author | Tom Tromey <tromey@redhat.com> | 2002-02-07 19:18:35 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2002-02-07 19:18:35 +0000 |
commit | fc7563ecb0c86c8bb261652297fb27152c7b4aca (patch) | |
tree | 6be707a712e1e6e4eed9c7f220ef78ec45fad871 /libjava/java | |
parent | 73272ce6089d2c44aee23abf515f7d8be808e51d (diff) | |
download | gcc-fc7563ecb0c86c8bb261652297fb27152c7b4aca.tar.gz |
natFile.cc (_access): Don't stack-allocate buffer.
* 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.
From-SVN: r49584
Diffstat (limited to 'libjava/java')
-rw-r--r-- | libjava/java/io/natFile.cc | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/libjava/java/io/natFile.cc b/libjava/java/io/natFile.cc index 0d2afb62097..82fab1c3acd 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<java::io::File *> *unixroot; - JArray< ::java::io::File *>* java::io::File::performListRoots () { - if (unixroot == NULL) - { - ::java::io::File *f = new ::java::io::File (JvNewStringLatin1 ("/")); - unixroot = reinterpret_cast <JArray<java::io::File *>*> - (JvNewObjectArray (1, &java::io::File::class$, f)); - elements (unixroot) [0] = f; - } + ::java::io::File *f = new ::java::io::File (JvNewStringLatin1 ("/")); + JArray<java::io::File *> *unixroot + = reinterpret_cast <JArray<java::io::File *>*> + (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'; |