From 5205b738107db88501a5d8f0bd3908a66d81b87b Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 20 Sep 2005 13:51:01 +0000 Subject: (fdopendir): Be sure to close the supplied file descriptor before returning. This makes our replacement implementation a little closer to Solaris's, where fdopendir ties the file descriptor to the returned DIR* pointer. --- lib/openat.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/openat.c') diff --git a/lib/openat.c b/lib/openat.c index 3e3251ba1..ea42ec26b 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -93,7 +93,12 @@ rpl_openat (int fd, char const *file, int flags, ...) If either the save_cwd or the restore_cwd fails (relatively unlikely, and usually indicative of a problem that deserves close attention), then give a diagnostic and exit nonzero. - Otherwise, this function works just like Solaris' fdopendir. */ + Otherwise, this function works just like Solaris' fdopendir. + + 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. */ DIR * fdopendir (int fd) { @@ -111,6 +116,7 @@ fdopendir (int fd) { saved_errno = errno; free_cwd (&saved_cwd); + close (fd); errno = saved_errno; return NULL; } @@ -122,6 +128,7 @@ fdopendir (int fd) openat_restore_fail (errno); free_cwd (&saved_cwd); + close (fd); errno = saved_errno; return dir; -- cgit v1.2.3-54-g00ecf