mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-19 03:33:43 +03:00
(fdopendir): Do not define if HAVE_FDOPENDIR.
Remove AT_FDCWD test. Do not consume the fd unless successful.
This commit is contained in:
1 parent
e94c88d4a2
commit
5230885d13
1 file changed
+7
-6
+7
-6
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user