From: Jim Meyering Date: Mon, 19 Feb 2007 20:03:22 +0000 (+0000) Subject: Don't use FD after a successful "fdopendir (fd)". X-Git-Tag: cvs-readonly~1016 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=788ab9bcd51307ffb600856bbb2485e3c6b515a3;p=gnulib.git 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*. --- diff --git a/ChangeLog b/ChangeLog index 89196395d..2f3243697 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2007-02-19 Jim Meyering + 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. diff --git a/lib/getcwd.c b/lib/getcwd.c index 3cdc11391..dea0ebcac 100644 --- a/lib/getcwd.c +++ b/lib/getcwd.c @@ -234,6 +234,8 @@ __getcwd (char *buf, size_t size) 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);