summaryrefslogtreecommitdiff
path: root/native/jni/native-lib/cpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'native/jni/native-lib/cpio.c')
-rw-r--r--native/jni/native-lib/cpio.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/native/jni/native-lib/cpio.c b/native/jni/native-lib/cpio.c
index eb544dc83..4d23b7a1f 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, 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;
}