summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-03-19 12:32:42 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2015-03-19 12:33:44 -0700
commitccf00107f7aa8897cde017bec3717ecc350515f7 (patch)
treef92f5f4c4a8f61f8f1f73a3ebb61304b409471ec /lib
parent8aa13d07fe72b8a00ded10602f5c5ce773181b40 (diff)
downloademacs-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')
-rw-r--r--lib/dirent.in.h2
-rw-r--r--lib/dirfd.c32
-rw-r--r--lib/fdopendir.c13
-rw-r--r--lib/gnulib.mk11
4 files changed, 56 insertions, 2 deletions
diff --git a/lib/dirent.in.h b/lib/dirent.in.h
index ddd3b84fbb2..154d2689e3d 100644
--- a/lib/dirent.in.h
+++ b/lib/dirent.in.h
@@ -77,6 +77,7 @@ typedef struct gl_directory DIR;
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef opendir
# define opendir rpl_opendir
+# define GNULIB_defined_opendir 1
# endif
_GL_FUNCDECL_RPL (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (opendir, DIR *, (const char *dir_name));
@@ -128,6 +129,7 @@ _GL_WARN_ON_USE (rewinddir, "rewinddir is not portable - "
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef closedir
# define closedir rpl_closedir
+# define GNULIB_defined_closedir 1
# endif
_GL_FUNCDECL_RPL (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (closedir, int, (DIR *dirp));
diff --git a/lib/dirfd.c b/lib/dirfd.c
new file mode 100644
index 00000000000..c91f8e55872
--- /dev/null
+++ b/lib/dirfd.c
@@ -0,0 +1,32 @@
+/* dirfd.c -- return the file descriptor associated with an open DIR*
+
+ Copyright (C) 2001, 2006, 2008-2015 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering. */
+
+#include <config.h>
+
+#include <dirent.h>
+#include <errno.h>
+
+int
+dirfd (DIR *dir_p)
+{
+ int fd = DIR_TO_FD (dir_p);
+ if (fd == -1)
+ errno = ENOTSUP;
+ return fd;
+}
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;
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index 1b671e7f6de..7703cbfe283 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -237,6 +237,17 @@ EXTRA_DIST += dirent.in.h
## end gnulib module dirent
+## begin gnulib module dirfd
+
+if gl_GNULIB_ENABLED_dirfd
+
+endif
+EXTRA_DIST += dirfd.c
+
+EXTRA_libgnu_a_SOURCES += dirfd.c
+
+## end gnulib module dirfd
+
## begin gnulib module dosname
if gl_GNULIB_ENABLED_dosname