From 510e597e7fff1d112e20e88ecf7b5f2ca890c2e9 Mon Sep 17 00:00:00 2001 From: Michihiro NAKAJIMA Date: Mon, 15 Oct 2012 04:27:52 +0900 Subject: [PATCH] Fix a handing of readdir_r on AIX. The meaning of the return value is different from other posix systems. --- libarchive/archive_read_disk_posix.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; -- 2.47.2