summaryrefslogtreecommitdiff
path: root/lib/openat.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-09-30 15:19:24 +0000
committerJim Meyering <jim@meyering.net>2005-09-30 15:19:24 +0000
commit5230885d13b2ec25d6976acea475de475b01f1fa (patch)
tree2cdfdf6b8b69b8c8cf8553bc9077b683696ab565 /lib/openat.c
parente94c88d4a23e520844c8c8102653e4c2fdfc2fe6 (diff)
downloadcoreutils-5230885d13b2ec25d6976acea475de475b01f1fa.tar.xz
(fdopendir): Do not define if HAVE_FDOPENDIR.
Remove AT_FDCWD test. Do not consume the fd unless successful.
Diffstat (limited to 'lib/openat.c')
-rw-r--r--lib/openat.c13
1 files changed, 7 insertions, 6 deletions
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.
<http://www.google.com/search?q=fdopendir+site:docs.sun.com>
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.
<http://www.google.com/search?q=fstatat+site:docs.sun.com>
Simulate it by doing save_cwd/fchdir/(stat|lstat)/restore_cwd.