changeset 8202:b0e0eba8a254

Don't use FD after a successful "fdopendir (fd)". * lib/getcwd.c (__getcwd) [AT_FDCWD]: fdopendir (fd) usually closes fd. Reset it by calling dirfd on the just-obtained DIR*.
author Jim Meyering <jim@meyering.net>
date Mon, 19 Feb 2007 20:03:22 +0000
parents d2e94bbbda55
children 96f4287dd956
files ChangeLog lib/getcwd.c
diffstat 2 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2007-02-19  Jim Meyering  <jim@meyering.net>
 
+	Don't use FD after a successful "fdopendir (fd)".
+	* lib/getcwd.c (__getcwd) [AT_FDCWD]: fdopendir (fd) usually closes fd.
+	Reset it by calling dirfd on the just-obtained DIR*.
+
 	* m4/ftruncate.m4: Adjust comment to give this module a 3-year reprieve.
 	Prompted by a report from Bruno Haible that mingw lacks ftruncate.
 
--- a/lib/getcwd.c
+++ b/lib/getcwd.c
@@ -234,6 +234,8 @@
       dirstream = fdopendir (fd);
       if (dirstream == NULL)
 	goto lose;
+      /* Reset fd.  It may have been closed by fdopendir.  */
+      fd = dirfd (dirstream);
       fd_needs_closing = false;
 #else
       dirstream = __opendir (dotlist);