diff options
author | Casey Marshall <csm@gnu.org> | 2006-09-23 01:45:29 +0000 |
---|---|---|
committer | Casey Marshall <csm@gnu.org> | 2006-09-23 01:45:29 +0000 |
commit | 2c639ca6b5413fc46644bc36f14ceaff3b5dd740 (patch) | |
tree | 709f0cb86882aa1e9a42e411ee12f3be107d69a0 | |
parent | 38301647337533dbfd8655db4961ad487f8cfccf (diff) | |
download | classpath-2c639ca6b5413fc46644bc36f14ceaff3b5dd740.tar.gz |
2006-09-22 Casey Marshall <csm@gnu.org>
* configure.ac (AC_CHECK_FUNCS): check for `readdir_r.'
* native/jni/java-io/java_io_VMFile.c (Java_java_io_VMFile_list):
allocate `filename,' and handle changes to `cpio_readDir.'
* native/jni/native-lib/cpio.c (cpio_readDir): use `readdir_r' if
available; copy the filename into the destination buffer; return
an error code if readdir returns NULL, but errno is 0.
* native/jni/native-lib/cpio.h (cpio_readDir): change second
parameter to `const char *.'
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | configure.ac | 5 | ||||
-rw-r--r-- | native/jni/java-io/java_io_VMFile.c | 11 | ||||
-rw-r--r-- | native/jni/native-lib/cpio.c | 20 | ||||
-rw-r--r-- | native/jni/native-lib/cpio.h | 2 |
5 files changed, 40 insertions, 9 deletions
@@ -1,3 +1,14 @@ +2006-09-22 Casey Marshall <csm@gnu.org> + + * configure.ac (AC_CHECK_FUNCS): check for `readdir_r.' + * native/jni/java-io/java_io_VMFile.c (Java_java_io_VMFile_list): + allocate `filename,' and handle changes to `cpio_readDir.' + * native/jni/native-lib/cpio.c (cpio_readDir): use `readdir_r' if + available; copy the filename into the destination buffer; return + an error code if readdir returns NULL, but errno is 0. + * native/jni/native-lib/cpio.h (cpio_readDir): change second + parameter to `const char *.' + 2006-09-23 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/management/ObjectName.java: diff --git a/configure.ac b/configure.ac index 22507ee3c..1805eb8f8 100644 --- a/configure.ac +++ b/configure.ac @@ -375,7 +375,8 @@ if test "x${COMPILE_JNI}" = xyes; then mmap munmap mincore msync madvise getpagesize sysconf \ lstat readlink \ inet_aton inet_addr inet_pton \ - getifaddrs kqueue kevent epoll_create]) + getifaddrs kqueue kevent epoll_create \ + readdir_r ]) LIBMAGIC= AC_CHECK_LIB(magic, magic_open, LIBMAGIC=-lmagic) @@ -938,4 +939,4 @@ AC_OUTPUT cat ${srcdir}/lib/standard.omit.in > lib/standard.omit if test x$use_escher != xtrue; then echo gnu/java/awt/peer/x/.*java$ >> lib/standard.omit -fi +fi
\ No newline at end of file diff --git a/native/jni/java-io/java_io_VMFile.c b/native/jni/java-io/java_io_VMFile.c index 3f9282049..921b610a1 100644 --- a/native/jni/java-io/java_io_VMFile.c +++ b/native/jni/java-io/java_io_VMFile.c @@ -593,7 +593,7 @@ Java_java_io_VMFile_list (JNIEnv * env, jobject obj int result; char **filelist; void *handle; - const char *filename; + const char *filename = (const char *) JCL_malloc (env, FILENAME_MAX); unsigned long int filelist_count, max_filelist_count; char **tmp_filelist; jclass str_clazz; @@ -630,7 +630,7 @@ Java_java_io_VMFile_list (JNIEnv * env, jobject obj max_filelist_count = REALLOC_SIZE; /* read the files from the directory */ - result = cpio_readDir (handle, &filename); + result = cpio_readDir (handle, filename); while (result == CPNATIVE_OK) { if ((strcmp (filename, ".") != 0) && (strcmp (filename, "..") != 0)) @@ -666,9 +666,11 @@ Java_java_io_VMFile_list (JNIEnv * env, jobject obj } /* read next directory entry */ - result = cpio_readDir (handle, &filename); + result = cpio_readDir (handle, filename); } + JCL_free (env, filename); + /* close directory */ result = cpio_closeDir (handle); @@ -693,6 +695,9 @@ Java_java_io_VMFile_list (JNIEnv * env, jobject obj JCL_free (env, filelist); return 0; } + + (*env)->DeleteLocalRef (env, str_clazz); + for (i = 0; i < filelist_count; i++) { /* create new string */ diff --git a/native/jni/native-lib/cpio.c b/native/jni/native-lib/cpio.c index eb544dc83..a2e226298 100644 --- a/native/jni/native-lib/cpio.c +++ b/native/jni/native-lib/cpio.c @@ -448,14 +448,28 @@ int cpio_closeDir (void *handle) } -int cpio_readDir (void *handle, const char **filename) +int cpio_readDir (void *handle, const char *filename) { +#ifdef HAVE_READDIR_R + struct dirent dent; +#endif /* HAVE_READDIR_R */ struct dirent *dBuf; +#ifdef HAVE_READDIR_R + readdir_r ((DIR *) handle, &dent, &dBuf); +#else dBuf = readdir((DIR *)handle); +#endif /* HAVE_READDIR_R */ + if (dBuf == NULL) - return errno; + { + /* Some OS's (OS X) return NULL on end-of-dir, but + don't set errno to anything. */ + if (errno == 0) + return ENOENT; /* Whatever. */ + return errno; + } - *filename = dBuf->d_name; + strncpy (filename, dBuf->d_name, FILENAME_MAX); return 0; } diff --git a/native/jni/native-lib/cpio.h b/native/jni/native-lib/cpio.h index 1776b199d..7aad312bd 100644 --- a/native/jni/native-lib/cpio.h +++ b/native/jni/native-lib/cpio.h @@ -79,6 +79,6 @@ JNIEXPORT int cpio_rename (const char *old_name, const char *new_name); JNIEXPORT int cpio_openDir (const char *dirname, void **handle); JNIEXPORT int cpio_closeDir (void *handle); -JNIEXPORT int cpio_readDir (void *handle, const char **filename); +JNIEXPORT int cpio_readDir (void *handle, const char *filename); #endif |