summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2018-05-21 11:42:18 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2018-05-21 11:43:07 -0700
commit79f15092b9d16631840cd42db034b787fae762ac (patch)
tree86f3e4917944af36516547d4d19d5dda758684f1 /lib
parentf21db9e1206f830ee5e991a26f9e30056f68efb8 (diff)
downloademacs-79f15092b9d16631840cd42db034b787fae762ac.tar.gz
Update from Gnulib
This incorporates: 2018-05-21 crypto: omit stream ops Emacs doesn’t need 2018-05-13 truncate: Fix compilation error on Android 2018-05-13 imaxdiv: Fix compilation error on Android 2018-05-13 Support selective inclusion of recent mingw.org headers 2018-05-13 Add cross-compilation guesses for Linux systems sans glibc 2018-05-13 stdioext: Fix compilation errors with newer Android headers 2018-05-07 af_alg: Pacify --enable-gcc-warnings 2018-05-06 af_alg: Fix bug with streams that are not at position 0 2018-05-06 Followup to 'af_alg: New module' 2018-05-05 crypto/{md5,sha1,sha256,sha512}: simplify 2018-05-05 af_alg: New module 2018-05-05 af_alg: Improve function signature 2018-04-28 md5sum: Use AF_ALG when available 2018-04-28 sha512sum: Use AF_ALG when available 2018-04-28 sha256sum: Use AF_ALG when available 2018-04-28 sha1sum: Use AF_ALG when available 2018-05-05 all: Replace more http URLs by https URLs 2018-05-03 maint: port more modules to GCC 8 2018-05-03 Simplify code; drop support for Borland C++ on Windows * admin/merge-gnulib (GNULIB_MODULES): Use crypto/md5-buffer rather than crypto/md5, since Emacs doesn’t use the stream operations that in recent Gnulib pull in other stuff Emacs doesn’t need. Similarly for crypto/sha1-buffer, crypto/sha256-buffer, crypto/sha512-buffer. * build-aux/config.guess, build-aux/config.sub, lib/dosname.h: * lib/dup2.c, lib/errno.in.h, lib/euidaccess.c, lib/fcntl.c: * lib/fcntl.in.h, lib/fpending.c, lib/fsync.c, lib/getdtablesize.c: * lib/getopt.c, lib/gettimeofday.c, lib/inttypes.in.h, lib/md5.c: * lib/md5.h, lib/open.c, lib/pipe2.c, lib/putenv.c, lib/sha1.c: * lib/sha1.h, lib/sha256.c, lib/sha256.h, lib/sha512.c: * lib/sha512.h, lib/stat-time.h, lib/stdio-impl.h, lib/stdio.in.h: * lib/stdlib.in.h, lib/sys_stat.in.h, lib/sys_types.in.h: * lib/timespec.h, lib/unistd.in.h, lib/utimens.c, m4/c-strtod.m4: * m4/gnulib-common.m4, m4/inttypes.m4, m4/lstat.m4, m4/nocrash.m4: * m4/pselect.m4, m4/readlink.m4, m4/stdio_h.m4, m4/symlink.m4: * m4/unistd_h.m4, m4/utimens.m4: Copy from Gnulib. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
Diffstat (limited to 'lib')
-rw-r--r--lib/dosname.h5
-rw-r--r--lib/dup2.c2
-rw-r--r--lib/errno.in.h4
-rw-r--r--lib/euidaccess.c4
-rw-r--r--lib/fcntl.c4
-rw-r--r--lib/fcntl.in.h2
-rw-r--r--lib/fpending.c3
-rw-r--r--lib/fsync.c2
-rw-r--r--lib/getdtablesize.c2
-rw-r--r--lib/getopt.c2
-rw-r--r--lib/gettimeofday.c2
-rw-r--r--lib/gnulib.mk.in32
-rw-r--r--lib/inttypes.in.h6
-rw-r--r--lib/md5.c15
-rw-r--r--lib/md5.h7
-rw-r--r--lib/open.c2
-rw-r--r--lib/pipe2.c7
-rw-r--r--lib/putenv.c4
-rw-r--r--lib/sha1.c17
-rw-r--r--lib/sha1.h7
-rw-r--r--lib/sha256.c119
-rw-r--r--lib/sha256.h7
-rw-r--r--lib/sha512.c107
-rw-r--r--lib/sha512.h7
-rw-r--r--lib/stat-time.h2
-rw-r--r--lib/stdio-impl.h62
-rw-r--r--lib/stdio.in.h4
-rw-r--r--lib/stdlib.in.h4
-rw-r--r--lib/sys_stat.in.h6
-rw-r--r--lib/sys_types.in.h15
-rw-r--r--lib/timespec.h2
-rw-r--r--lib/unistd.in.h8
-rw-r--r--lib/utimens.c3
33 files changed, 242 insertions, 233 deletions
diff --git a/lib/dosname.h b/lib/dosname.h
index 66486d5209d..fef3b6daa1f 100644
--- a/lib/dosname.h
+++ b/lib/dosname.h
@@ -20,9 +20,8 @@
#ifndef _DOSNAME_H
#define _DOSNAME_H
-#if (defined _WIN32 || defined __WIN32__ || \
- defined __MSDOS__ || defined __CYGWIN__ || \
- defined __EMX__ || defined __DJGPP__)
+#if (defined _WIN32 || defined __CYGWIN__ \
+ || defined __EMX__ || defined __MSDOS__ || defined __DJGPP__)
/* This internal macro assumes ASCII, but all hosts that support drive
letters use ASCII. */
# define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a' \
diff --git a/lib/dup2.c b/lib/dup2.c
index c8b49b25e47..c7d176728d4 100644
--- a/lib/dup2.c
+++ b/lib/dup2.c
@@ -29,7 +29,7 @@
# undef dup2
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# if defined _WIN32 && ! defined __CYGWIN__
/* Get declarations of the native Windows API functions. */
# define WIN32_LEAN_AND_MEAN
diff --git a/lib/errno.in.h b/lib/errno.in.h
index 8d2f3074fab..b95c4e9ce76 100644
--- a/lib/errno.in.h
+++ b/lib/errno.in.h
@@ -30,7 +30,7 @@
/* On native Windows platforms, many macros are not defined. */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# if defined _WIN32 && ! defined __CYGWIN__
/* These are the same values as defined by MSVC 10, for interoperability. */
@@ -248,7 +248,7 @@
interoperability. */
# define EOWNERDEAD 58
# define ENOTRECOVERABLE 59
-# elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# elif defined _WIN32 && ! defined __CYGWIN__
/* We have a conflict here: pthreads-win32 defines these values
differently than MSVC 10. It's hairy to decide which one to use. */
# if defined __MINGW32__ && !defined USE_WINDOWS_THREADS
diff --git a/lib/euidaccess.c b/lib/euidaccess.c
index 4f512f5af54..de5d82b52d5 100644
--- a/lib/euidaccess.c
+++ b/lib/euidaccess.c
@@ -29,7 +29,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
# include <io.h>
#else
# include "root-uid.h"
@@ -87,7 +87,7 @@ euidaccess (const char *file, int mode)
return accessx (file, mode, ACC_SELF);
#elif HAVE_EACCESS /* FreeBSD */
return eaccess (file, mode);
-#elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* mingw */
+#elif defined _WIN32 && ! defined __CYGWIN__ /* mingw */
return _access (file, mode);
#else /* Mac OS X, NetBSD, OpenBSD, HP-UX, Solaris, Cygwin, BeOS */
diff --git a/lib/fcntl.c b/lib/fcntl.c
index b8cb271f55c..be6583565b4 100644
--- a/lib/fcntl.c
+++ b/lib/fcntl.c
@@ -32,7 +32,7 @@
#endif
#undef fcntl
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
/* Get declarations of the native Windows API functions. */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
@@ -376,7 +376,7 @@ rpl_fcntl (int fd, int action, /* arg */...)
#if !HAVE_FCNTL
case F_GETFD:
{
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# if defined _WIN32 && ! defined __CYGWIN__
HANDLE handle = (HANDLE) _get_osfhandle (fd);
DWORD flags;
if (handle == INVALID_HANDLE_VALUE
diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h
index 719a54d0f72..a1e7d35c1b9 100644
--- a/lib/fcntl.in.h
+++ b/lib/fcntl.in.h
@@ -68,7 +68,7 @@
/* Native Windows platforms declare open(), creat() in <io.h>. */
#if (@GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
- && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+ && (defined _WIN32 && ! defined __CYGWIN__)
# include <io.h>
#endif
diff --git a/lib/fpending.c b/lib/fpending.c
index 7bc235deda2..de370d4b10f 100644
--- a/lib/fpending.c
+++ b/lib/fpending.c
@@ -24,6 +24,9 @@
#include "stdio-impl.h"
+/* This file is not used on systems that already have the __fpending function,
+ namely glibc >= 2.2, Solaris >= 7, Android API >= 23. */
+
/* Return the number of pending (aka buffered, unflushed)
bytes on the stream, FP, that is open for writing. */
size_t
diff --git a/lib/fsync.c b/lib/fsync.c
index a0b12b6ccc7..ecacb0ba25e 100644
--- a/lib/fsync.c
+++ b/lib/fsync.c
@@ -25,7 +25,7 @@
#include <config.h>
#include <unistd.h>
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
/* FlushFileBuffers */
# define WIN32_LEAN_AND_MEAN
diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c
index c6c1136fc55..ac05bc483cc 100644
--- a/lib/getdtablesize.c
+++ b/lib/getdtablesize.c
@@ -20,7 +20,7 @@
/* Specification. */
#include <unistd.h>
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
# include <stdio.h>
diff --git a/lib/getopt.c b/lib/getopt.c
index 55375ccd40f..11e36eef815 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -46,7 +46,7 @@
/* When used standalone, flockfile and funlockfile might not be
available. */
# if (!defined _POSIX_THREAD_SAFE_FUNCTIONS \
- || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
+ || (defined _WIN32 && ! defined __CYGWIN__))
# define flockfile(fp) /* nop */
# define funlockfile(fp) /* nop */
# endif
diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
index 39575658264..d598b2f7f56 100644
--- a/lib/gettimeofday.c
+++ b/lib/gettimeofday.c
@@ -24,7 +24,7 @@
#include <time.h>
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
# define WINDOWS_NATIVE
# include <windows.h>
#endif
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index ce47b9de661..19128bab2da 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -21,7 +21,7 @@
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=close --avoid=dup --avoid=fchdir --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=setenv --avoid=sigprocmask --avoid=stat --avoid=stdarg --avoid=stdbool --avoid=threadlib --avoid=tzset --avoid=unsetenv --avoid=utime --avoid=utime-h --gnu-make --makefile-name=gnulib.mk.in --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt binary-io byteswap c-ctype c-strcase careadlinkat close-stream count-leading-zeros count-one-bits count-trailing-zeros crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 d-type diffseq dtoastr dtotimespec dup2 environ execinfo explicit_bzero faccessat fcntl fcntl-h fdatasync fdopendir filemode filevercmp flexmember fstatat fsusage fsync getloadavg getopt-gnu gettime gettimeofday gitlog-to-changelog ignore-value intprops largefile lstat manywarnings memrchr minmax mkostemp mktime nstrftime pipe2 pselect pthread_sigmask putenv qcopy-acl readlink readlinkat sig2str socklen stat-time std-gnu11 stdalign stddef stdio stpcpy strtoimax symlink sys_stat sys_time tempname time time_r time_rz timegm timer-time timespec-add timespec-sub unlocked-io update-copyright utimens vla warnings
+# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=close --avoid=dup --avoid=fchdir --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=setenv --avoid=sigprocmask --avoid=stat --avoid=stdarg --avoid=stdbool --avoid=threadlib --avoid=tzset --avoid=unsetenv --avoid=utime --avoid=utime-h --gnu-make --makefile-name=gnulib.mk.in --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt binary-io byteswap c-ctype c-strcase careadlinkat close-stream count-leading-zeros count-one-bits count-trailing-zeros crypto/md5-buffer crypto/sha1-buffer crypto/sha256-buffer crypto/sha512-buffer d-type diffseq dtoastr dtotimespec dup2 environ execinfo explicit_bzero faccessat fcntl fcntl-h fdatasync fdopendir filemode filevercmp flexmember fstatat fsusage fsync getloadavg getopt-gnu gettime gettimeofday gitlog-to-changelog ignore-value intprops largefile lstat manywarnings memrchr minmax mkostemp mktime nstrftime pipe2 pselect pthread_sigmask putenv qcopy-acl readlink readlinkat sig2str socklen stat-time std-gnu11 stdalign stddef stdio stpcpy strtoimax symlink sys_stat sys_time tempname time time_r time_rz timegm timer-time timespec-add timespec-sub unlocked-io update-copyright utimens vla warnings
MOSTLYCLEANFILES += core *.stackdump
@@ -387,6 +387,7 @@ HAVE_DECL_STRSIGNAL = @HAVE_DECL_STRSIGNAL@
HAVE_DECL_STRTOIMAX = @HAVE_DECL_STRTOIMAX@
HAVE_DECL_STRTOK_R = @HAVE_DECL_STRTOK_R@
HAVE_DECL_STRTOUMAX = @HAVE_DECL_STRTOUMAX@
+HAVE_DECL_TRUNCATE = @HAVE_DECL_TRUNCATE@
HAVE_DECL_TTYNAME_R = @HAVE_DECL_TTYNAME_R@
HAVE_DECL_UNSETENV = @HAVE_DECL_UNSETENV@
HAVE_DECL_VSNPRINTF = @HAVE_DECL_VSNPRINTF@
@@ -421,6 +422,7 @@ HAVE_GETSUBOPT = @HAVE_GETSUBOPT@
HAVE_GETTIMEOFDAY = @HAVE_GETTIMEOFDAY@
HAVE_GRANTPT = @HAVE_GRANTPT@
HAVE_GROUP_MEMBER = @HAVE_GROUP_MEMBER@
+HAVE_IMAXDIV_T = @HAVE_IMAXDIV_T@
HAVE_INTTYPES_H = @HAVE_INTTYPES_H@
HAVE_LCHMOD = @HAVE_LCHMOD@
HAVE_LCHOWN = @HAVE_LCHOWN@
@@ -513,7 +515,6 @@ HAVE_SYS_TIME_H = @HAVE_SYS_TIME_H@
HAVE_SYS_TYPES_H = @HAVE_SYS_TYPES_H@
HAVE_TIMEGM = @HAVE_TIMEGM@
HAVE_TIMEZONE_T = @HAVE_TIMEZONE_T@
-HAVE_TRUNCATE = @HAVE_TRUNCATE@
HAVE_TYPE_VOLATILE_SIG_ATOMIC_T = @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
HAVE_TZSET = @HAVE_TZSET@
HAVE_UNISTD_H = @HAVE_UNISTD_H@
@@ -1151,45 +1152,45 @@ EXTRA_DIST += count-trailing-zeros.h
endif
## end gnulib module count-trailing-zeros
-## begin gnulib module crypto/md5
-ifeq (,$(OMIT_GNULIB_MODULE_crypto/md5))
+## begin gnulib module crypto/md5-buffer
+ifeq (,$(OMIT_GNULIB_MODULE_crypto/md5-buffer))
libgnu_a_SOURCES += md5.c
EXTRA_DIST += gl_openssl.h md5.h
endif
-## end gnulib module crypto/md5
+## end gnulib module crypto/md5-buffer
-## begin gnulib module crypto/sha1
-ifeq (,$(OMIT_GNULIB_MODULE_crypto/sha1))
+## begin gnulib module crypto/sha1-buffer
+ifeq (,$(OMIT_GNULIB_MODULE_crypto/sha1-buffer))
libgnu_a_SOURCES += sha1.c
EXTRA_DIST += gl_openssl.h sha1.h
endif
-## end gnulib module crypto/sha1
+## end gnulib module crypto/sha1-buffer
-## begin gnulib module crypto/sha256
-ifeq (,$(OMIT_GNULIB_MODULE_crypto/sha256))
+## begin gnulib module crypto/sha256-buffer
+ifeq (,$(OMIT_GNULIB_MODULE_crypto/sha256-buffer))
libgnu_a_SOURCES += sha256.c
EXTRA_DIST += gl_openssl.h sha256.h
endif
-## end gnulib module crypto/sha256
+## end gnulib module crypto/sha256-buffer
-## begin gnulib module crypto/sha512
-ifeq (,$(OMIT_GNULIB_MODULE_crypto/sha512))
+## begin gnulib module crypto/sha512-buffer
+ifeq (,$(OMIT_GNULIB_MODULE_crypto/sha512-buffer))
libgnu_a_SOURCES += sha512.c
EXTRA_DIST += gl_openssl.h sha512.h
endif
-## end gnulib module crypto/sha512
+## end gnulib module crypto/sha512-buffer
## begin gnulib module diffseq
ifeq (,$(OMIT_GNULIB_MODULE_diffseq))
@@ -1717,6 +1718,7 @@ inttypes.h: inttypes.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_U
-e 's/@''HAVE_DECL_IMAXDIV''@/$(HAVE_DECL_IMAXDIV)/g' \
-e 's/@''HAVE_DECL_STRTOIMAX''@/$(HAVE_DECL_STRTOIMAX)/g' \
-e 's/@''HAVE_DECL_STRTOUMAX''@/$(HAVE_DECL_STRTOUMAX)/g' \
+ -e 's/@''HAVE_IMAXDIV_T''@/$(HAVE_IMAXDIV_T)/g' \
-e 's/@''REPLACE_STRTOIMAX''@/$(REPLACE_STRTOIMAX)/g' \
-e 's/@''REPLACE_STRTOUMAX''@/$(REPLACE_STRTOUMAX)/g' \
-e 's/@''INT32_MAX_LT_INTMAX_MAX''@/$(INT32_MAX_LT_INTMAX_MAX)/g' \
@@ -2984,7 +2986,6 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
-e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
-e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \
-e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \
- -e 's|@''HAVE_TRUNCATE''@|$(HAVE_TRUNCATE)|g' \
-e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \
-e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
-e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
@@ -2996,6 +2997,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
-e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
-e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \
-e 's|@''HAVE_DECL_SETHOSTNAME''@|$(HAVE_DECL_SETHOSTNAME)|g' \
+ -e 's|@''HAVE_DECL_TRUNCATE''@|$(HAVE_DECL_TRUNCATE)|g' \
-e 's|@''HAVE_DECL_TTYNAME_R''@|$(HAVE_DECL_TTYNAME_R)|g' \
-e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \
-e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \
diff --git a/lib/inttypes.in.h b/lib/inttypes.in.h
index ca3cec5b477..c7d7968e6e9 100644
--- a/lib/inttypes.in.h
+++ b/lib/inttypes.in.h
@@ -52,7 +52,7 @@
/* Get CHAR_BIT. */
#include <limits.h>
/* On mingw, __USE_MINGW_ANSI_STDIO only works if <stdio.h> is also included */
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
# include <stdio.h>
#endif
@@ -1067,11 +1067,13 @@ _GL_WARN_ON_USE (imaxabs, "imaxabs is unportable - "
#endif
#if @GNULIB_IMAXDIV@
-# if !@HAVE_DECL_IMAXDIV@
+# if !@HAVE_IMAXDIV_T@
# if !GNULIB_defined_imaxdiv_t
typedef struct { intmax_t quot; intmax_t rem; } imaxdiv_t;
# define GNULIB_defined_imaxdiv_t 1
# endif
+# endif
+# if !@HAVE_DECL_IMAXDIV@
extern imaxdiv_t imaxdiv (intmax_t, intmax_t);
# endif
#elif defined GNULIB_POSIXCHECK
diff --git a/lib/md5.c b/lib/md5.c
index 9dc915e2cf0..577aab46d7a 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -134,21 +134,29 @@ md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
}
#endif
+#if defined _LIBC || defined GL_COMPILE_CRYPTO_STREAM
+
+#include "af_alg.h"
+
/* Compute MD5 message digest for bytes read from STREAM. The
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
int
md5_stream (FILE *stream, void *resblock)
{
- struct md5_ctx ctx;
- size_t sum;
+ switch (afalg_stream (stream, "md5", resblock, MD5_DIGEST_SIZE))
+ {
+ case 0: return 0;
+ case -EIO: return 1;
+ }
char *buffer = malloc (BLOCKSIZE + 72);
if (!buffer)
return 1;
- /* Initialize the computation context. */
+ struct md5_ctx ctx;
md5_init_ctx (&ctx);
+ size_t sum;
/* Iterate over full file contents. */
while (1)
@@ -206,6 +214,7 @@ process_partial_block:
free (buffer);
return 0;
}
+#endif
#if ! HAVE_OPENSSL_MD5
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
diff --git a/lib/md5.h b/lib/md5.h
index d89f819a97b..db031aac04c 100644
--- a/lib/md5.h
+++ b/lib/md5.h
@@ -122,8 +122,11 @@ extern void *__md5_buffer (const char *buffer, size_t len,
void *resblock) __THROW;
# endif
-/* Compute MD5 message digest for bytes read from STREAM. The
- resulting message digest number will be written into the 16 bytes
+/* Compute MD5 message digest for bytes read from STREAM.
+ STREAM is an open file stream. Regular files are handled more efficiently.
+ The contents of STREAM from its current position to its end will be read.
+ The case that the last operation on STREAM was an 'ungetc' is not supported.
+ The resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
extern int __md5_stream (FILE *stream, void *resblock) __THROW;
diff --git a/lib/open.c b/lib/open.c
index b344f13a92a..792e258ba0b 100644
--- a/lib/open.c
+++ b/lib/open.c
@@ -86,7 +86,7 @@ open (const char *filename, int flags, ...)
flags &= ~O_NONBLOCK;
#endif
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
if (strcmp (filename, "/dev/null") == 0)
filename = "NUL";
#endif
diff --git a/lib/pipe2.c b/lib/pipe2.c
index 807ba6a9f9d..c16d9351ec8 100644
--- a/lib/pipe2.c
+++ b/lib/pipe2.c
@@ -29,7 +29,7 @@
# include "nonblocking.h"
#endif
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
/* Native Windows API. */
# include <io.h>
@@ -73,7 +73,7 @@ pipe2 (int fd[2], int flags)
return -1;
}
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
/* Native Windows API. */
if (_pipe (fd, 4096, flags & ~O_NONBLOCK) < 0)
@@ -152,8 +152,7 @@ pipe2 (int fd[2], int flags)
#endif
-#if GNULIB_defined_O_NONBLOCK || \
- !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+#if GNULIB_defined_O_NONBLOCK || !(defined _WIN32 && ! defined __CYGWIN__)
fail:
{
int saved_errno = errno;
diff --git a/lib/putenv.c b/lib/putenv.c
index 556d5f82302..801e372c329 100644
--- a/lib/putenv.c
+++ b/lib/putenv.c
@@ -34,7 +34,7 @@
#include <string.h>
#include <unistd.h>
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
@@ -153,7 +153,7 @@ putenv (char *string)
*ep = string;
break;
}
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# if defined _WIN32 && ! defined __CYGWIN__
if (putenv_result == 0)
{
/* _putenv propagated "NAME= " into the subprocess environment;
diff --git a/lib/sha1.c b/lib/sha1.c
index ce0f0b2e71f..8306d887da5 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -122,21 +122,29 @@ sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
}
#endif
+#ifdef GL_COMPILE_CRYPTO_STREAM
+
+#include "af_alg.h"
+
/* Compute SHA1 message digest for bytes read from STREAM. The
- resulting message digest number will be written into the 16 bytes
+ resulting message digest number will be written into the 20 bytes
beginning at RESBLOCK. */
int
sha1_stream (FILE *stream, void *resblock)
{
- struct sha1_ctx ctx;
- size_t sum;
+ switch (afalg_stream (stream, "sha1", resblock, SHA1_DIGEST_SIZE))
+ {
+ case 0: return 0;
+ case -EIO: return 1;
+ }
char *buffer = malloc (BLOCKSIZE + 72);
if (!buffer)
return 1;
- /* Initialize the computation context. */
+ struct sha1_ctx ctx;
sha1_init_ctx (&ctx);
+ size_t sum;
/* Iterate over full file contents. */
while (1)
@@ -194,6 +202,7 @@ sha1_stream (FILE *stream, void *resblock)
free (buffer);
return 0;
}
+#endif
#if ! HAVE_OPENSSL_SHA1
/* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
diff --git a/lib/sha1.h b/lib/sha1.h
index b1db15da1e7..9419750f485 100644
--- a/lib/sha1.h
+++ b/lib/sha1.h
@@ -87,8 +87,11 @@ extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
# endif
-/* Compute SHA1 message digest for bytes read from STREAM. The
- resulting message digest number will be written into the 20 bytes
+/* Compute SHA1 message digest for bytes read from STREAM.
+ STREAM is an open file stream. Regular files are handled more efficiently.
+ The contents of STREAM from its current position to its end will be read.
+ The case that the last operation on STREAM was an 'ungetc' is not supported.
+ The resulting message digest number will be written into the 20 bytes
beginning at RESBLOCK. */
extern int sha1_stream (FILE *stream, void *resblock);
diff --git a/lib/sha256.c b/lib/sha256.c
index 85405b20fdf..a036befcafd 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -91,17 +91,17 @@ sha224_init_ctx (struct sha256_ctx *ctx)
ctx->buflen = 0;
}
-/* Copy the value from v into the memory location pointed to by *cp,
- If your architecture allows unaligned access this is equivalent to
- * (uint32_t *) cp = v */
+/* Copy the value from v into the memory location pointed to by *CP,
+ If your architecture allows unaligned access, this is equivalent to
+ * (__typeof__ (v) *) cp = v */
static void
set_uint32 (char *cp, uint32_t v)
{
memcpy (cp, &v, sizeof v);
}
-/* Put result from CTX in first 32 bytes following RESBUF. The result
- must be in little endian byte order. */
+/* Put result from CTX in first 32 bytes following RESBUF.
+ The result must be in little endian byte order. */
void *
sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf)
{
@@ -169,21 +169,32 @@ sha224_finish_ctx (struct sha256_ctx *ctx, void *resbuf)
}
#endif
-/* Compute SHA256 message digest for bytes read from STREAM. The
- resulting message digest number will be written into the 32 bytes
- beginning at RESBLOCK. */
-int
-sha256_stream (FILE *stream, void *resblock)
+#ifdef GL_COMPILE_CRYPTO_STREAM
+
+#include "af_alg.h"
+
+/* Compute message digest for bytes read from STREAM using algorithm ALG.
+ Write the message digest into RESBLOCK, which contains HASHLEN bytes.
+ The initial and finishing operations are INIT_CTX and FINISH_CTX.
+ Return zero if and only if successful. */
+static int
+shaxxx_stream (FILE *stream, char const *alg, void *resblock,
+ ssize_t hashlen, void (*init_ctx) (struct sha256_ctx *),
+ void *(*finish_ctx) (struct sha256_ctx *, void *))
{
- struct sha256_ctx ctx;
- size_t sum;
+ switch (afalg_stream (stream, alg, resblock, hashlen))
+ {
+ case 0: return 0;
+ case -EIO: return 1;
+ }
char *buffer = malloc (BLOCKSIZE + 72);
if (!buffer)
return 1;
- /* Initialize the computation context. */
- sha256_init_ctx (&ctx);
+ struct sha256_ctx ctx;
+ init_ctx (&ctx);
+ size_t sum;
/* Iterate over full file contents. */
while (1)
@@ -237,84 +248,28 @@ sha256_stream (FILE *stream, void *resblock)
sha256_process_bytes (buffer, sum, &ctx);
/* Construct result in desired memory. */
- sha256_finish_ctx (&ctx, resblock);
+ finish_ctx (&ctx, resblock);
free (buffer);
return 0;
}
-/* FIXME: Avoid code duplication */
int
-sha224_stream (FILE *stream, void *resblock)
+sha256_stream (FILE *stream, void *resblock)
{
- struct sha256_ctx ctx;
- size_t sum;
-
- char *buffer = malloc (BLOCKSIZE + 72);
- if (!buffer)
- return 1;
-
- /* Initialize the computation context. */
- sha224_init_ctx (&ctx);
-
- /* Iterate over full file contents. */
- while (1)
- {
- /* We read the file in blocks of BLOCKSIZE bytes. One call of the
- computation function processes the whole buffer so that with the
- next round of the loop another block can be read. */
- size_t n;
- sum = 0;
-
- /* Read block. Take care for partial reads. */
- while (1)
- {
- n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
-
- sum += n;
-
- if (sum == BLOCKSIZE)
- break;
-
- if (n == 0)
- {
- /* Check for the error flag IFF N == 0, so that we don't
- exit the loop after a partial read due to e.g., EAGAIN
- or EWOULDBLOCK. */
- if (ferror (stream))
- {
- free (buffer);
- return 1;
- }
- goto process_partial_block;
- }
-
- /* We've read at least one byte, so ignore errors. But always
- check for EOF, since feof may be true even though N > 0.
- Otherwise, we could end up calling fread after EOF. */
- if (feof (stream))
- goto process_partial_block;
- }
-
- /* Process buffer with BLOCKSIZE bytes. Note that
- BLOCKSIZE % 64 == 0
- */
- sha256_process_block (buffer, BLOCKSIZE, &ctx);
- }
-
- process_partial_block:;
-
- /* Process any remaining bytes. */
- if (sum > 0)
- sha256_process_bytes (buffer, sum, &ctx);
+ return shaxxx_stream (stream, "sha256", resblock, SHA256_DIGEST_SIZE,
+ sha256_init_ctx, sha256_finish_ctx);
+}
- /* Construct result in desired memory. */
- sha224_finish_ctx (&ctx, resblock);
- free (buffer);
- return 0;
+int
+sha224_stream (FILE *stream, void *resblock)
+{
+ return shaxxx_stream (stream, "sha224", resblock, SHA224_DIGEST_SIZE,
+ sha224_init_ctx, sha224_finish_ctx);
}
+#endif
#if ! HAVE_OPENSSL_SHA256
-/* Compute SHA512 message digest for LEN bytes beginning at BUFFER. The
+/* Compute SHA256 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
diff --git a/lib/sha256.h b/lib/sha256.h
index e3449864bb6..19ed3ccd4d0 100644
--- a/lib/sha256.h
+++ b/lib/sha256.h
@@ -89,8 +89,11 @@ extern void *sha256_buffer (const char *buffer, size_t len, void *resblock);
extern void *sha224_buffer (const char *buffer, size_t len, void *resblock);
# endif
-/* Compute SHA256 (SHA224) message digest for bytes read from STREAM. The
- resulting message digest number will be written into the 32 (28) bytes
+/* Compute SHA256 (SHA224) message digest for bytes read from STREAM.
+ STREAM is an open file stream. Regular files are handled more efficiently.
+ The contents of STREAM from its current position to its end will be read.
+ The case that the last operation on STREAM was an 'ungetc' is not supported.
+ The resulting message digest number will be written into the 32 (28) bytes
beginning at RESBLOCK. */
extern int sha256_stream (FILE *stream, void *resblock);
extern int sha224_stream (FILE *stream, void *resblock);
diff --git a/lib/sha512.c b/lib/sha512.c
index 8a6dd4e83ac..e175e705f52 100644
--- a/lib/sha512.c
+++ b/lib/sha512.c
@@ -177,21 +177,32 @@ sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf)
}
#endif
-/* Compute SHA512 message digest for bytes read from STREAM. The
- resulting message digest number will be written into the 64 bytes
- beginning at RESBLOCK. */
-int
-sha512_stream (FILE *stream, void *resblock)
+#ifdef GL_COMPILE_CRYPTO_STREAM
+
+#include "af_alg.h"
+
+/* Compute message digest for bytes read from STREAM using algorithm ALG.
+ Write the message digest into RESBLOCK, which contains HASHLEN bytes.
+ The initial and finishing operations are INIT_CTX and FINISH_CTX.
+ Return zero if and only if successful. */
+static int
+shaxxx_stream (FILE *stream, char const *alg, void *resblock,
+ ssize_t hashlen, void (*init_ctx) (struct sha512_ctx *),
+ void *(*finish_ctx) (struct sha512_ctx *, void *))
{
- struct sha512_ctx ctx;
- size_t sum;
+ switch (afalg_stream (stream, alg, resblock, hashlen))
+ {
+ case 0: return 0;
+ case -EIO: return 1;
+ }
char *buffer = malloc (BLOCKSIZE + 72);
if (!buffer)
return 1;
- /* Initialize the computation context. */
- sha512_init_ctx (&ctx);
+ struct sha512_ctx ctx;
+ init_ctx (&ctx);
+ size_t sum;
/* Iterate over full file contents. */
while (1)
@@ -245,81 +256,25 @@ sha512_stream (FILE *stream, void *resblock)
sha512_process_bytes (buffer, sum, &ctx);
/* Construct result in desired memory. */
- sha512_finish_ctx (&ctx, resblock);
+ finish_ctx (&ctx, resblock);
free (buffer);
return 0;
}
-/* FIXME: Avoid code duplication */
int
-sha384_stream (FILE *stream, void *resblock)
+sha512_stream (FILE *stream, void *resblock)
{
- struct sha512_ctx ctx;
- size_t sum;
-
- char *buffer = malloc (BLOCKSIZE + 72);
- if (!buffer)
- return 1;
-
- /* Initialize the computation context. */
- sha384_init_ctx (&ctx);
-
- /* Iterate over full file contents. */
- while (1)
- {
- /* We read the file in blocks of BLOCKSIZE bytes. One call of the
- computation function processes the whole buffer so that with the
- next round of the loop another block can be read. */
- size_t n;
- sum = 0;
-
- /* Read block. Take care for partial reads. */
- while (1)
- {
- n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
-
- sum += n;
-
- if (sum == BLOCKSIZE)
- break;
-
- if (n == 0)
- {
- /* Check for the error flag IFF N == 0, so that we don't
- exit the loop after a partial read due to e.g., EAGAIN
- or EWOULDBLOCK. */
- if (ferror (stream))
- {
- free (buffer);
- return 1;
- }
- goto process_partial_block;
- }
-
- /* We've read at least one byte, so ignore errors. But always
- check for EOF, since feof may be true even though N > 0.
- Otherwise, we could end up calling fread after EOF. */
- if (feof (stream))
- goto process_partial_block;
- }
-
- /* Process buffer with BLOCKSIZE bytes. Note that
- BLOCKSIZE % 128 == 0
- */
- sha512_process_block (buffer, BLOCKSIZE, &ctx);
- }
-
- process_partial_block:;
-
- /* Process any remaining bytes. */
- if (sum > 0)
- sha512_process_bytes (buffer, sum, &ctx);
+ return shaxxx_stream (stream, "sha512", resblock, SHA512_DIGEST_SIZE,
+ sha512_init_ctx, sha512_finish_ctx);
+}
- /* Construct result in desired memory. */
- sha384_finish_ctx (&ctx, resblock);
- free (buffer);
- return 0;
+int
+sha384_stream (FILE *stream, void *resblock)
+{
+ return shaxxx_stream (stream, "sha384", resblock, SHA384_DIGEST_SIZE,
+ sha384_init_ctx, sha384_finish_ctx);
}
+#endif
#if ! HAVE_OPENSSL_SHA512
/* Compute SHA512 message digest for LEN bytes beginning at BUFFER. The
diff --git a/lib/sha512.h b/lib/sha512.h
index 6a0aadba02f..2c39ab195cf 100644
--- a/lib/sha512.h
+++ b/lib/sha512.h
@@ -92,8 +92,11 @@ extern void *sha512_buffer (const char *buffer, size_t len, void *resblock);
extern void *sha384_buffer (const char *buffer, size_t len, void *resblock);
# endif
-/* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The
- resulting message digest number will be written into the 64 (48) bytes
+/* Compute SHA512 (SHA384) message digest for bytes read from STREAM.
+ STREAM is an open file stream. Regular files are handled more efficiently.
+ The contents of STREAM from its current position to its end will be read.
+ The case that the last operation on STREAM was an 'ungetc' is not supported.
+ The resulting message digest number will be written into the 64 (48) bytes
beginning at RESBLOCK. */
extern int sha512_stream (FILE *stream, void *resblock);
extern int sha384_stream (FILE *stream, void *resblock);
diff --git a/lib/stat-time.h b/lib/stat-time.h
index 104f5376682..8e787bd3b2d 100644
--- a/lib/stat-time.h
+++ b/lib/stat-time.h
@@ -168,7 +168,7 @@ get_stat_birthtime (struct stat const *st _GL_UNUSED)
#elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
t.tv_sec = st->st_birthtime;
t.tv_nsec = st->st_birthtimensec;
-#elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#elif defined _WIN32 && ! defined __CYGWIN__
/* Native Windows platforms (but not Cygwin) put the "file creation
time" in st_ctime (!). See
<https://msdn.microsoft.com/en-us/library/14h5k7ff(VS.80).aspx>. */
diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h
index 05c5752a243..393ef0cf58d 100644
--- a/lib/stdio-impl.h
+++ b/lib/stdio-impl.h
@@ -60,25 +60,79 @@
# define _flags pub._flags
# define _r pub._r
# define _w pub._w
+# elif defined __ANDROID__ /* Android */
+ /* Up to this commit from 2015-10-12
+ <https://android.googlesource.com/platform/bionic.git/+/f0141dfab10a4b332769d52fa76631a64741297a>
+ the innards of FILE were public, and fp_ub could be defined like for OpenBSD,
+ see <https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/fileext.h>
+ and <https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/local.h>.
+ After this commit, the innards of FILE are hidden. */
+# define fp_ ((struct { unsigned char *_p; \
+ int _r; \
+ int _w; \
+ int _flags; \
+ int _file; \
+ struct { unsigned char *_base; size_t _size; } _bf; \
+ int _lbfsize; \
+ void *_cookie; \
+ void *_close; \
+ void *_read; \
+ void *_seek; \
+ void *_write; \
+ struct { unsigned char *_base; size_t _size; } _ext; \
+ unsigned char *_up; \
+ int _ur; \
+ unsigned char _ubuf[3]; \
+ unsigned char _nbuf[1]; \
+ struct { unsigned char *_base; size_t _size; } _lb; \
+ int _blksize; \
+ fpos_t _offset; \
+ /* More fields, not relevant here. */ \
+ } *) fp)
# else
# define fp_ fp
# endif
-# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __minix || defined __ANDROID__ /* NetBSD >= 1.5ZA, OpenBSD, Minix 3, Android */
+# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __minix /* NetBSD >= 1.5ZA, OpenBSD, Minix 3 */
/* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
- and <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
+ and <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
+ and <https://github.com/Stichting-MINIX-Research-Foundation/minix/blob/master/lib/libc/stdio/fileext.h> */
struct __sfileext
{
struct __sbuf _ub; /* ungetc buffer */
/* More fields, not relevant here. */
};
# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
-# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin, Android */
+# elif defined __ANDROID__ /* Android */
+ struct __sfileext
+ {
+ struct { unsigned char *_base; size_t _size; } _ub; /* ungetc buffer */
+ /* More fields, not relevant here. */
+ };
+# define fp_ub ((struct __sfileext *) fp_->_ext._base)->_ub
+# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */
# define fp_ub fp_->_ub
# endif
# define HASUB(fp) (fp_ub._base != NULL)
+# if defined __ANDROID__ /* Android */
+ /* Needed after this commit from 2016-01-25
+ <https://android.googlesource.com/platform/bionic.git/+/e70e0e9267d069bf56a5078c99307e08a7280de7> */
+# ifndef __SEOF
+# define __SLBF 1
+# define __SNBF 2
+# define __SRD 4
+# define __SWR 8
+# define __SRW 0x10
+# define __SEOF 0x20
+# define __SERR 0x40
+# endif
+# ifndef __SOFF
+# define __SOFF 0x1000
+# endif
+# endif
+
#endif
@@ -118,7 +172,7 @@
# define _flag __flag
# endif
-#elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* newer Windows with MSVC */
+#elif defined _WIN32 && ! defined __CYGWIN__ /* newer Windows with MSVC */
/* <stdio.h> does not define the innards of FILE any more. */
# define WINDOWS_OPAQUE_FILE
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index b9a43bb80ca..ff7c9c831ac 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -122,7 +122,7 @@
it before we #define perror rpl_perror. */
/* But in any case avoid namespace pollution on glibc systems. */
#if (@GNULIB_PERROR@ || defined GNULIB_POSIXCHECK) \
- && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) \
+ && (defined _WIN32 && ! defined __CYGWIN__) \
&& ! defined __GLIBC__
# include <stdlib.h>
#endif
@@ -133,7 +133,7 @@
it before we #define rename rpl_rename. */
/* But in any case avoid namespace pollution on glibc systems. */
#if (@GNULIB_REMOVE@ || @GNULIB_RENAME@ || defined GNULIB_POSIXCHECK) \
- && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) \
+ && (defined _WIN32 && ! defined __CYGWIN__) \
&& ! defined __GLIBC__
# include <io.h>
#endif
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index c8a5d0d0c61..3bf35bf6b0f 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -54,7 +54,7 @@
#endif
/* Native Windows platforms declare mktemp() in <io.h>. */
-#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+#if 0 && (defined _WIN32 && ! defined __CYGWIN__)
# include <io.h>
#endif
@@ -90,7 +90,7 @@ struct random_data
# endif
#endif
-#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !(defined _WIN32 && ! defined __CYGWIN__)
/* On Mac OS X 10.3, only <unistd.h> declares mkstemp. */
/* On Mac OS X 10.5, only <unistd.h> declares mkstemps. */
/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */
diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h
index d96fde1007d..6ae6ac5fbdc 100644
--- a/lib/sys_stat.in.h
+++ b/lib/sys_stat.in.h
@@ -57,13 +57,13 @@
/* Before doing "#define mkdir rpl_mkdir" below, we need to include all
headers that may declare mkdir(). Native Windows platforms declare mkdir
in <io.h> and/or <direct.h>, not in <unistd.h>. */
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
# include <io.h> /* mingw32, mingw64 */
# include <direct.h> /* mingw64, MSVC 9 */
#endif
/* Native Windows platforms declare umask() in <io.h>. */
-#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+#if 0 && (defined _WIN32 && ! defined __CYGWIN__)
# include <io.h>
#endif
@@ -576,7 +576,7 @@ _GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
Additionally, it declares _mkdir (and depending on compile flags, an
alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
which are included above. */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# if defined _WIN32 && ! defined __CYGWIN__
# if !GNULIB_defined_rpl_mkdir
static int
diff --git a/lib/sys_types.in.h b/lib/sys_types.in.h
index 747371644df..7f8c1c42117 100644
--- a/lib/sys_types.in.h
+++ b/lib/sys_types.in.h
@@ -20,6 +20,17 @@
#endif
@PRAGMA_COLUMNS@
+#if defined _WIN32 && !defined __CYGWIN__ \
+ && (defined __need_off_t || defined __need___off64_t \
+ || defined __need_ssize_t || defined __need_time_t)
+
+/* Special invocation convention inside mingw header files. */
+
+#@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@
+
+#else
+/* Normal invocation convention. */
+
#ifndef _@GUARD_PREFIX@_SYS_TYPES_H
/* The include_next requires a split double-inclusion guard. */
@@ -86,10 +97,10 @@ typedef unsigned long long int rpl_ino_t;
/* MSVC 9 defines size_t in <stddef.h>, not in <sys/types.h>. */
/* But avoid namespace pollution on glibc systems. */
-#if ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) \
- && ! defined __GLIBC__
+#if (defined _WIN32 && ! defined __CYGWIN__) && ! defined __GLIBC__
# include <stddef.h>
#endif
#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */
#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */
+#endif /* __need_XXX */
diff --git a/lib/timespec.h b/lib/timespec.h
index eef3030d9c5..94ba8d0b6a0 100644
--- a/lib/timespec.h
+++ b/lib/timespec.h
@@ -87,7 +87,7 @@ timespec_cmp (struct timespec a, struct timespec b)
return 1;
/* Pacify gcc -Wstrict-overflow (bleeding-edge circa 2017-10-02). See:
- http://lists.gnu.org/r/bug-gnulib/2017-10/msg00006.html */
+ https://lists.gnu.org/r/bug-gnulib/2017-10/msg00006.html */
assume (-1 <= a.tv_nsec && a.tv_nsec <= 2 * TIMESPEC_RESOLUTION);
assume (-1 <= b.tv_nsec && b.tv_nsec <= 2 * TIMESPEC_RESOLUTION);
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index beeb8e1d6fd..b6a348f5297 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -61,7 +61,7 @@
/* But avoid namespace pollution on glibc systems. */
#if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
|| ((@GNULIB_UNLINK@ || defined GNULIB_POSIXCHECK) \
- && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) \
+ && (defined _WIN32 && ! defined __CYGWIN__)) \
|| ((@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK) \
&& defined __CYGWIN__)) \
&& ! defined __GLIBC__
@@ -94,13 +94,13 @@
lseek(), read(), unlink(), write() in <io.h>. */
#if ((@GNULIB_CHDIR@ || @GNULIB_GETCWD@ || @GNULIB_RMDIR@ \
|| defined GNULIB_POSIXCHECK) \
- && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
+ && (defined _WIN32 && ! defined __CYGWIN__))
# include <io.h> /* mingw32, mingw64 */
# include <direct.h> /* mingw64, MSVC 9 */
#elif (@GNULIB_CLOSE@ || @GNULIB_DUP@ || @GNULIB_DUP2@ || @GNULIB_ISATTY@ \
|| @GNULIB_LSEEK@ || @GNULIB_READ@ || @GNULIB_UNLINK@ || @GNULIB_WRITE@ \
|| defined GNULIB_POSIXCHECK) \
- && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+ && (defined _WIN32 && ! defined __CYGWIN__)
# include <io.h>
#endif
@@ -1489,7 +1489,7 @@ _GL_FUNCDECL_RPL (truncate, int, (const char *filename, off_t length)
_GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (truncate, int, (const char *filename, off_t length));
# else
-# if !@HAVE_TRUNCATE@
+# if !@HAVE_DECL_TRUNCATE@
_GL_FUNCDECL_SYS (truncate, int, (const char *filename, off_t length)
_GL_ARG_NONNULL ((1)));
# endif
diff --git a/lib/utimens.c b/lib/utimens.c
index c0b0704eb29..e65f55d82fe 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -39,8 +39,7 @@
GNU Emacs, which arranges for this in some other way and which
defines WIN32_LEAN_AND_MEAN itself. */
-#if ((defined _WIN32 || defined __WIN32__) \
- && ! defined __CYGWIN__ && ! defined EMACS_CONFIGURATION)
+#if defined _WIN32 && ! defined __CYGWIN__ && ! defined EMACS_CONFIGURATION
# define USE_SETFILETIME
# define WIN32_LEAN_AND_MEAN
# include <windows.h>