X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fopenat.c;h=929d264924c4cf93fe38ec0031044ddc15099ec0;hb=fb84631f1ec8e82d252cbad0b5b7f83a98e74ba9;hp=f7eb39d0ec5035997692246a0b6e900e85a8062f;hpb=357e1c26576e584fbc24b72798d2f7cf70bd9867;p=gnulib.git diff --git a/lib/openat.c b/lib/openat.c index f7eb39d0e..929d26492 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.