diff options
author | Jim Meyering <jim@meyering.net> | 2005-09-20 13:51:01 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2005-09-20 13:51:01 +0000 |
commit | 5205b738107db88501a5d8f0bd3908a66d81b87b (patch) | |
tree | 4e1cc2305a6cd309f875a8ee6e44729b50c64bf2 /lib | |
parent | 3fcdbfdfda725ba1a31f30b3a8aba4d783de3c45 (diff) | |
download | coreutils-5205b738107db88501a5d8f0bd3908a66d81b87b.tar.xz |
(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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/openat.c | 9 |
1 files changed, 8 insertions, 1 deletions
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; |