aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2018-10-08 18:21:47 -0700
committerPaul Eggert2018-10-08 18:22:22 -0700
commitcf1ebfa055fcd0749aa4ed2fc4c399470b9eb3de (patch)
tree8af8b5c52560c91b2094dae951b082c370496aea
parentfc6004e61760d3bd3e27b593c318e634a221652c (diff)
downloademacs-cf1ebfa055fcd0749aa4ed2fc4c399470b9eb3de.tar.gz
emacs-cf1ebfa055fcd0749aa4ed2fc4c399470b9eb3de.zip
Update from Gnulib
This incorporates: 2018-10-05 explicit_bzero: make it possible to namespace 2018-10-04 fcntl: make it possible to namespace 2018-10-01 mkostemp, mkostemps: fix C++ compilation on Mac OS X 2018-09-19 maint: mktime.c now shared with glibc 2018-09-18 file-has-acl: fix test failure on Cygwin 2.9 2018-09-18 gettime: nanotime never existed * admin/merge-gnulib (AVOIDED_MODULES): Add mkdir. * doc/misc/texinfo.tex, lib/acl-internal.c, lib/acl-internal.h: * lib/acl_entries.c, lib/explicit_bzero.c, lib/fcntl.c: * lib/get-permissions.c, lib/gettime.c, lib/mktime.c: * lib/set-permissions.c, lib/stdlib.in.h, m4/acl.m4, m4/gettime.m4: Copy from Gnulib. * lib/gnulib.mk.in: Regenerate.
-rwxr-xr-xadmin/merge-gnulib2
-rw-r--r--doc/misc/texinfo.tex3
-rw-r--r--lib/acl-internal.c12
-rw-r--r--lib/acl-internal.h16
-rw-r--r--lib/acl_entries.c6
-rw-r--r--lib/explicit_bzero.c4
-rw-r--r--lib/fcntl.c380
-rw-r--r--lib/get-permissions.c10
-rw-r--r--lib/gettime.c2
-rw-r--r--lib/gnulib.mk.in1
-rw-r--r--lib/mktime.c4
-rw-r--r--lib/set-permissions.c14
-rw-r--r--lib/stdlib.in.h3
-rw-r--r--m4/acl.m45
-rw-r--r--m4/gettime.m44
15 files changed, 250 insertions, 216 deletions
diff --git a/admin/merge-gnulib b/admin/merge-gnulib
index abb192911d9..575e3fa74a7 100755
--- a/admin/merge-gnulib
+++ b/admin/merge-gnulib
@@ -47,7 +47,7 @@ GNULIB_MODULES='
47 47
48AVOIDED_MODULES=' 48AVOIDED_MODULES='
49 btowc close dup fchdir fstat langinfo lock 49 btowc close dup fchdir fstat langinfo lock
50 malloc-posix mbrtowc mbsinit msvc-inval msvc-nothrow nl_langinfo 50 malloc-posix mbrtowc mbsinit mkdir msvc-inval msvc-nothrow nl_langinfo
51 openat-die opendir raise 51 openat-die opendir raise
52 save-cwd select setenv sigprocmask stat stdarg stdbool 52 save-cwd select setenv sigprocmask stat stdarg stdbool
53 threadlib tzset unsetenv utime utime-h 53 threadlib tzset unsetenv utime utime-h
diff --git a/doc/misc/texinfo.tex b/doc/misc/texinfo.tex
index d7f7f53a348..5840aff4d7c 100644
--- a/doc/misc/texinfo.tex
+++ b/doc/misc/texinfo.tex
@@ -3,7 +3,7 @@
3% Load plain if necessary, i.e., if running under initex. 3% Load plain if necessary, i.e., if running under initex.
4\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi 4\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
5% 5%
6\def\texinfoversion{2018-06-02.09} 6\def\texinfoversion{2018-09-21.20}
7% 7%
8% Copyright 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995, 8% Copyright 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
9% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 9% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
@@ -8004,6 +8004,7 @@ end
8004 \gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb} 8004 \gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
8005 \gdef\magicamp{\let&=\amprm} 8005 \gdef\magicamp{\let&=\amprm}
8006} 8006}
8007\let\ampchar\&
8007 8008
8008\newcount\parencount 8009\newcount\parencount
8009 8010
diff --git a/lib/acl-internal.c b/lib/acl-internal.c
index c62adb0d9d5..92e7b9bdf58 100644
--- a/lib/acl-internal.c
+++ b/lib/acl-internal.c
@@ -23,7 +23,7 @@
23 23
24#include "acl-internal.h" 24#include "acl-internal.h"
25 25
26#if USE_ACL && HAVE_ACL_GET_FILE 26#if USE_ACL && HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
27 27
28# if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */ 28# if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */
29 29
@@ -37,7 +37,7 @@ acl_extended_nontrivial (acl_t acl)
37 return (acl_entries (acl) > 0); 37 return (acl_entries (acl) > 0);
38} 38}
39 39
40# else /* Linux, FreeBSD, IRIX, Tru64 */ 40# else /* Linux, FreeBSD, IRIX, Tru64, Cygwin >= 2.5 */
41 41
42/* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS. 42/* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS.
43 Return 1 if the given ACL is non-trivial. 43 Return 1 if the given ACL is non-trivial.
@@ -51,7 +51,7 @@ acl_access_nontrivial (acl_t acl)
51 at least, allowing us to write 51 at least, allowing us to write
52 return (3 < acl_entries (acl)); 52 return (3 < acl_entries (acl));
53 but the following code is more robust. */ 53 but the following code is more robust. */
54# if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD */ 54# if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD, Cygwin >= 2.5 */
55 55
56 acl_entry_t ace; 56 acl_entry_t ace;
57 int got_one; 57 int got_one;
@@ -124,7 +124,7 @@ acl_default_nontrivial (acl_t acl)
124 124
125# endif 125# endif
126 126
127#elif USE_ACL && HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ 127#elif USE_ACL && HAVE_FACL && defined GETACL /* Solaris, Cygwin < 2.5, not HP-UX */
128 128
129/* Test an ACL retrieved with GETACL. 129/* Test an ACL retrieved with GETACL.
130 Return 1 if the given ACL, consisting of COUNT entries, is non-trivial. 130 Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
@@ -479,7 +479,7 @@ void
479free_permission_context (struct permission_context *ctx) 479free_permission_context (struct permission_context *ctx)
480{ 480{
481#if USE_ACL 481#if USE_ACL
482# if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ 482# if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
483 if (ctx->acl) 483 if (ctx->acl)
484 acl_free (ctx->acl); 484 acl_free (ctx->acl);
485# if !HAVE_ACL_TYPE_EXTENDED 485# if !HAVE_ACL_TYPE_EXTENDED
@@ -487,7 +487,7 @@ free_permission_context (struct permission_context *ctx)
487 acl_free (ctx->default_acl); 487 acl_free (ctx->default_acl);
488# endif 488# endif
489 489
490# elif defined GETACL /* Solaris, Cygwin */ 490# elif defined GETACL /* Solaris, Cygwin < 2.5 */
491 free (ctx->entries); 491 free (ctx->entries);
492# ifdef ACE_GETACL 492# ifdef ACE_GETACL
493 free (ctx->ace_entries); 493 free (ctx->ace_entries);
diff --git a/lib/acl-internal.h b/lib/acl-internal.h
index 0669d83c469..2da7c5a0366 100644
--- a/lib/acl-internal.h
+++ b/lib/acl-internal.h
@@ -30,7 +30,8 @@
30# define GETACLCNT ACL_CNT 30# define GETACLCNT ACL_CNT
31#endif 31#endif
32 32
33/* On Linux, additional ACL related API is available in <acl/libacl.h>. */ 33/* On Linux and Cygwin >= 2.5, additional ACL related API is available in
34 <acl/libacl.h>. */
34#ifdef HAVE_ACL_LIBACL_H 35#ifdef HAVE_ACL_LIBACL_H
35# include <acl/libacl.h> 36# include <acl/libacl.h>
36#endif 37#endif
@@ -72,7 +73,7 @@ _GL_INLINE_HEADER_BEGIN
72 73
73# if HAVE_ACL_GET_FILE 74# if HAVE_ACL_GET_FILE
74/* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ 75/* POSIX 1003.1e (draft 17 -- abandoned) specific version. */
75/* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ 76/* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
76 77
77# ifndef MIN_ACL_ENTRIES 78# ifndef MIN_ACL_ENTRIES
78# define MIN_ACL_ENTRIES 4 79# define MIN_ACL_ENTRIES 4
@@ -122,7 +123,10 @@ rpl_acl_set_fd (int fd, acl_t acl)
122# endif 123# endif
123 124
124/* Linux-specific */ 125/* Linux-specific */
125# ifndef HAVE_ACL_EXTENDED_FILE 126/* Cygwin >= 2.5 implements this function, but it returns 1 for all
127 directories, thus is unusable. */
128# if !defined HAVE_ACL_EXTENDED_FILE || defined __CYGWIN__
129# undef HAVE_ACL_EXTENDED_FILE
126# define HAVE_ACL_EXTENDED_FILE false 130# define HAVE_ACL_EXTENDED_FILE false
127# define acl_extended_file(name) (-1) 131# define acl_extended_file(name) (-1)
128# endif 132# endif
@@ -163,7 +167,7 @@ extern int acl_access_nontrivial (acl_t);
163extern int acl_default_nontrivial (acl_t); 167extern int acl_default_nontrivial (acl_t);
164# endif 168# endif
165 169
166# elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ 170# elif HAVE_FACL && defined GETACL /* Solaris, Cygwin < 2.5, not HP-UX */
167 171
168/* Set to 0 if a file's mode is stored independently from the ACL. */ 172/* Set to 0 if a file's mode is stored independently from the ACL. */
169# if defined __CYGWIN__ /* Cygwin */ 173# if defined __CYGWIN__ /* Cygwin */
@@ -256,14 +260,14 @@ extern int acl_nontrivial (int count, struct acl *entries);
256struct permission_context { 260struct permission_context {
257 mode_t mode; 261 mode_t mode;
258#if USE_ACL 262#if USE_ACL
259# if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ 263# if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
260 acl_t acl; 264 acl_t acl;
261# if !HAVE_ACL_TYPE_EXTENDED 265# if !HAVE_ACL_TYPE_EXTENDED
262 acl_t default_acl; 266 acl_t default_acl;
263# endif 267# endif
264 bool acls_not_supported; 268 bool acls_not_supported;
265 269
266# elif defined GETACL /* Solaris, Cygwin */ 270# elif defined GETACL /* Solaris, Cygwin < 2.5 */
267 int count; 271 int count;
268 aclent_t *entries; 272 aclent_t *entries;
269# ifdef ACE_GETACL 273# ifdef ACE_GETACL
diff --git a/lib/acl_entries.c b/lib/acl_entries.c
index 59dd420eaf4..ce730d466e1 100644
--- a/lib/acl_entries.c
+++ b/lib/acl_entries.c
@@ -22,7 +22,7 @@
22#include "acl-internal.h" 22#include "acl-internal.h"
23 23
24/* This file assumes POSIX-draft like ACLs 24/* This file assumes POSIX-draft like ACLs
25 (Linux, FreeBSD, Mac OS X, IRIX, Tru64). */ 25 (Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5). */
26 26
27/* Return the number of entries in ACL. 27/* Return the number of entries in ACL.
28 Return -1 and set errno upon failure to determine it. */ 28 Return -1 and set errno upon failure to determine it. */
@@ -34,7 +34,7 @@ acl_entries (acl_t acl)
34 34
35 if (acl != NULL) 35 if (acl != NULL)
36 { 36 {
37#if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD, Mac OS X */ 37#if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD, Mac OS X, Cygwin >= 2.5 */
38# if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */ 38# if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */
39 /* acl_get_entry returns 0 when it successfully fetches an entry, 39 /* acl_get_entry returns 0 when it successfully fetches an entry,
40 and -1/EINVAL at the end. */ 40 and -1/EINVAL at the end. */
@@ -45,7 +45,7 @@ acl_entries (acl_t acl)
45 got_one >= 0; 45 got_one >= 0;
46 got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace)) 46 got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace))
47 count++; 47 count++;
48# else /* Linux, FreeBSD */ 48# else /* Linux, FreeBSD, Cygwin >= 2.5 */
49 /* acl_get_entry returns 1 when it successfully fetches an entry, 49 /* acl_get_entry returns 1 when it successfully fetches an entry,
50 and 0 at the end. */ 50 and 0 at the end. */
51 acl_entry_t ace; 51 acl_entry_t ace;
diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c
index 78ec747c3a6..79b7fd66b66 100644
--- a/lib/explicit_bzero.c
+++ b/lib/explicit_bzero.c
@@ -27,9 +27,11 @@
27 27
28#include <string.h> 28#include <string.h>
29 29
30#if _LIBC
30/* glibc-internal users use __explicit_bzero_chk, and explicit_bzero 31/* glibc-internal users use __explicit_bzero_chk, and explicit_bzero
31 redirects to that. */ 32 redirects to that. */
32#undef explicit_bzero 33# undef explicit_bzero
34#endif
33 35
34/* Set LEN bytes of S to 0. The compiler will not delete a call to 36/* Set LEN bytes of S to 0. The compiler will not delete a call to
35 this function, even if S is dead after the call. */ 37 this function, even if S is dead after the call. */
diff --git a/lib/fcntl.c b/lib/fcntl.c
index 8e976173c0b..74e0f5d3910 100644
--- a/lib/fcntl.c
+++ b/lib/fcntl.c
@@ -27,10 +27,10 @@
27#include <stdarg.h> 27#include <stdarg.h>
28#include <unistd.h> 28#include <unistd.h>
29 29
30#if !HAVE_FCNTL 30#ifdef __KLIBC__
31# define rpl_fcntl fcntl 31# define INCL_DOS
32# include <os2.h>
32#endif 33#endif
33#undef fcntl
34 34
35#if defined _WIN32 && ! defined __CYGWIN__ 35#if defined _WIN32 && ! defined __CYGWIN__
36/* Get declarations of the native Windows API functions. */ 36/* Get declarations of the native Windows API functions. */
@@ -166,93 +166,18 @@ dupfd (int oldfd, int newfd, int flags)
166} 166}
167#endif /* W32 */ 167#endif /* W32 */
168 168
169/* Forward declarations, because we '#undef fcntl' in the middle of this
170 compilation unit. */
171/* Our implementation of fcntl (fd, F_DUPFD, target). */
172static int rpl_fcntl_DUPFD (int fd, int target);
173/* Our implementation of fcntl (fd, F_DUPFD_CLOEXEC, target). */
174static int rpl_fcntl_DUPFD_CLOEXEC (int fd, int target);
169#ifdef __KLIBC__ 175#ifdef __KLIBC__
170 176/* Adds support for fcntl on directories. */
171# define INCL_DOS 177static int klibc_fcntl (int fd, int action, /* arg */...);
172# include <os2.h>
173
174static int
175klibc_fcntl (int fd, int action, /* arg */...)
176{
177 va_list arg_ptr;
178 int arg;
179 struct stat sbuf;
180 int result = -1;
181
182 va_start (arg_ptr, action);
183 arg = va_arg (arg_ptr, int);
184 result = fcntl (fd, action, arg);
185 /* EPERM for F_DUPFD, ENOTSUP for others */
186 if (result == -1 && (errno == EPERM || errno == ENOTSUP)
187 && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
188 {
189 ULONG ulMode;
190
191 switch (action)
192 {
193 case F_DUPFD:
194 /* Find available fd */
195 while (fcntl (arg, F_GETFL) != -1 || errno != EBADF)
196 arg++;
197
198 result = dup2 (fd, arg);
199 break;
200
201 /* Using underlying APIs is right ? */
202 case F_GETFD:
203 if (DosQueryFHState (fd, &ulMode))
204 break;
205
206 result = (ulMode & OPEN_FLAGS_NOINHERIT) ? FD_CLOEXEC : 0;
207 break;
208
209 case F_SETFD:
210 if (arg & ~FD_CLOEXEC)
211 break;
212
213 if (DosQueryFHState (fd, &ulMode))
214 break;
215
216 if (arg & FD_CLOEXEC)
217 ulMode |= OPEN_FLAGS_NOINHERIT;
218 else
219 ulMode &= ~OPEN_FLAGS_NOINHERIT;
220
221 /* Filter supported flags. */
222 ulMode &= (OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR
223 | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT);
224
225 if (DosSetFHState (fd, ulMode))
226 break;
227
228 result = 0;
229 break;
230
231 case F_GETFL:
232 result = 0;
233 break;
234
235 case F_SETFL:
236 if (arg != 0)
237 break;
238
239 result = 0;
240 break;
241
242 default :
243 errno = EINVAL;
244 break;
245 }
246 }
247
248 va_end (arg_ptr);
249
250 return result;
251}
252
253# define fcntl klibc_fcntl
254#endif 178#endif
255 179
180
256/* Perform the specified ACTION on the file descriptor FD, possibly 181/* Perform the specified ACTION on the file descriptor FD, possibly
257 using the argument ARG further described below. This replacement 182 using the argument ARG further described below. This replacement
258 handles the following actions, and forwards all others on to the 183 handles the following actions, and forwards all others on to the
@@ -273,112 +198,30 @@ klibc_fcntl (int fd, int action, /* arg */...)
273 return -1 and set errno. */ 198 return -1 and set errno. */
274 199
275int 200int
276rpl_fcntl (int fd, int action, /* arg */...) 201fcntl (int fd, int action, /* arg */...)
202#undef fcntl
203#ifdef __KLIBC__
204# define fcntl klibc_fcntl
205#endif
277{ 206{
278 va_list arg; 207 va_list arg;
279 int result = -1; 208 int result = -1;
280 va_start (arg, action); 209 va_start (arg, action);
281 switch (action) 210 switch (action)
282 { 211 {
283
284#if !HAVE_FCNTL
285 case F_DUPFD: 212 case F_DUPFD:
286 { 213 {
287 int target = va_arg (arg, int); 214 int target = va_arg (arg, int);
288 result = dupfd (fd, target, 0); 215 result = rpl_fcntl_DUPFD (fd, target);
289 break; 216 break;
290 } 217 }
291#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR
292 case F_DUPFD:
293 {
294 int target = va_arg (arg, int);
295 /* Detect invalid target; needed for cygwin 1.5.x. */
296 if (target < 0 || getdtablesize () <= target)
297 errno = EINVAL;
298 else
299 {
300 /* Haiku alpha 2 loses fd flags on original. */
301 int flags = fcntl (fd, F_GETFD);
302 if (flags < 0)
303 {
304 result = -1;
305 break;
306 }
307 result = fcntl (fd, action, target);
308 if (0 <= result && fcntl (fd, F_SETFD, flags) == -1)
309 {
310 int saved_errno = errno;
311 close (result);
312 result = -1;
313 errno = saved_errno;
314 }
315# if REPLACE_FCHDIR
316 if (0 <= result)
317 result = _gl_register_dup (fd, result);
318# endif
319 }
320 break;
321 } /* F_DUPFD */
322#endif /* FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR */
323 218
324 case F_DUPFD_CLOEXEC: 219 case F_DUPFD_CLOEXEC:
325 { 220 {
326 int target = va_arg (arg, int); 221 int target = va_arg (arg, int);
327 222 result = rpl_fcntl_DUPFD_CLOEXEC (fd, target);
328#if !HAVE_FCNTL
329 result = dupfd (fd, target, O_CLOEXEC);
330 break; 223 break;
331#else /* HAVE_FCNTL */ 224 }
332# if defined __HAIKU__
333 /* On Haiku, the system fcntl (fd, F_DUPFD_CLOEXEC, target) sets
334 the FD_CLOEXEC flag on fd, not on target. Therefore avoid the
335 system fcntl in this case. */
336# define have_dupfd_cloexec -1
337# else
338 /* Try the system call first, if the headers claim it exists
339 (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we
340 may be running with a glibc that has the macro but with an
341 older kernel that does not support it. Cache the
342 information on whether the system call really works, but
343 avoid caching failure if the corresponding F_DUPFD fails
344 for any reason. 0 = unknown, 1 = yes, -1 = no. */
345 static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0;
346 if (0 <= have_dupfd_cloexec)
347 {
348 result = fcntl (fd, action, target);
349 if (0 <= result || errno != EINVAL)
350 {
351 have_dupfd_cloexec = 1;
352# if REPLACE_FCHDIR
353 if (0 <= result)
354 result = _gl_register_dup (fd, result);
355# endif
356 }
357 else
358 {
359 result = rpl_fcntl (fd, F_DUPFD, target);
360 if (result < 0)
361 break;
362 have_dupfd_cloexec = -1;
363 }
364 }
365 else
366# endif
367 result = rpl_fcntl (fd, F_DUPFD, target);
368 if (0 <= result && have_dupfd_cloexec == -1)
369 {
370 int flags = fcntl (result, F_GETFD);
371 if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1)
372 {
373 int saved_errno = errno;
374 close (result);
375 errno = saved_errno;
376 result = -1;
377 }
378 }
379 break;
380#endif /* HAVE_FCNTL */
381 } /* F_DUPFD_CLOEXEC */
382 225
383#if !HAVE_FCNTL 226#if !HAVE_FCNTL
384 case F_GETFD: 227 case F_GETFD:
@@ -598,3 +441,186 @@ rpl_fcntl (int fd, int action, /* arg */...)
598 va_end (arg); 441 va_end (arg);
599 return result; 442 return result;
600} 443}
444
445static int
446rpl_fcntl_DUPFD (int fd, int target)
447{
448 int result;
449#if !HAVE_FCNTL
450 result = dupfd (fd, target, 0);
451#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR
452 /* Detect invalid target; needed for cygwin 1.5.x. */
453 if (target < 0 || getdtablesize () <= target)
454 {
455 result = -1;
456 errno = EINVAL;
457 }
458 else
459 {
460 /* Haiku alpha 2 loses fd flags on original. */
461 int flags = fcntl (fd, F_GETFD);
462 if (flags < 0)
463 result = -1;
464 else
465 {
466 result = fcntl (fd, F_DUPFD, target);
467 if (0 <= result && fcntl (fd, F_SETFD, flags) == -1)
468 {
469 int saved_errno = errno;
470 close (result);
471 result = -1;
472 errno = saved_errno;
473 }
474# if REPLACE_FCHDIR
475 if (0 <= result)
476 result = _gl_register_dup (fd, result);
477# endif
478 }
479 }
480#else
481 result = fcntl (fd, F_DUPFD, target);
482#endif
483 return result;
484}
485
486static int
487rpl_fcntl_DUPFD_CLOEXEC (int fd, int target)
488{
489 int result;
490#if !HAVE_FCNTL
491 result = dupfd (fd, target, O_CLOEXEC);
492#else /* HAVE_FCNTL */
493# if defined __HAIKU__
494 /* On Haiku, the system fcntl (fd, F_DUPFD_CLOEXEC, target) sets
495 the FD_CLOEXEC flag on fd, not on target. Therefore avoid the
496 system fcntl in this case. */
497# define have_dupfd_cloexec -1
498# else
499 /* Try the system call first, if the headers claim it exists
500 (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we
501 may be running with a glibc that has the macro but with an
502 older kernel that does not support it. Cache the
503 information on whether the system call really works, but
504 avoid caching failure if the corresponding F_DUPFD fails
505 for any reason. 0 = unknown, 1 = yes, -1 = no. */
506 static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0;
507 if (0 <= have_dupfd_cloexec)
508 {
509 result = fcntl (fd, F_DUPFD_CLOEXEC, target);
510 if (0 <= result || errno != EINVAL)
511 {
512 have_dupfd_cloexec = 1;
513# if REPLACE_FCHDIR
514 if (0 <= result)
515 result = _gl_register_dup (fd, result);
516# endif
517 }
518 else
519 {
520 result = rpl_fcntl_DUPFD (fd, target);
521 if (result >= 0)
522 have_dupfd_cloexec = -1;
523 }
524 }
525 else
526# endif
527 result = rpl_fcntl_DUPFD (fd, target);
528 if (0 <= result && have_dupfd_cloexec == -1)
529 {
530 int flags = fcntl (result, F_GETFD);
531 if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1)
532 {
533 int saved_errno = errno;
534 close (result);
535 errno = saved_errno;
536 result = -1;
537 }
538 }
539#endif /* HAVE_FCNTL */
540 return result;
541}
542
543#undef fcntl
544
545#ifdef __KLIBC__
546
547static int
548klibc_fcntl (int fd, int action, /* arg */...);
549{
550 va_list arg_ptr;
551 int arg;
552 struct stat sbuf;
553 int result;
554
555 va_start (arg_ptr, action);
556 arg = va_arg (arg_ptr, int);
557 result = fcntl (fd, action, arg);
558 /* EPERM for F_DUPFD, ENOTSUP for others */
559 if (result == -1 && (errno == EPERM || errno == ENOTSUP)
560 && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
561 {
562 ULONG ulMode;
563
564 switch (action)
565 {
566 case F_DUPFD:
567 /* Find available fd */
568 while (fcntl (arg, F_GETFL) != -1 || errno != EBADF)
569 arg++;
570
571 result = dup2 (fd, arg);
572 break;
573
574 /* Using underlying APIs is right ? */
575 case F_GETFD:
576 if (DosQueryFHState (fd, &ulMode))
577 break;
578
579 result = (ulMode & OPEN_FLAGS_NOINHERIT) ? FD_CLOEXEC : 0;
580 break;
581
582 case F_SETFD:
583 if (arg & ~FD_CLOEXEC)
584 break;
585
586 if (DosQueryFHState (fd, &ulMode))
587 break;
588
589 if (arg & FD_CLOEXEC)
590 ulMode |= OPEN_FLAGS_NOINHERIT;
591 else
592 ulMode &= ~OPEN_FLAGS_NOINHERIT;
593
594 /* Filter supported flags. */
595 ulMode &= (OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR
596 | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT);
597
598 if (DosSetFHState (fd, ulMode))
599 break;
600
601 result = 0;
602 break;
603
604 case F_GETFL:
605 result = 0;
606 break;
607
608 case F_SETFL:
609 if (arg != 0)
610 break;
611
612 result = 0;
613 break;
614
615 default:
616 errno = EINVAL;
617 break;
618 }
619 }
620
621 va_end (arg_ptr);
622
623 return result;
624}
625
626#endif
diff --git a/lib/get-permissions.c b/lib/get-permissions.c
index 83ba2639a17..3b984510955 100644
--- a/lib/get-permissions.c
+++ b/lib/get-permissions.c
@@ -38,9 +38,9 @@ get_permissions (const char *name, int desc, mode_t mode,
38 38
39#if USE_ACL && HAVE_ACL_GET_FILE 39#if USE_ACL && HAVE_ACL_GET_FILE
40 /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ 40 /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */
41 /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ 41 /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
42# if !HAVE_ACL_TYPE_EXTENDED 42# if !HAVE_ACL_TYPE_EXTENDED
43 /* Linux, FreeBSD, IRIX, Tru64 */ 43 /* Linux, FreeBSD, IRIX, Tru64, Cygwin >= 2.5 */
44 44
45 if (HAVE_ACL_GET_FD && desc != -1) 45 if (HAVE_ACL_GET_FD && desc != -1)
46 ctx->acl = acl_get_fd (desc); 46 ctx->acl = acl_get_fd (desc);
@@ -60,13 +60,13 @@ get_permissions (const char *name, int desc, mode_t mode,
60 return -1; 60 return -1;
61 } 61 }
62 62
63# if HAVE_ACL_TYPE_NFS4 /* FreeBSD */ 63# if HAVE_ACL_TYPE_NFS4 /* FreeBSD */
64 64
65 /* TODO (see set_permissions). */ 65 /* TODO (see set_permissions). */
66 66
67# endif 67# endif
68 68
69# else /* HAVE_ACL_TYPE_EXTENDED */ 69# else /* HAVE_ACL_TYPE_EXTENDED */
70 /* Mac OS X */ 70 /* Mac OS X */
71 71
72 /* On Mac OS X, acl_get_file (name, ACL_TYPE_ACCESS) 72 /* On Mac OS X, acl_get_file (name, ACL_TYPE_ACCESS)
diff --git a/lib/gettime.c b/lib/gettime.c
index 171f22476f8..bb59c44ff0e 100644
--- a/lib/gettime.c
+++ b/lib/gettime.c
@@ -30,8 +30,6 @@ gettime (struct timespec *ts)
30{ 30{
31#if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME 31#if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME
32 clock_gettime (CLOCK_REALTIME, ts); 32 clock_gettime (CLOCK_REALTIME, ts);
33#elif HAVE_NANOTIME
34 nanotime (ts);
35#else 33#else
36 struct timeval tv; 34 struct timeval tv;
37 gettimeofday (&tv, NULL); 35 gettimeofday (&tv, NULL);
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index 2e265b3068b..431d0c0b77b 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -44,6 +44,7 @@
44# --avoid=malloc-posix \ 44# --avoid=malloc-posix \
45# --avoid=mbrtowc \ 45# --avoid=mbrtowc \
46# --avoid=mbsinit \ 46# --avoid=mbsinit \
47# --avoid=mkdir \
47# --avoid=msvc-inval \ 48# --avoid=msvc-inval \
48# --avoid=msvc-nothrow \ 49# --avoid=msvc-nothrow \
49# --avoid=nl_langinfo \ 50# --avoid=nl_langinfo \
diff --git a/lib/mktime.c b/lib/mktime.c
index 6953e984e5d..557712fdaa4 100644
--- a/lib/mktime.c
+++ b/lib/mktime.c
@@ -78,7 +78,7 @@
78 78
79#include "mktime-internal.h" 79#include "mktime-internal.h"
80 80
81#ifndef _LIBC 81#if !defined _LIBC && (NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS)
82static void 82static void
83my_tzset (void) 83my_tzset (void)
84{ 84{
@@ -527,7 +527,7 @@ mktime (struct tm *tp)
527 be set as if the tzset() function had been called. */ 527 be set as if the tzset() function had been called. */
528 __tzset (); 528 __tzset ();
529 529
530# if defined __LIBC || NEED_MKTIME_WORKING 530# if defined _LIBC || NEED_MKTIME_WORKING
531 static mktime_offset_t localtime_offset; 531 static mktime_offset_t localtime_offset;
532 return __mktime_internal (tp, __localtime_r, &localtime_offset); 532 return __mktime_internal (tp, __localtime_r, &localtime_offset);
533# else 533# else
diff --git a/lib/set-permissions.c b/lib/set-permissions.c
index d42335aa502..a415e133ac7 100644
--- a/lib/set-permissions.c
+++ b/lib/set-permissions.c
@@ -24,7 +24,7 @@
24#include "acl-internal.h" 24#include "acl-internal.h"
25 25
26#if USE_ACL 26#if USE_ACL
27# if ! defined HAVE_ACL_FROM_MODE && defined HAVE_ACL_FROM_TEXT /* FreeBSD, IRIX, Tru64 */ 27# if ! defined HAVE_ACL_FROM_MODE && defined HAVE_ACL_FROM_TEXT /* FreeBSD, IRIX, Tru64, Cygwin >= 2.5 */
28# if HAVE_ACL_GET_FILE && !HAVE_ACL_TYPE_EXTENDED 28# if HAVE_ACL_GET_FILE && !HAVE_ACL_TYPE_EXTENDED
29 29
30static acl_t 30static acl_t
@@ -32,7 +32,7 @@ acl_from_mode (mode_t mode)
32{ 32{
33# if HAVE_ACL_FREE_TEXT /* Tru64 */ 33# if HAVE_ACL_FREE_TEXT /* Tru64 */
34 char acl_text[] = "u::---,g::---,o::---,"; 34 char acl_text[] = "u::---,g::---,o::---,";
35# else /* FreeBSD, IRIX */ 35# else /* FreeBSD, IRIX, Cygwin >= 2.5 */
36 char acl_text[] = "u::---,g::---,o::---"; 36 char acl_text[] = "u::---,g::---,o::---";
37# endif 37# endif
38 38
@@ -51,7 +51,7 @@ acl_from_mode (mode_t mode)
51# endif 51# endif
52# endif 52# endif
53 53
54# if HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ 54# if HAVE_FACL && defined GETACL /* Solaris, Cygwin < 2.5, not HP-UX */
55static int 55static int
56set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod) 56set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
57{ 57{
@@ -489,9 +489,9 @@ set_acls (struct permission_context *ctx, const char *name, int desc,
489 489
490# if HAVE_ACL_GET_FILE 490# if HAVE_ACL_GET_FILE
491 /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ 491 /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */
492 /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ 492 /* Linux, FreeBSD, Mac OS X, IRIX, Tru64, Cygwin >= 2.5 */
493# if !HAVE_ACL_TYPE_EXTENDED 493# if !HAVE_ACL_TYPE_EXTENDED
494 /* Linux, FreeBSD, IRIX, Tru64 */ 494 /* Linux, FreeBSD, IRIX, Tru64, Cygwin >= 2.5 */
495 495
496# ifndef HAVE_ACL_FROM_TEXT 496# ifndef HAVE_ACL_FROM_TEXT
497# error Must have acl_from_text (see POSIX 1003.1e draft 17). 497# error Must have acl_from_text (see POSIX 1003.1e draft 17).
@@ -542,14 +542,14 @@ set_acls (struct permission_context *ctx, const char *name, int desc,
542 } 542 }
543 } 543 }
544 544
545# if HAVE_ACL_TYPE_NFS4 /* FreeBSD */ 545# if HAVE_ACL_TYPE_NFS4 /* FreeBSD */
546 546
547 /* File systems either support POSIX ACLs (for example, ufs) or NFS4 ACLs 547 /* File systems either support POSIX ACLs (for example, ufs) or NFS4 ACLs
548 (for example, zfs). */ 548 (for example, zfs). */
549 549
550 /* TODO: Implement setting ACLs once get_permissions() reads them. */ 550 /* TODO: Implement setting ACLs once get_permissions() reads them. */
551 551
552# endif 552# endif
553 553
554# else /* HAVE_ACL_TYPE_EXTENDED */ 554# else /* HAVE_ACL_TYPE_EXTENDED */
555 /* Mac OS X */ 555 /* Mac OS X */
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 3bf35bf6b0f..441c018ec18 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -90,9 +90,10 @@ struct random_data
90# endif 90# endif
91#endif 91#endif
92 92
93#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !(defined _WIN32 && ! defined __CYGWIN__) 93#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_MKOSTEMP@ || @GNULIB_MKOSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !(defined _WIN32 && ! defined __CYGWIN__)
94/* On Mac OS X 10.3, only <unistd.h> declares mkstemp. */ 94/* On Mac OS X 10.3, only <unistd.h> declares mkstemp. */
95/* On Mac OS X 10.5, only <unistd.h> declares mkstemps. */ 95/* On Mac OS X 10.5, only <unistd.h> declares mkstemps. */
96/* On Mac OS X 10.13, only <unistd.h> declares mkostemp and mkostemps. */
96/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */ 97/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */
97/* But avoid namespace pollution on glibc systems and native Windows. */ 98/* But avoid namespace pollution on glibc systems and native Windows. */
98# include <unistd.h> 99# include <unistd.h>
diff --git a/m4/acl.m4 b/m4/acl.m4
index 485cf9af08b..b64aa849c88 100644
--- a/m4/acl.m4
+++ b/m4/acl.m4
@@ -1,5 +1,5 @@
1# acl.m4 - check for access control list (ACL) primitives 1# acl.m4 - check for access control list (ACL) primitives
2# serial 22 2# serial 23
3 3
4# Copyright (C) 2002, 2004-2018 Free Software Foundation, Inc. 4# Copyright (C) 2002, 2004-2018 Free Software Foundation, Inc.
5# This file is free software; the Free Software Foundation 5# This file is free software; the Free Software Foundation
@@ -30,7 +30,8 @@ AC_DEFUN([gl_FUNC_ACL],
30 ac_save_LIBS=$LIBS 30 ac_save_LIBS=$LIBS
31 31
32 dnl Test for POSIX-draft-like API (GNU/Linux, FreeBSD, Mac OS X, 32 dnl Test for POSIX-draft-like API (GNU/Linux, FreeBSD, Mac OS X,
33 dnl IRIX, Tru64). -lacl is needed on GNU/Linux, -lpacl on OSF/1. 33 dnl IRIX, Tru64, Cygwin >= 2.5).
34 dnl -lacl is needed on GNU/Linux, -lpacl on OSF/1.
34 if test $use_acl = 0; then 35 if test $use_acl = 0; then
35 AC_SEARCH_LIBS([acl_get_file], [acl pacl], 36 AC_SEARCH_LIBS([acl_get_file], [acl pacl],
36 [if test "$ac_cv_search_acl_get_file" != "none required"; then 37 [if test "$ac_cv_search_acl_get_file" != "none required"; then
diff --git a/m4/gettime.m4 b/m4/gettime.m4
index ad355463cce..671b70d5ab2 100644
--- a/m4/gettime.m4
+++ b/m4/gettime.m4
@@ -1,4 +1,4 @@
1# gettime.m4 serial 8 1# gettime.m4 serial 9
2dnl Copyright (C) 2002, 2004-2006, 2009-2018 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2004-2006, 2009-2018 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
@@ -9,5 +9,5 @@ AC_DEFUN([gl_GETTIME],
9 dnl Prerequisites of lib/gettime.c. 9 dnl Prerequisites of lib/gettime.c.
10 AC_REQUIRE([gl_CLOCK_TIME]) 10 AC_REQUIRE([gl_CLOCK_TIME])
11 AC_REQUIRE([gl_TIMESPEC]) 11 AC_REQUIRE([gl_TIMESPEC])
12 AC_CHECK_FUNCS_ONCE([gettimeofday nanotime]) 12 AC_CHECK_FUNCS_ONCE([gettimeofday])
13]) 13])