diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2015-03-19 12:32:42 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2015-03-19 12:33:44 -0700 |
commit | ccf00107f7aa8897cde017bec3717ecc350515f7 (patch) | |
tree | f92f5f4c4a8f61f8f1f73a3ebb61304b409471ec /lib/fdopendir.c | |
parent | 8aa13d07fe72b8a00ded10602f5c5ce773181b40 (diff) | |
download | emacs-ccf00107f7aa8897cde017bec3717ecc350515f7.tar.gz |
Merge from gnulib
This incorporates:
2015-03-19 fdopendir: port better to MinGW
2015-03-18 fdopendir: fix typo in comment
2015-02-24 glob, etc.: port to MSVC v18 on MS-Windows 8.1
* lib/dirent.in.h, lib/fdopendir.c: Update from gnulib.
* lib/dirfd.c, m4/dirfd.m4: New files from gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
Diffstat (limited to 'lib/fdopendir.c')
-rw-r--r-- | lib/fdopendir.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/fdopendir.c b/lib/fdopendir.c index 9dc1e7b26dc..837a8219b33 100644 --- a/lib/fdopendir.c +++ b/lib/fdopendir.c @@ -93,7 +93,7 @@ fdopendir (int fd) That way, barring race conditions, fd_clone_opendir returns a stream whose file descriptor is FD. - If REPLACE_CHDIR or CWD is null, use opendir ("/proc/self/fd/...", + If REPLACE_FCHDIR or CWD is null, use opendir ("/proc/self/fd/...", falling back on fchdir metadata. Otherwise, CWD is a saved version of the working directory; use fchdir/opendir(".")/restore_cwd(CWD). */ static DIR * @@ -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; |