From: Michihiro NAKAJIMA Date: Sun, 14 Oct 2012 19:27:52 +0000 (+0900) Subject: Fix a handing of readdir_r on AIX. The meaning of the return value is X-Git-Tag: v3.1.0~40^2~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=510e597e7fff1d112e20e88ecf7b5f2ca890c2e9;p=thirdparty%2Flibarchive.git Fix a handing of readdir_r on AIX. The meaning of the return value is different from other posix systems. --- diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c index 8b50cc426..2a9ab68c4 100644 --- a/libarchive/archive_read_disk_posix.c +++ b/libarchive/archive_read_disk_posix.c @@ -2339,11 +2339,21 @@ tree_dir_next_posix(struct tree *t) #endif /* HAVE_READDIR_R */ } for (;;) { + errno = 0; #if defined(HAVE_READDIR_R) r = readdir_r(t->d, t->dirent, &t->de); +#ifdef _AIX + /* Note: According to the man page, return value 9 indicates + * that the readdir_r was not successful and the error code + * is set to the global errno variable. And then if the end + * of directory entries was reached, the return value is 9 + * and the third parameter is set to NULL and errno is + * unchanged. */ + if (r == 9) + r = errno; +#endif /* _AIX */ if (r != 0 || t->de == NULL) { #else - errno = 0; t->de = readdir(t->d); if (t->de == NULL) { r = errno;