diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2015-03-19 12:11:07 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2015-03-19 12:13:27 -0700 |
commit | a277f536d9b33ebc24893d946fb8be14f23c9d00 (patch) | |
tree | 0a0d1338ae8b86b854aeda3fcbdb44a31b649c14 /lib/fdopendir.c | |
parent | b89aa0edea32ca947722bb845b41606f171c9895 (diff) | |
download | gnulib-a277f536d9b33ebc24893d946fb8be14f23c9d00.tar.gz |
fdopendir: port better to MinGW
* lib/fdopendir.c (fd_clone_opendir) [REPLACE_FCHDIR]:
Use 'dup' if dirfd fails. Suggested by Eli Zaretskii in:
http://lists.gnu.org/archive/html/bug-gnulib/2015-03/msg00033.html
* modules/fdopendir (Depends-on): Add dirfd.
Diffstat (limited to 'lib/fdopendir.c')
-rw-r--r-- | lib/fdopendir.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/fdopendir.c b/lib/fdopendir.c index 117baa9993..837a8219b3 100644 --- a/lib/fdopendir.c +++ b/lib/fdopendir.c @@ -156,7 +156,16 @@ fd_clone_opendir (int fd, struct saved_cwd const *cwd) if (! dir && EXPECTED_ERRNO (saved_errno)) { char const *name = _gl_directory_name (fd); - return (name ? opendir (name) : NULL); + DIR *dp = name ? opendir (name) : NULL; + + /* The caller has done an elaborate dance to arrange for opendir to + consume just the right file descriptor. If dirfd returns -1, + though, we're on a system like mingw where opendir does not + consume a file descriptor. Consume it via 'dup' instead. */ + if (dp && dirfd (dp) < 0) + dup (fd); + + return dp; } # endif errno = saved_errno; |