From: Jim Meyering Date: Fri, 30 Sep 2005 15:19:24 +0000 (+0000) Subject: (fdopendir): Do not define if HAVE_FDOPENDIR. X-Git-Tag: COREUTILS-5_91~96 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5230885d13b2ec25d6976acea475de475b01f1fa;p=platform%2Fupstream%2Fcoreutils.git (fdopendir): Do not define if HAVE_FDOPENDIR. Remove AT_FDCWD test. Do not consume the fd unless successful. --- diff --git a/lib/openat.c b/lib/openat.c index f7eb39d..929d264 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -89,6 +89,8 @@ rpl_openat (int fd, char const *file, int flags, ...) return new_fd; } +#if !HAVE_FDOPENDIR + /* Replacement for Solaris' function by the same name. Simulate it by doing save_cwd/fchdir/opendir(".")/restore_cwd. @@ -100,7 +102,7 @@ rpl_openat (int fd, char const *file, int flags, ...) W A R N I N G: Unlike the other fd-related functions here, this one effectively consumes its FD parameter. The caller should not - close or otherwise manipulate FD after calling this function. */ + close or otherwise manipulate FD if this function returns successfully. */ DIR * fdopendir (int fd) { @@ -108,9 +110,6 @@ fdopendir (int fd) int saved_errno; DIR *dir; - if (fd == AT_FDCWD) - return opendir ("."); - if (save_cwd (&saved_cwd) != 0) openat_save_fail (errno); @@ -118,7 +117,6 @@ fdopendir (int fd) { saved_errno = errno; free_cwd (&saved_cwd); - close (fd); errno = saved_errno; return NULL; } @@ -130,12 +128,15 @@ fdopendir (int fd) openat_restore_fail (errno); free_cwd (&saved_cwd); - close (fd); + if (dir) + close (fd); errno = saved_errno; return dir; } +#endif + /* Replacement for Solaris' function by the same name. Simulate it by doing save_cwd/fchdir/(stat|lstat)/restore_cwd.