public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gnulib: import nonblocking module
@ 2021-09-09  6:38 Mike Frysinger
  2021-09-09  6:38 ` [PATCH 2/2] sim: use gnulib to set nonblocking mode Mike Frysinger
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2021-09-09  6:38 UTC (permalink / raw)
  To: gdb-patches

This provides a portable API for managing O_NONBLOCK settings.
The sim will use this to replace its own incomplete shims.
---
 gnulib/Makefile.in                 |  12 +
 gnulib/aclocal.m4                  |   4 +
 gnulib/config.in                   |  20 ++
 gnulib/configure                   | 390 +++++++++++++++++++++++++++++
 gnulib/import/Makefile.am          |  52 ++++
 gnulib/import/Makefile.in          | 137 ++++++----
 gnulib/import/ioctl.c              |  92 +++++++
 gnulib/import/m4/asm-underscore.m4 |  83 ++++++
 gnulib/import/m4/gnulib-cache.m4   |   2 +
 gnulib/import/m4/gnulib-comp.m4    |  31 +++
 gnulib/import/m4/ioctl.m4          |  44 ++++
 gnulib/import/m4/nonblocking.m4    |  29 +++
 gnulib/import/m4/sys_ioctl_h.m4    |  64 +++++
 gnulib/import/nonblocking.c        | 163 ++++++++++++
 gnulib/import/nonblocking.h        |  62 +++++
 gnulib/import/stdio-read.c         | 168 +++++++++++++
 gnulib/import/stdio-write.c        | 206 +++++++++++++++
 gnulib/import/sys_ioctl.in.h       |  79 ++++++
 gnulib/update-gnulib.sh            |   1 +
 19 files changed, 1592 insertions(+), 47 deletions(-)
 create mode 100644 gnulib/import/ioctl.c
 create mode 100644 gnulib/import/m4/asm-underscore.m4
 create mode 100644 gnulib/import/m4/ioctl.m4
 create mode 100644 gnulib/import/m4/nonblocking.m4
 create mode 100644 gnulib/import/m4/sys_ioctl_h.m4
 create mode 100644 gnulib/import/nonblocking.c
 create mode 100644 gnulib/import/nonblocking.h
 create mode 100644 gnulib/import/stdio-read.c
 create mode 100644 gnulib/import/stdio-write.c
 create mode 100644 gnulib/import/sys_ioctl.in.h

diff --git a/gnulib/Makefile.in b/gnulib/Makefile.in
index af264c3c12de..4868d7253760 100644
--- a/gnulib/Makefile.in
+++ b/gnulib/Makefile.in
@@ -117,6 +117,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/absolute-header.m4 \
 	$(top_srcdir)/import/m4/alloca.m4 \
 	$(top_srcdir)/import/m4/arpa_inet_h.m4 \
+	$(top_srcdir)/import/m4/asm-underscore.m4 \
 	$(top_srcdir)/import/m4/btowc.m4 \
 	$(top_srcdir)/import/m4/builtin-expect.m4 \
 	$(top_srcdir)/import/m4/canonicalize.m4 \
@@ -177,6 +178,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/include_next.m4 \
 	$(top_srcdir)/import/m4/inet_ntop.m4 \
 	$(top_srcdir)/import/m4/inttypes.m4 \
+	$(top_srcdir)/import/m4/ioctl.m4 \
 	$(top_srcdir)/import/m4/isblank.m4 \
 	$(top_srcdir)/import/m4/isnand.m4 \
 	$(top_srcdir)/import/m4/isnanl.m4 \
@@ -213,6 +215,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/netdb_h.m4 \
 	$(top_srcdir)/import/m4/netinet_in_h.m4 \
 	$(top_srcdir)/import/m4/nocrash.m4 \
+	$(top_srcdir)/import/m4/nonblocking.m4 \
 	$(top_srcdir)/import/m4/off_t.m4 \
 	$(top_srcdir)/import/m4/open-cloexec.m4 \
 	$(top_srcdir)/import/m4/open-slash.m4 \
@@ -258,6 +261,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/strnlen.m4 \
 	$(top_srcdir)/import/m4/strstr.m4 \
 	$(top_srcdir)/import/m4/strtok_r.m4 \
+	$(top_srcdir)/import/m4/sys_ioctl_h.m4 \
 	$(top_srcdir)/import/m4/sys_random_h.m4 \
 	$(top_srcdir)/import/m4/sys_select_h.m4 \
 	$(top_srcdir)/import/m4/sys_socket_h.m4 \
@@ -355,6 +359,7 @@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
 APPLE_UNIVERSAL_BUILD = @APPLE_UNIVERSAL_BUILD@
 AR = @AR@
 ARFLAGS = @ARFLAGS@
+ASM_SYMBOL_PREFIX = @ASM_SYMBOL_PREFIX@
 AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
@@ -539,6 +544,7 @@ GNULIB_IMAXABS = @GNULIB_IMAXABS@
 GNULIB_IMAXDIV = @GNULIB_IMAXDIV@
 GNULIB_INET_NTOP = @GNULIB_INET_NTOP@
 GNULIB_INET_PTON = @GNULIB_INET_PTON@
+GNULIB_IOCTL = @GNULIB_IOCTL@
 GNULIB_ISATTY = @GNULIB_ISATTY@
 GNULIB_ISBLANK = @GNULIB_ISBLANK@
 GNULIB_ISFINITE = @GNULIB_ISFINITE@
@@ -1167,6 +1173,7 @@ HAVE_SYMLINK = @HAVE_SYMLINK@
 HAVE_SYMLINKAT = @HAVE_SYMLINKAT@
 HAVE_SYS_BITYPES_H = @HAVE_SYS_BITYPES_H@
 HAVE_SYS_INTTYPES_H = @HAVE_SYS_INTTYPES_H@
+HAVE_SYS_IOCTL_H = @HAVE_SYS_IOCTL_H@
 HAVE_SYS_LOADAVG_H = @HAVE_SYS_LOADAVG_H@
 HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@
 HAVE_SYS_RANDOM_H = @HAVE_SYS_RANDOM_H@
@@ -1302,6 +1309,7 @@ NEXT_AS_FIRST_DIRECTIVE_STDIO_H = @NEXT_AS_FIRST_DIRECTIVE_STDIO_H@
 NEXT_AS_FIRST_DIRECTIVE_STDLIB_H = @NEXT_AS_FIRST_DIRECTIVE_STDLIB_H@
 NEXT_AS_FIRST_DIRECTIVE_STRINGS_H = @NEXT_AS_FIRST_DIRECTIVE_STRINGS_H@
 NEXT_AS_FIRST_DIRECTIVE_STRING_H = @NEXT_AS_FIRST_DIRECTIVE_STRING_H@
+NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H@
@@ -1334,6 +1342,7 @@ NEXT_STDIO_H = @NEXT_STDIO_H@
 NEXT_STDLIB_H = @NEXT_STDLIB_H@
 NEXT_STRINGS_H = @NEXT_STRINGS_H@
 NEXT_STRING_H = @NEXT_STRING_H@
+NEXT_SYS_IOCTL_H = @NEXT_SYS_IOCTL_H@
 NEXT_SYS_RANDOM_H = @NEXT_SYS_RANDOM_H@
 NEXT_SYS_SELECT_H = @NEXT_SYS_SELECT_H@
 NEXT_SYS_SOCKET_H = @NEXT_SYS_SOCKET_H@
@@ -1464,6 +1473,7 @@ REPLACE_ILOGBL = @REPLACE_ILOGBL@
 REPLACE_INET_NTOP = @REPLACE_INET_NTOP@
 REPLACE_INET_PTON = @REPLACE_INET_PTON@
 REPLACE_INITSTATE = @REPLACE_INITSTATE@
+REPLACE_IOCTL = @REPLACE_IOCTL@
 REPLACE_ISATTY = @REPLACE_ISATTY@
 REPLACE_ISFINITE = @REPLACE_ISFINITE@
 REPLACE_ISINF = @REPLACE_ISINF@
@@ -1635,6 +1645,8 @@ STDBOOL_H = @STDBOOL_H@
 STDDEF_H = @STDDEF_H@
 STDINT_H = @STDINT_H@
 STRIP = @STRIP@
+SYS_IOCTL_H_HAVE_WINSOCK2_H = @SYS_IOCTL_H_HAVE_WINSOCK2_H@
+SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS = @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC = @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
 TIME_H_DEFINES_STRUCT_TIMESPEC = @TIME_H_DEFINES_STRUCT_TIMESPEC@
 TIME_H_DEFINES_TIME_UTC = @TIME_H_DEFINES_TIME_UTC@
diff --git a/gnulib/aclocal.m4 b/gnulib/aclocal.m4
index c03dc8bcafa7..bc3a30278b5d 100644
--- a/gnulib/aclocal.m4
+++ b/gnulib/aclocal.m4
@@ -1189,6 +1189,7 @@ m4_include([import/m4/__inline.m4])
 m4_include([import/m4/absolute-header.m4])
 m4_include([import/m4/alloca.m4])
 m4_include([import/m4/arpa_inet_h.m4])
+m4_include([import/m4/asm-underscore.m4])
 m4_include([import/m4/btowc.m4])
 m4_include([import/m4/builtin-expect.m4])
 m4_include([import/m4/canonicalize.m4])
@@ -1250,6 +1251,7 @@ m4_include([import/m4/gnulib-comp.m4])
 m4_include([import/m4/include_next.m4])
 m4_include([import/m4/inet_ntop.m4])
 m4_include([import/m4/inttypes.m4])
+m4_include([import/m4/ioctl.m4])
 m4_include([import/m4/isblank.m4])
 m4_include([import/m4/isnand.m4])
 m4_include([import/m4/isnanl.m4])
@@ -1286,6 +1288,7 @@ m4_include([import/m4/multiarch.m4])
 m4_include([import/m4/netdb_h.m4])
 m4_include([import/m4/netinet_in_h.m4])
 m4_include([import/m4/nocrash.m4])
+m4_include([import/m4/nonblocking.m4])
 m4_include([import/m4/off_t.m4])
 m4_include([import/m4/open-cloexec.m4])
 m4_include([import/m4/open-slash.m4])
@@ -1331,6 +1334,7 @@ m4_include([import/m4/strings_h.m4])
 m4_include([import/m4/strnlen.m4])
 m4_include([import/m4/strstr.m4])
 m4_include([import/m4/strtok_r.m4])
+m4_include([import/m4/sys_ioctl_h.m4])
 m4_include([import/m4/sys_random_h.m4])
 m4_include([import/m4/sys_select_h.m4])
 m4_include([import/m4/sys_socket_h.m4])
diff --git a/gnulib/config.in b/gnulib/config.in
index dd960bf6e0b6..5863675b8ec7 100644
--- a/gnulib/config.in
+++ b/gnulib/config.in
@@ -119,6 +119,10 @@
    whether the gnulib module msvc-nothrow shall be considered present. */
 #undef GNULIB_MSVC_NOTHROW
 
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+   whether the gnulib module nonblocking shall be considered present. */
+#undef GNULIB_NONBLOCKING
+
 /* Define to a C preprocessor expression that evaluates to 1 or 0, depending
    whether the gnulib module openat shall be considered present. */
 #undef GNULIB_OPENAT
@@ -237,6 +241,9 @@
 /* Define to 1 when the gnulib module glob should be tested. */
 #undef GNULIB_TEST_GLOB
 
+/* Define to 1 when the gnulib module ioctl should be tested. */
+#undef GNULIB_TEST_IOCTL
+
 /* Define to 1 when the gnulib module listen should be tested. */
 #undef GNULIB_TEST_LISTEN
 
@@ -279,6 +286,9 @@
 /* Define to 1 when the gnulib module mkostemp should be tested. */
 #undef GNULIB_TEST_MKOSTEMP
 
+/* Define to 1 when the gnulib module nonblocking should be tested. */
+#undef GNULIB_TEST_NONBLOCKING
+
 /* Define to 1 when the gnulib module open should be tested. */
 #undef GNULIB_TEST_OPEN
 
@@ -643,6 +653,9 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
+/* Define to 1 if you have the `ioctl' function. */
+#undef HAVE_IOCTL
+
 /* Define to 1 if <sys/socket.h> defines AF_INET. */
 #undef HAVE_IPV4
 
@@ -892,6 +905,9 @@
 /* Define to 1 if you have the <sys/inttypes.h> header file. */
 #undef HAVE_SYS_INTTYPES_H
 
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#undef HAVE_SYS_IOCTL_H
+
 /* Define to 1 if you have the <sys/mman.h> header file. */
 #undef HAVE_SYS_MMAN_H
 
@@ -1167,6 +1183,10 @@
    timespec. */
 #undef TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC
 
+/* Define to the prefix of C symbols at the assembler and linker level, either
+   an underscore or empty. */
+#undef USER_LABEL_PREFIX
+
 /* Define if the combination of the ISO C and POSIX multithreading APIs can be
    used. */
 #undef USE_ISOC_AND_POSIX_THREADS
diff --git a/gnulib/configure b/gnulib/configure
index 39555afe9f01..54e1f19115f1 100644
--- a/gnulib/configure
+++ b/gnulib/configure
@@ -745,6 +745,9 @@ NEXT_SYS_TYPES_H
 HAVE_SYS_RANDOM_H
 NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H
 NEXT_SYS_RANDOM_H
+NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H
+NEXT_SYS_IOCTL_H
+HAVE_SYS_IOCTL_H
 HAVE_STRINGS_H
 NEXT_AS_FIRST_DIRECTIVE_STRINGS_H
 NEXT_STRINGS_H
@@ -789,6 +792,7 @@ REPLACE_PSELECT
 HAVE_PSELECT
 GNULIB_SELECT
 GNULIB_PSELECT
+ASM_SYMBOL_PREFIX
 GL_GENERATE_NETINET_IN_H_FALSE
 GL_GENERATE_NETINET_IN_H_TRUE
 NETINET_IN_H
@@ -1745,6 +1749,10 @@ GL_GENERATE_ALLOCA_H_TRUE
 ALLOCA_H
 ALLOCA
 HAVE_WINSOCK2_H
+REPLACE_IOCTL
+SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS
+SYS_IOCTL_H_HAVE_WINSOCK2_H
+GNULIB_IOCTL
 UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS
 UNISTD_H_HAVE_WINSOCK2_H
 UNISTD_H_HAVE_SYS_RANDOM_H
@@ -3803,6 +3811,7 @@ as_fn_append ac_func_list " __xpg_strerror_r"
 as_fn_append ac_func_list " catgets"
 as_fn_append ac_func_list " snprintf"
 as_fn_append ac_header_list " strings.h"
+as_fn_append ac_header_list " sys/ioctl.h"
 as_fn_append ac_header_list " sys/random.h"
 as_fn_append ac_header_list " sys/uio.h"
 as_fn_append ac_header_list " sys/wait.h"
@@ -6781,6 +6790,7 @@ fi
   # Code from module intprops:
   # Code from module inttypes:
   # Code from module inttypes-incomplete:
+  # Code from module ioctl:
   # Code from module isblank:
   # Code from module isnand-nolibm:
   # Code from module isnanl-nolibm:
@@ -6815,6 +6825,7 @@ fi
   # Code from module netdb:
   # Code from module netinet_in:
   # Code from module nocrash:
+  # Code from module nonblocking:
   # Code from module open:
   # Code from module openat:
   # Code from module openat-die:
@@ -6868,6 +6879,7 @@ fi
   # Code from module strstr:
   # Code from module strstr-simple:
   # Code from module strtok_r:
+  # Code from module sys_ioctl:
   # Code from module sys_random:
   # Code from module sys_select:
   # Code from module sys_socket:
@@ -7297,6 +7309,13 @@ $as_echo "$gl_cv_source_line_length_unlimited" >&6; }
   UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
 
 
+
+  GNULIB_IOCTL=0;
+    SYS_IOCTL_H_HAVE_WINSOCK2_H=0;
+  SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
+
+  REPLACE_IOCTL=0;
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
 $as_echo_n "checking for C/C++ restrict keyword... " >&6; }
 if ${ac_cv_c_restrict+:} false; then :
@@ -16428,6 +16447,97 @@ $as_echo "#define HAVE_MINMAX_IN_SYS_PARAM_H 1" >>confdefs.h
   REPLACE_GETADDRINFO=0;
 
 
+
+  case "$host_os" in
+    mingw*) gl_cv_have_nonblocking=no ;;
+    *)      gl_cv_have_nonblocking=yes ;;
+  esac
+  case "$host_os" in
+    mingw*) gl_cv_have_open_O_NONBLOCK=no ;;
+    *)      gl_cv_have_open_O_NONBLOCK=yes ;;
+  esac
+
+
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#ifdef _MSC_VER
+MicrosoftCompiler
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "MicrosoftCompiler" >/dev/null 2>&1; then :
+            rm -f conftest*
+     echo 'int dummy;' > conftest.c
+     { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; } >/dev/null 2>&1
+     if test -f conftest.o; then
+       gl_asmext='s'
+       gl_c_asm_opt='-S'
+     else
+       gl_asmext='asm'
+       gl_c_asm_opt='-c -Fa'
+     fi
+     rm -f conftest*
+
+else
+  gl_asmext='s'
+     gl_c_asm_opt='-S'
+
+fi
+rm -f conftest*
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C symbols are prefixed with underscore at the linker level" >&5
+$as_echo_n "checking whether C symbols are prefixed with underscore at the linker level... " >&6; }
+if ${gl_cv_prog_as_underscore+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat > conftest.c <<EOF
+#ifdef __cplusplus
+extern "C" int foo (void);
+#endif
+int foo(void) { return 0; }
+EOF
+     # Look for the assembly language name in the .s file.
+     { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; } >/dev/null 2>&1
+     if LC_ALL=C $EGREP '(^|[^a-zA-Z0-9_])_foo([^a-zA-Z0-9_]|$)' conftest.$gl_asmext >/dev/null; then
+       gl_cv_prog_as_underscore=yes
+     else
+       gl_cv_prog_as_underscore=no
+     fi
+     rm -f conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_prog_as_underscore" >&5
+$as_echo "$gl_cv_prog_as_underscore" >&6; }
+  if test $gl_cv_prog_as_underscore = yes; then
+    USER_LABEL_PREFIX=_
+  else
+    USER_LABEL_PREFIX=
+  fi
+
+cat >>confdefs.h <<_ACEOF
+#define USER_LABEL_PREFIX $USER_LABEL_PREFIX
+_ACEOF
+
+  ASM_SYMBOL_PREFIX='"'${USER_LABEL_PREFIX}'"'
+
+
+
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for O_CLOEXEC" >&5
 $as_echo_n "checking for O_CLOEXEC... " >&6; }
 if ${gl_cv_macro_O_CLOEXEC+:} false; then :
@@ -17686,6 +17796,8 @@ _ACEOF
 
 
 
+
+
 $as_echo "#define _USE_STD_STAT 1" >>confdefs.h
 
 
@@ -23248,6 +23360,91 @@ $as_echo "$gl_cv_test_UINT64_MAX_EQ_ULONG_MAX" >&6; }
 
 
 
+  HAVE_IOCTL=1
+  if test "$ac_cv_header_winsock2_h" = yes; then
+                HAVE_IOCTL=0
+  else
+    for ac_func in ioctl
+do :
+  ac_fn_c_check_func "$LINENO" "ioctl" "ac_cv_func_ioctl"
+if test "x$ac_cv_func_ioctl" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_IOCTL 1
+_ACEOF
+
+fi
+done
+
+                { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ioctl with POSIX signature" >&5
+$as_echo_n "checking for ioctl with POSIX signature... " >&6; }
+if ${gl_cv_func_ioctl_posix_signature+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/ioctl.h>
+              /* On some platforms, ioctl() is declared in <unistd.h>.  */
+              #include <unistd.h>
+
+int
+main ()
+{
+extern
+              #ifdef __cplusplus
+              "C"
+              #endif
+              int ioctl (int, int, ...);
+
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_func_ioctl_posix_signature=yes
+else
+  gl_cv_func_ioctl_posix_signature=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_ioctl_posix_signature" >&5
+$as_echo "$gl_cv_func_ioctl_posix_signature" >&6; }
+    if test $gl_cv_func_ioctl_posix_signature != yes; then
+      REPLACE_IOCTL=1
+    fi
+  fi
+
+  if test $HAVE_IOCTL = 0 || test $REPLACE_IOCTL = 1; then
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS ioctl.$ac_objext"
+
+  fi
+
+
+
+
+
+          GNULIB_IOCTL=1
+
+
+
+
+
+$as_echo "#define GNULIB_TEST_IOCTL 1" >>confdefs.h
+
+
+
+
+
+
 
 
   if test $ac_cv_func_isblank = no; then
@@ -27053,6 +27250,36 @@ fi
 
 
 
+
+
+
+
+
+          GNULIB_NONBLOCKING=1
+
+
+
+
+
+$as_echo "#define GNULIB_TEST_NONBLOCKING 1" >>confdefs.h
+
+
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define GNULIB_NONBLOCKING 1
+_ACEOF
+
+
+
+
+  GNULIB_STDIO_H_NONBLOCKING=1
+
+  GNULIB_UNISTD_H_NONBLOCKING=1
+
+
+
   case "$host_os" in
     mingw* | pw*)
       REPLACE_OPEN=1
@@ -27151,6 +27378,15 @@ $as_echo "#define OPEN_TRAILING_SLASH_BUG 1" >>confdefs.h
     fi
 
 
+    if test $REPLACE_OPEN = 0; then
+
+
+
+      if test $gl_cv_have_open_O_NONBLOCK != yes; then
+        REPLACE_OPEN=1
+      fi
+    fi
+
 
   if test $REPLACE_OPEN = 1; then
 
@@ -29688,6 +29924,23 @@ _ACEOF
   GNULIB_FREAD=1
 
 
+
+
+    if test $gl_cv_have_nonblocking != yes; then
+      REPLACE_STDIO_READ_FUNCS=1
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS stdio-read.$ac_objext"
+
+    fi
+
+
       GNULIB_FPRINTF=1
   GNULIB_PRINTF=1
   GNULIB_VFPRINTF=1
@@ -29703,6 +29956,23 @@ _ACEOF
 
 
 
+    if test $gl_cv_have_nonblocking != yes; then
+      REPLACE_STDIO_WRITE_FUNCS=1
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS stdio-write.$ac_objext"
+
+    fi
+
+
+
+
 
 
 
@@ -30607,6 +30877,126 @@ $as_echo "#define GNULIB_TEST_STRTOK_R 1" >>confdefs.h
 
 
 
+  if test $ac_cv_header_sys_ioctl_h = yes; then
+    HAVE_SYS_IOCTL_H=1
+            { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether <sys/ioctl.h> declares ioctl" >&5
+$as_echo_n "checking whether <sys/ioctl.h> declares ioctl... " >&6; }
+if ${gl_cv_decl_ioctl_in_sys_ioctl_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+         cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/ioctl.h>
+int
+main ()
+{
+(void) ioctl;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_decl_ioctl_in_sys_ioctl_h=yes
+else
+  gl_cv_decl_ioctl_in_sys_ioctl_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_decl_ioctl_in_sys_ioctl_h" >&5
+$as_echo "$gl_cv_decl_ioctl_in_sys_ioctl_h" >&6; }
+  else
+    HAVE_SYS_IOCTL_H=0
+  fi
+
+
+
+
+
+
+
+
+
+
+     if test $gl_cv_have_include_next = yes; then
+       gl_cv_next_sys_ioctl_h='<'sys/ioctl.h'>'
+     else
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking absolute name of <sys/ioctl.h>" >&5
+$as_echo_n "checking absolute name of <sys/ioctl.h>... " >&6; }
+if ${gl_cv_next_sys_ioctl_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+             if test $ac_cv_header_sys_ioctl_h = yes; then
+
+
+
+
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/ioctl.h>
+_ACEOF
+                case "$host_os" in
+    aix*) gl_absname_cpp="$ac_cpp -C" ;;
+    *)    gl_absname_cpp="$ac_cpp" ;;
+  esac
+
+  case "$host_os" in
+    mingw*)
+                                          gl_dirsep_regex='[/\\]'
+      ;;
+    *)
+      gl_dirsep_regex='\/'
+      ;;
+  esac
+      gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
+  gl_header_literal_regex=`echo 'sys/ioctl.h' \
+                           | sed -e "$gl_make_literal_regex_sed"`
+  gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
+      s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
+      s|^/[^/]|//&|
+      p
+      q
+    }'
+
+        gl_cv_absolute_sys_ioctl_h=`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&5 |
+  sed -n "$gl_absolute_header_sed"`
+
+           gl_header=$gl_cv_absolute_sys_ioctl_h
+           gl_cv_next_sys_ioctl_h='"'$gl_header'"'
+          else
+               gl_cv_next_sys_ioctl_h='<'sys/ioctl.h'>'
+             fi
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_next_sys_ioctl_h" >&5
+$as_echo "$gl_cv_next_sys_ioctl_h" >&6; }
+     fi
+     NEXT_SYS_IOCTL_H=$gl_cv_next_sys_ioctl_h
+
+     if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
+       gl_next_as_first_directive='<'sys/ioctl.h'>'
+     else
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
+       gl_next_as_first_directive=$gl_cv_next_sys_ioctl_h
+     fi
+     NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H=$gl_next_as_first_directive
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
 
 
diff --git a/gnulib/import/Makefile.am b/gnulib/import/Makefile.am
index 5a405cfc3683..685be26bf7b9 100644
--- a/gnulib/import/Makefile.am
+++ b/gnulib/import/Makefile.am
@@ -63,6 +63,7 @@
 #  mkdtemp \
 #  mkostemp \
 #  netdb \
+#  nonblocking \
 #  pathmax \
 #  rawmemchr \
 #  readlink \
@@ -947,6 +948,15 @@ EXTRA_DIST += inttypes.in.h
 
 ## end   gnulib module inttypes-incomplete
 
+## begin gnulib module ioctl
+
+
+EXTRA_DIST += ioctl.c w32sock.h
+
+EXTRA_libgnu_a_SOURCES += ioctl.c
+
+## end   gnulib module ioctl
+
 ## begin gnulib module isblank
 
 
@@ -1603,6 +1613,16 @@ EXTRA_DIST += netinet_in.in.h
 
 ## end   gnulib module netinet_in
 
+## begin gnulib module nonblocking
+
+libgnu_a_SOURCES += nonblocking.c
+
+EXTRA_DIST += nonblocking.h stdio-read.c stdio-write.c
+
+EXTRA_libgnu_a_SOURCES += stdio-read.c stdio-write.c
+
+## end   gnulib module nonblocking
+
 ## begin gnulib module open
 
 
@@ -2539,6 +2559,38 @@ EXTRA_libgnu_a_SOURCES += strtok_r.c
 
 ## end   gnulib module strtok_r
 
+## begin gnulib module sys_ioctl
+
+BUILT_SOURCES += sys/ioctl.h
+
+# We need the following in order to create <sys/ioctl.h> when the system
+# does not have a complete one.
+sys/ioctl.h: sys_ioctl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
+	$(AM_V_at)$(MKDIR_P) sys
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's|@''HAVE_SYS_IOCTL_H''@|$(HAVE_SYS_IOCTL_H)|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_SYS_IOCTL_H''@|$(NEXT_SYS_IOCTL_H)|g' \
+	      -e 's/@''GNULIB_IOCTL''@/$(GNULIB_IOCTL)/g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
+	      -e 's|@''REPLACE_IOCTL''@|$(REPLACE_IOCTL)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/sys_ioctl.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+MOSTLYCLEANFILES += sys/ioctl.h sys/ioctl.h-t
+MOSTLYCLEANDIRS += sys
+
+EXTRA_DIST += sys_ioctl.in.h
+
+## end   gnulib module sys_ioctl
+
 ## begin gnulib module sys_random
 
 BUILT_SOURCES += sys/random.h
diff --git a/gnulib/import/Makefile.in b/gnulib/import/Makefile.in
index 3393458f4e66..990b64186c1f 100644
--- a/gnulib/import/Makefile.in
+++ b/gnulib/import/Makefile.in
@@ -77,6 +77,7 @@
 #  mkdtemp \
 #  mkostemp \
 #  netdb \
+#  nonblocking \
 #  pathmax \
 #  rawmemchr \
 #  readlink \
@@ -188,6 +189,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/absolute-header.m4 \
 	$(top_srcdir)/import/m4/alloca.m4 \
 	$(top_srcdir)/import/m4/arpa_inet_h.m4 \
+	$(top_srcdir)/import/m4/asm-underscore.m4 \
 	$(top_srcdir)/import/m4/btowc.m4 \
 	$(top_srcdir)/import/m4/builtin-expect.m4 \
 	$(top_srcdir)/import/m4/canonicalize.m4 \
@@ -248,6 +250,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/include_next.m4 \
 	$(top_srcdir)/import/m4/inet_ntop.m4 \
 	$(top_srcdir)/import/m4/inttypes.m4 \
+	$(top_srcdir)/import/m4/ioctl.m4 \
 	$(top_srcdir)/import/m4/isblank.m4 \
 	$(top_srcdir)/import/m4/isnand.m4 \
 	$(top_srcdir)/import/m4/isnanl.m4 \
@@ -284,6 +287,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/netdb_h.m4 \
 	$(top_srcdir)/import/m4/netinet_in_h.m4 \
 	$(top_srcdir)/import/m4/nocrash.m4 \
+	$(top_srcdir)/import/m4/nonblocking.m4 \
 	$(top_srcdir)/import/m4/off_t.m4 \
 	$(top_srcdir)/import/m4/open-cloexec.m4 \
 	$(top_srcdir)/import/m4/open-slash.m4 \
@@ -329,6 +333,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/strnlen.m4 \
 	$(top_srcdir)/import/m4/strstr.m4 \
 	$(top_srcdir)/import/m4/strtok_r.m4 \
+	$(top_srcdir)/import/m4/sys_ioctl_h.m4 \
 	$(top_srcdir)/import/m4/sys_random_h.m4 \
 	$(top_srcdir)/import/m4/sys_select_h.m4 \
 	$(top_srcdir)/import/m4/sys_socket_h.m4 \
@@ -374,8 +379,9 @@ am_libgnu_a_OBJECTS = openat-proc.$(OBJEXT) basename-lgpl.$(OBJEXT) \
 	dup-safer-flag.$(OBJEXT) filenamecat-lgpl.$(OBJEXT) \
 	getprogname.$(OBJEXT) hard-locale.$(OBJEXT) \
 	localcharset.$(OBJEXT) glthread/lock.$(OBJEXT) \
-	malloca.$(OBJEXT) math.$(OBJEXT) openat-die.$(OBJEXT) \
-	save-cwd.$(OBJEXT) malloc/scratch_buffer_dupfree.$(OBJEXT) \
+	malloca.$(OBJEXT) math.$(OBJEXT) nonblocking.$(OBJEXT) \
+	openat-die.$(OBJEXT) save-cwd.$(OBJEXT) \
+	malloc/scratch_buffer_dupfree.$(OBJEXT) \
 	malloc/scratch_buffer_grow.$(OBJEXT) \
 	malloc/scratch_buffer_grow_preserve.$(OBJEXT) \
 	malloc/scratch_buffer_set_array_size.$(OBJEXT) \
@@ -464,6 +470,7 @@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
 APPLE_UNIVERSAL_BUILD = @APPLE_UNIVERSAL_BUILD@
 AR = @AR@
 ARFLAGS = @ARFLAGS@
+ASM_SYMBOL_PREFIX = @ASM_SYMBOL_PREFIX@
 AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
@@ -648,6 +655,7 @@ GNULIB_IMAXABS = @GNULIB_IMAXABS@
 GNULIB_IMAXDIV = @GNULIB_IMAXDIV@
 GNULIB_INET_NTOP = @GNULIB_INET_NTOP@
 GNULIB_INET_PTON = @GNULIB_INET_PTON@
+GNULIB_IOCTL = @GNULIB_IOCTL@
 GNULIB_ISATTY = @GNULIB_ISATTY@
 GNULIB_ISBLANK = @GNULIB_ISBLANK@
 GNULIB_ISFINITE = @GNULIB_ISFINITE@
@@ -1276,6 +1284,7 @@ HAVE_SYMLINK = @HAVE_SYMLINK@
 HAVE_SYMLINKAT = @HAVE_SYMLINKAT@
 HAVE_SYS_BITYPES_H = @HAVE_SYS_BITYPES_H@
 HAVE_SYS_INTTYPES_H = @HAVE_SYS_INTTYPES_H@
+HAVE_SYS_IOCTL_H = @HAVE_SYS_IOCTL_H@
 HAVE_SYS_LOADAVG_H = @HAVE_SYS_LOADAVG_H@
 HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@
 HAVE_SYS_RANDOM_H = @HAVE_SYS_RANDOM_H@
@@ -1411,6 +1420,7 @@ NEXT_AS_FIRST_DIRECTIVE_STDIO_H = @NEXT_AS_FIRST_DIRECTIVE_STDIO_H@
 NEXT_AS_FIRST_DIRECTIVE_STDLIB_H = @NEXT_AS_FIRST_DIRECTIVE_STDLIB_H@
 NEXT_AS_FIRST_DIRECTIVE_STRINGS_H = @NEXT_AS_FIRST_DIRECTIVE_STRINGS_H@
 NEXT_AS_FIRST_DIRECTIVE_STRING_H = @NEXT_AS_FIRST_DIRECTIVE_STRING_H@
+NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H@
@@ -1443,6 +1453,7 @@ NEXT_STDIO_H = @NEXT_STDIO_H@
 NEXT_STDLIB_H = @NEXT_STDLIB_H@
 NEXT_STRINGS_H = @NEXT_STRINGS_H@
 NEXT_STRING_H = @NEXT_STRING_H@
+NEXT_SYS_IOCTL_H = @NEXT_SYS_IOCTL_H@
 NEXT_SYS_RANDOM_H = @NEXT_SYS_RANDOM_H@
 NEXT_SYS_SELECT_H = @NEXT_SYS_SELECT_H@
 NEXT_SYS_SOCKET_H = @NEXT_SYS_SOCKET_H@
@@ -1573,6 +1584,7 @@ REPLACE_ILOGBL = @REPLACE_ILOGBL@
 REPLACE_INET_NTOP = @REPLACE_INET_NTOP@
 REPLACE_INET_PTON = @REPLACE_INET_PTON@
 REPLACE_INITSTATE = @REPLACE_INITSTATE@
+REPLACE_IOCTL = @REPLACE_IOCTL@
 REPLACE_ISATTY = @REPLACE_ISATTY@
 REPLACE_ISFINITE = @REPLACE_ISFINITE@
 REPLACE_ISINF = @REPLACE_ISINF@
@@ -1744,6 +1756,8 @@ STDBOOL_H = @STDBOOL_H@
 STDDEF_H = @STDDEF_H@
 STDINT_H = @STDINT_H@
 STRIP = @STRIP@
+SYS_IOCTL_H_HAVE_WINSOCK2_H = @SYS_IOCTL_H_HAVE_WINSOCK2_H@
+SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS = @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC = @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
 TIME_H_DEFINES_STRUCT_TIMESPEC = @TIME_H_DEFINES_STRUCT_TIMESPEC@
 TIME_H_DEFINES_TIME_UTC = @TIME_H_DEFINES_TIME_UTC@
@@ -1843,30 +1857,32 @@ EXTRA_DIST = m4/gnulib-cache.m4 accept.c w32sock.h alloca.c \
 	gettimeofday.c $(top_srcdir)/import/extra/gitlog-to-changelog \
 	glob.c glob_internal.h glob_pattern_p.c globfree.c glob-libc.h \
 	glob.in.h hard-locale.h inet_ntop.c intprops.h inttypes.in.h \
-	isblank.c float+.h isnan.c isnand-nolibm.h isnand.c float+.h \
-	isnan.c isnanl-nolibm.h isnanl.c cdefs.h libc-config.h \
-	limits.in.h listen.c w32sock.h localcharset.h locale.in.h \
-	lstat.c malloc.c malloca.h math.in.h lc-charset-dispatch.c \
-	lc-charset-dispatch.h mbrtowc-impl-utf8.h mbrtowc-impl.h \
-	mbrtowc.c mbtowc-lock.c mbtowc-lock.h windows-initguard.h \
-	mbsinit.c mbsrtowcs-impl.h mbsrtowcs-state.c mbsrtowcs.c \
-	mbtowc-impl.h mbtowc.c memchr.c memchr.valgrind memmem.c \
-	memmem.c str-two-way.h mempcpy.c memrchr.c mkdir.c mkdtemp.c \
-	mkostemp.c msvc-inval.c msvc-inval.h msvc-nothrow.c \
-	msvc-nothrow.h netdb.in.h netinet_in.in.h open.c openat.c \
-	openat.h dirent-private.h opendir.c pathmax.h pipe.c \
-	rawmemchr.c rawmemchr.valgrind dirent-private.h readdir.c \
-	readlink.c realloc.c rename.c dirent-private.h rewinddir.c \
-	rmdir.c same-inode.h save-cwd.h malloc/scratch_buffer.h \
-	scratch_buffer.h select.c setenv.c setlocale-lock.c \
-	setlocale_null.h windows-initguard.h setsockopt.c w32sock.h \
-	signal.in.h _Noreturn.h arg-nonnull.h c++defs.h warn-on-use.h \
-	socket.c w32sock.h w32sock.h stat-w32.c stat-w32.h stat.c \
-	stat-time.h stdalign.in.h stdbool.in.h stddef.in.h stdint.in.h \
-	stdio.in.h stdlib.in.h strchrnul.c strchrnul.valgrind strdup.c \
-	streq.h strerror.c strerror-override.c strerror-override.h \
-	strerror_r.c string.in.h strings.in.h strnlen.c strstr.c \
-	str-two-way.h strstr.c strtok_r.c sys_random.in.h \
+	ioctl.c w32sock.h isblank.c float+.h isnan.c isnand-nolibm.h \
+	isnand.c float+.h isnan.c isnanl-nolibm.h isnanl.c cdefs.h \
+	libc-config.h limits.in.h listen.c w32sock.h localcharset.h \
+	locale.in.h lstat.c malloc.c malloca.h math.in.h \
+	lc-charset-dispatch.c lc-charset-dispatch.h \
+	mbrtowc-impl-utf8.h mbrtowc-impl.h mbrtowc.c mbtowc-lock.c \
+	mbtowc-lock.h windows-initguard.h mbsinit.c mbsrtowcs-impl.h \
+	mbsrtowcs-state.c mbsrtowcs.c mbtowc-impl.h mbtowc.c memchr.c \
+	memchr.valgrind memmem.c memmem.c str-two-way.h mempcpy.c \
+	memrchr.c mkdir.c mkdtemp.c mkostemp.c msvc-inval.c \
+	msvc-inval.h msvc-nothrow.c msvc-nothrow.h netdb.in.h \
+	netinet_in.in.h nonblocking.h stdio-read.c stdio-write.c \
+	open.c openat.c openat.h dirent-private.h opendir.c pathmax.h \
+	pipe.c rawmemchr.c rawmemchr.valgrind dirent-private.h \
+	readdir.c readlink.c realloc.c rename.c dirent-private.h \
+	rewinddir.c rmdir.c same-inode.h save-cwd.h \
+	malloc/scratch_buffer.h scratch_buffer.h select.c setenv.c \
+	setlocale-lock.c setlocale_null.h windows-initguard.h \
+	setsockopt.c w32sock.h signal.in.h _Noreturn.h arg-nonnull.h \
+	c++defs.h warn-on-use.h socket.c w32sock.h w32sock.h \
+	stat-w32.c stat-w32.h stat.c stat-time.h stdalign.in.h \
+	stdbool.in.h stddef.in.h stdint.in.h stdio.in.h stdlib.in.h \
+	strchrnul.c strchrnul.valgrind strdup.c streq.h strerror.c \
+	strerror-override.c strerror-override.h strerror_r.c \
+	string.in.h strings.in.h strnlen.c strstr.c str-two-way.h \
+	strstr.c strtok_r.c sys_ioctl.in.h sys_random.in.h \
 	sys_select.in.h sys_socket.in.h sys_stat.in.h sys_time.in.h \
 	sys_types.in.h sys_uio.in.h sys_wait.in.h tempname.h time.in.h \
 	time_r.c unistd.in.h unistd--.h unistd-safer.h unsetenv.c \
@@ -1880,9 +1896,9 @@ BUILT_SOURCES = $(ALLOCA_H) arpa/inet.h ctype.h dirent.h $(ERRNO_H) \
 	fcntl.h $(FLOAT_H) $(FNMATCH_H) $(GLOB_H) inttypes.h \
 	$(LIMITS_H) locale.h math.h netdb.h $(NETINET_IN_H) signal.h \
 	$(STDALIGN_H) $(STDBOOL_H) $(STDDEF_H) $(STDINT_H) stdio.h \
-	stdlib.h string.h strings.h sys/random.h sys/select.h \
-	sys/socket.h sys/stat.h sys/time.h sys/types.h sys/uio.h \
-	sys/wait.h time.h unistd.h wchar.h wctype.h
+	stdlib.h string.h strings.h sys/ioctl.h sys/random.h \
+	sys/select.h sys/socket.h sys/stat.h sys/time.h sys/types.h \
+	sys/uio.h sys/wait.h time.h unistd.h wchar.h wctype.h
 SUFFIXES = 
 MOSTLYCLEANFILES = core *.stackdump alloca.h alloca.h-t arpa/inet.h \
 	arpa/inet.h-t ctype.h ctype.h-t dirent.h dirent.h-t errno.h \
@@ -1893,12 +1909,13 @@ MOSTLYCLEANFILES = core *.stackdump alloca.h alloca.h-t arpa/inet.h \
 	stdalign.h stdalign.h-t stdbool.h stdbool.h-t stddef.h \
 	stddef.h-t stdint.h stdint.h-t stdio.h stdio.h-t stdlib.h \
 	stdlib.h-t string.h string.h-t strings.h strings.h-t \
-	sys/random.h sys/random.h-t sys/select.h sys/select.h-t \
-	sys/socket.h sys/socket.h-t sys/stat.h sys/stat.h-t sys/time.h \
-	sys/time.h-t sys/types.h sys/types.h-t sys/uio.h sys/uio.h-t \
-	sys/wait.h sys/wait.h-t time.h time.h-t unistd.h unistd.h-t \
-	wchar.h wchar.h-t wctype.h wctype.h-t
-MOSTLYCLEANDIRS = arpa netinet sys sys sys sys sys sys
+	sys/ioctl.h sys/ioctl.h-t sys/random.h sys/random.h-t \
+	sys/select.h sys/select.h-t sys/socket.h sys/socket.h-t \
+	sys/stat.h sys/stat.h-t sys/time.h sys/time.h-t sys/types.h \
+	sys/types.h-t sys/uio.h sys/uio.h-t sys/wait.h sys/wait.h-t \
+	time.h time.h-t unistd.h unistd.h-t wchar.h wchar.h-t wctype.h \
+	wctype.h-t
+MOSTLYCLEANDIRS = arpa netinet sys sys sys sys sys sys sys
 CLEANFILES = 
 DISTCLEANFILES = 
 MAINTAINERCLEANFILES = 
@@ -1909,8 +1926,8 @@ libgnu_a_SOURCES = openat-priv.h openat-proc.c basename-lgpl.c \
 	exitfail.c fd-hook.c fd-safer-flag.c dup-safer-flag.c \
 	filenamecat-lgpl.c getprogname.h getprogname.c gettext.h \
 	hard-locale.c idx.h localcharset.c glthread/lock.h \
-	glthread/lock.c malloca.c math.c minmax.h openat-die.c \
-	save-cwd.c malloc/scratch_buffer_dupfree.c \
+	glthread/lock.c malloca.c math.c minmax.h nonblocking.c \
+	openat-die.c save-cwd.c malloc/scratch_buffer_dupfree.c \
 	malloc/scratch_buffer_grow.c \
 	malloc/scratch_buffer_grow_preserve.c \
 	malloc/scratch_buffer_set_array_size.c setlocale_null.c \
@@ -1927,18 +1944,18 @@ EXTRA_libgnu_a_SOURCES = accept.c alloca.c bind.c btowc.c \
 	fstat.c stat-w32.c at-func.c fstatat.c getcwd.c getcwd-lgpl.c \
 	getdelim.c getdtablesize.c getline.c getlogin_r.c getrandom.c \
 	gettimeofday.c glob.c glob_pattern_p.c globfree.c inet_ntop.c \
-	isblank.c isnan.c isnand.c isnan.c isnanl.c listen.c lstat.c \
-	malloc.c lc-charset-dispatch.c mbrtowc.c mbtowc-lock.c \
+	ioctl.c isblank.c isnan.c isnand.c isnan.c isnanl.c listen.c \
+	lstat.c malloc.c lc-charset-dispatch.c mbrtowc.c mbtowc-lock.c \
 	mbsinit.c mbsrtowcs-state.c mbsrtowcs.c mbtowc.c memchr.c \
 	memmem.c memmem.c mempcpy.c memrchr.c mkdir.c mkdtemp.c \
-	mkostemp.c msvc-inval.c msvc-nothrow.c open.c openat.c \
-	opendir.c pipe.c rawmemchr.c readdir.c readlink.c realloc.c \
-	rename.c rewinddir.c rmdir.c select.c setenv.c \
-	setlocale-lock.c setsockopt.c socket.c stat-w32.c stat.c \
-	strchrnul.c strdup.c strerror.c strerror-override.c \
-	strerror_r.c strnlen.c strstr.c strstr.c strtok_r.c time_r.c \
-	unsetenv.c windows-mutex.c windows-once.c windows-recmutex.c \
-	windows-rwlock.c wmemchr.c wmempcpy.c
+	mkostemp.c msvc-inval.c msvc-nothrow.c stdio-read.c \
+	stdio-write.c open.c openat.c opendir.c pipe.c rawmemchr.c \
+	readdir.c readlink.c realloc.c rename.c rewinddir.c rmdir.c \
+	select.c setenv.c setlocale-lock.c setsockopt.c socket.c \
+	stat-w32.c stat.c strchrnul.c strdup.c strerror.c \
+	strerror-override.c strerror_r.c strnlen.c strstr.c strstr.c \
+	strtok_r.c time_r.c unsetenv.c windows-mutex.c windows-once.c \
+	windows-recmutex.c windows-rwlock.c wmemchr.c wmempcpy.c
 
 # Use this preprocessor expression to decide whether #include_next works.
 # Do not rely on a 'configure'-time test for this, since the expression
@@ -2103,6 +2120,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/globfree.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hard-locale.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet_ntop.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ioctl.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isblank.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isnan.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isnand.Po@am__quote@
@@ -2130,6 +2148,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkostemp.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msvc-inval.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msvc-nothrow.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nonblocking.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openat-die.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openat-proc.Po@am__quote@
@@ -2155,6 +2174,8 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat-time.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat-w32.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdio-read.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdio-write.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strchrnul.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strdup.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strerror-override.Po@am__quote@
@@ -3555,6 +3576,28 @@ strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE
 	} > $@-t && \
 	mv $@-t $@
 
+# We need the following in order to create <sys/ioctl.h> when the system
+# does not have a complete one.
+sys/ioctl.h: sys_ioctl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
+	$(AM_V_at)$(MKDIR_P) sys
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's|@''HAVE_SYS_IOCTL_H''@|$(HAVE_SYS_IOCTL_H)|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_SYS_IOCTL_H''@|$(NEXT_SYS_IOCTL_H)|g' \
+	      -e 's/@''GNULIB_IOCTL''@/$(GNULIB_IOCTL)/g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
+	      -e 's|@''REPLACE_IOCTL''@|$(REPLACE_IOCTL)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/sys_ioctl.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+
 # We need the following in order to create <sys/random.h> when the system
 # doesn't have one.
 sys/random.h: sys_random.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
diff --git a/gnulib/import/ioctl.c b/gnulib/import/ioctl.c
new file mode 100644
index 000000000000..5c5e7a474370
--- /dev/null
+++ b/gnulib/import/ioctl.c
@@ -0,0 +1,92 @@
+/* ioctl.c --- wrappers for Windows ioctl function
+
+   Copyright (C) 2008-2021 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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#include <sys/ioctl.h>
+
+#include <stdarg.h>
+
+#if HAVE_IOCTL
+
+/* Provide a wrapper with the POSIX prototype.  */
+# undef ioctl
+int
+rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */)
+{
+  void *buf;
+  va_list args;
+
+  va_start (args, request);
+  buf = va_arg (args, void *);
+  va_end (args);
+
+  /* Cast 'request' so that when the system's ioctl function takes a 64-bit
+     request argument, the value gets zero-extended, not sign-extended.  */
+  return ioctl (fd, (unsigned int) request, buf);
+}
+
+#else /* mingw */
+
+# include <errno.h>
+
+/* Get HANDLE.  */
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+# include "fd-hook.h"
+/* Get _get_osfhandle.  */
+# if GNULIB_MSVC_NOTHROW
+#  include "msvc-nothrow.h"
+# else
+#  include <io.h>
+# endif
+
+static int
+primary_ioctl (int fd, int request, void *arg)
+{
+  /* We don't support FIONBIO on pipes here.  If you want to make pipe
+     fds non-blocking, use the gnulib 'nonblocking' module, until
+     gnulib implements fcntl F_GETFL / F_SETFL with O_NONBLOCK.  */
+
+  if ((HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE)
+    errno = ENOSYS;
+  else
+    errno = EBADF;
+  return -1;
+}
+
+int
+ioctl (int fd, int request, ... /* {void *,char *} arg */)
+{
+  void *arg;
+  va_list args;
+
+  va_start (args, request);
+  arg = va_arg (args, void *);
+  va_end (args);
+
+# if WINDOWS_SOCKETS
+  return execute_all_ioctl_hooks (primary_ioctl, fd, request, arg);
+# else
+  return primary_ioctl (fd, request, arg);
+# endif
+}
+
+#endif
diff --git a/gnulib/import/m4/asm-underscore.m4 b/gnulib/import/m4/asm-underscore.m4
new file mode 100644
index 000000000000..93b98bea8f6e
--- /dev/null
+++ b/gnulib/import/m4/asm-underscore.m4
@@ -0,0 +1,83 @@
+# asm-underscore.m4 serial 5
+dnl Copyright (C) 2010-2021 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible. Based on as-underscore.m4 in GNU clisp.
+
+# gl_ASM_SYMBOL_PREFIX
+# Tests for the prefix of C symbols at the assembly language level and the
+# linker level. This prefix is either an underscore or empty. Defines the
+# C macro USER_LABEL_PREFIX to this prefix, and sets ASM_SYMBOL_PREFIX to
+# a stringified variant of this prefix.
+
+AC_DEFUN([gl_ASM_SYMBOL_PREFIX],
+[
+  AC_REQUIRE([AC_PROG_EGREP])
+  dnl We don't use GCC's __USER_LABEL_PREFIX__ here, because
+  dnl 1. It works only for GCC.
+  dnl 2. It is incorrectly defined on some platforms, in some GCC versions.
+  AC_REQUIRE([gl_C_ASM])
+  AC_CACHE_CHECK(
+    [whether C symbols are prefixed with underscore at the linker level],
+    [gl_cv_prog_as_underscore],
+    [cat > conftest.c <<EOF
+#ifdef __cplusplus
+extern "C" int foo (void);
+#endif
+int foo(void) { return 0; }
+EOF
+     # Look for the assembly language name in the .s file.
+     AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1
+     if LC_ALL=C $EGREP '(^|[[^a-zA-Z0-9_]])_foo([[^a-zA-Z0-9_]]|$)' conftest.$gl_asmext >/dev/null; then
+       gl_cv_prog_as_underscore=yes
+     else
+       gl_cv_prog_as_underscore=no
+     fi
+     rm -f conftest*
+    ])
+  if test $gl_cv_prog_as_underscore = yes; then
+    USER_LABEL_PREFIX=_
+  else
+    USER_LABEL_PREFIX=
+  fi
+  AC_DEFINE_UNQUOTED([USER_LABEL_PREFIX], [$USER_LABEL_PREFIX],
+    [Define to the prefix of C symbols at the assembler and linker level,
+     either an underscore or empty.])
+  ASM_SYMBOL_PREFIX='"'${USER_LABEL_PREFIX}'"'
+  AC_SUBST([ASM_SYMBOL_PREFIX])
+])
+
+# gl_C_ASM
+# Determines how to produce an assembly language file from C source code.
+# Sets the variables:
+#   gl_asmext - the extension of assembly language output,
+#   gl_c_asm_opt - the C compiler option that produces assembly language output.
+
+AC_DEFUN([gl_C_ASM],
+[
+  AC_EGREP_CPP([MicrosoftCompiler],
+    [
+#ifdef _MSC_VER
+MicrosoftCompiler
+#endif
+    ],
+    [dnl Microsoft's 'cl' and 'clang-cl' produce an .asm file, whereas 'clang'
+     dnl produces a .s file. Need to distinguish 'clang' and 'clang-cl'.
+     rm -f conftest*
+     echo 'int dummy;' > conftest.c
+     AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c) >/dev/null 2>&1
+     if test -f conftest.o; then
+       gl_asmext='s'
+       gl_c_asm_opt='-S'
+     else
+       gl_asmext='asm'
+       gl_c_asm_opt='-c -Fa'
+     fi
+     rm -f conftest*
+    ],
+    [gl_asmext='s'
+     gl_c_asm_opt='-S'
+    ])
+])
diff --git a/gnulib/import/m4/gnulib-cache.m4 b/gnulib/import/m4/gnulib-cache.m4
index 381cdde68f2b..bb91d4dce7a5 100644
--- a/gnulib/import/m4/gnulib-cache.m4
+++ b/gnulib/import/m4/gnulib-cache.m4
@@ -68,6 +68,7 @@
 #  mkdtemp \
 #  mkostemp \
 #  netdb \
+#  nonblocking \
 #  pathmax \
 #  rawmemchr \
 #  readlink \
@@ -123,6 +124,7 @@ gl_MODULES([
   mkdtemp
   mkostemp
   netdb
+  nonblocking
   pathmax
   rawmemchr
   readlink
diff --git a/gnulib/import/m4/gnulib-comp.m4 b/gnulib/import/m4/gnulib-comp.m4
index 5376a93c7924..4b3b0fc117ad 100644
--- a/gnulib/import/m4/gnulib-comp.m4
+++ b/gnulib/import/m4/gnulib-comp.m4
@@ -125,6 +125,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module intprops:
   # Code from module inttypes:
   # Code from module inttypes-incomplete:
+  # Code from module ioctl:
   # Code from module isblank:
   # Code from module isnand-nolibm:
   # Code from module isnanl-nolibm:
@@ -159,6 +160,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module netdb:
   # Code from module netinet_in:
   # Code from module nocrash:
+  # Code from module nonblocking:
   # Code from module open:
   # Code from module openat:
   # Code from module openat-die:
@@ -212,6 +214,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module strstr:
   # Code from module strstr-simple:
   # Code from module strtok_r:
+  # Code from module sys_ioctl:
   # Code from module sys_random:
   # Code from module sys_select:
   # Code from module sys_socket:
@@ -500,6 +503,11 @@ AC_DEFUN([gl_INIT],
   gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
   gl_INTTYPES_H
   gl_INTTYPES_INCOMPLETE
+  gl_FUNC_IOCTL
+  if test $HAVE_IOCTL = 0 || test $REPLACE_IOCTL = 1; then
+    AC_LIBOBJ([ioctl])
+  fi
+  gl_SYS_IOCTL_MODULE_INDICATOR([ioctl])
   gl_FUNC_ISBLANK
   if test $HAVE_ISBLANK = 0; then
     AC_LIBOBJ([isblank])
@@ -633,6 +641,17 @@ AC_DEFUN([gl_INIT],
   gl_HEADER_NETDB
   gl_HEADER_NETINET_IN
   AC_PROG_MKDIR_P
+  gl_NONBLOCKING_IO
+  gl_FCNTL_MODULE_INDICATOR([nonblocking])
+  dnl Define the C macro GNULIB_NONBLOCKING to 1.
+  gl_MODULE_INDICATOR([nonblocking])
+  dnl Define the substituted variable GNULIB_STDIO_H_NONBLOCKING to 1.
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_REQUIRE([gl_ASM_SYMBOL_PREFIX])
+  GNULIB_STDIO_H_NONBLOCKING=1
+  dnl Define the substituted variable GNULIB_UNISTD_H_NONBLOCKING to 1.
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  GNULIB_UNISTD_H_NONBLOCKING=1
   gl_FUNC_OPEN
   if test $REPLACE_OPEN = 1; then
     AC_LIBOBJ([open])
@@ -809,6 +828,8 @@ AC_DEFUN([gl_INIT],
     gl_PREREQ_STRTOK_R
   fi
   gl_STRING_MODULE_INDICATOR([strtok_r])
+  gl_SYS_IOCTL_H
+  AC_PROG_MKDIR_P
   gl_HEADER_SYS_RANDOM
   AC_PROG_MKDIR_P
   AC_REQUIRE([gl_HEADER_SYS_SELECT])
@@ -1118,6 +1139,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/inet_ntop.c
   lib/intprops.h
   lib/inttypes.in.h
+  lib/ioctl.c
   lib/isblank.c
   lib/isnan.c
   lib/isnand-nolibm.h
@@ -1170,6 +1192,8 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/msvc-nothrow.h
   lib/netdb.in.h
   lib/netinet_in.in.h
+  lib/nonblocking.c
+  lib/nonblocking.h
   lib/open.c
   lib/openat-die.c
   lib/openat-priv.h
@@ -1211,6 +1235,8 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/stdbool.in.h
   lib/stddef.in.h
   lib/stdint.in.h
+  lib/stdio-read.c
+  lib/stdio-write.c
   lib/stdio.in.h
   lib/stdlib.in.h
   lib/str-two-way.h
@@ -1230,6 +1256,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/strnlen1.h
   lib/strstr.c
   lib/strtok_r.c
+  lib/sys_ioctl.in.h
   lib/sys_random.in.h
   lib/sys_select.in.h
   lib/sys_socket.c
@@ -1272,6 +1299,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/absolute-header.m4
   m4/alloca.m4
   m4/arpa_inet_h.m4
+  m4/asm-underscore.m4
   m4/btowc.m4
   m4/builtin-expect.m4
   m4/canonicalize.m4
@@ -1332,6 +1360,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/include_next.m4
   m4/inet_ntop.m4
   m4/inttypes.m4
+  m4/ioctl.m4
   m4/isblank.m4
   m4/isnand.m4
   m4/isnanl.m4
@@ -1368,6 +1397,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/netdb_h.m4
   m4/netinet_in_h.m4
   m4/nocrash.m4
+  m4/nonblocking.m4
   m4/off_t.m4
   m4/open-cloexec.m4
   m4/open-slash.m4
@@ -1413,6 +1443,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/strnlen.m4
   m4/strstr.m4
   m4/strtok_r.m4
+  m4/sys_ioctl_h.m4
   m4/sys_random_h.m4
   m4/sys_select_h.m4
   m4/sys_socket_h.m4
diff --git a/gnulib/import/m4/ioctl.m4 b/gnulib/import/m4/ioctl.m4
new file mode 100644
index 000000000000..18286783a88b
--- /dev/null
+++ b/gnulib/import/m4/ioctl.m4
@@ -0,0 +1,44 @@
+# ioctl.m4 serial 5
+dnl Copyright (C) 2008-2021 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_IOCTL],
+[
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+  HAVE_IOCTL=1
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    dnl Even if the 'socket' module is not used here, another part of the
+    dnl application may use it and pass file descriptors that refer to
+    dnl sockets to the ioctl() function. So enable the support for sockets.
+    HAVE_IOCTL=0
+  else
+    AC_CHECK_FUNCS([ioctl])
+    dnl On glibc systems, the second parameter is 'unsigned long int request',
+    dnl not 'int request'. We cannot simply cast the function pointer, but
+    dnl instead need a wrapper.
+    AC_CACHE_CHECK([for ioctl with POSIX signature],
+      [gl_cv_func_ioctl_posix_signature],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <sys/ioctl.h>
+              /* On some platforms, ioctl() is declared in <unistd.h>.  */
+              #include <unistd.h>
+            ]],
+            [[extern
+              #ifdef __cplusplus
+              "C"
+              #endif
+              int ioctl (int, int, ...);
+            ]])
+         ],
+         [gl_cv_func_ioctl_posix_signature=yes],
+         [gl_cv_func_ioctl_posix_signature=no])
+      ])
+    if test $gl_cv_func_ioctl_posix_signature != yes; then
+      REPLACE_IOCTL=1
+    fi
+  fi
+])
diff --git a/gnulib/import/m4/nonblocking.m4 b/gnulib/import/m4/nonblocking.m4
new file mode 100644
index 000000000000..5f988b1c9bcd
--- /dev/null
+++ b/gnulib/import/m4/nonblocking.m4
@@ -0,0 +1,29 @@
+# nonblocking.m4 serial 2
+dnl Copyright (C) 2011-2021 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Tests whether non-blocking I/O is natively supported by read(), write().
+dnl Sets gl_cv_have_nonblocking.
+dnl Also tests whether open() supports O_NONBLOCK.
+dnl Sets gl_cv_have_open_O_NONBLOCK.
+AC_DEFUN([gl_NONBLOCKING_IO],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_NONBLOCKING_IO_BODY])
+])
+
+AC_DEFUN([gl_NONBLOCKING_IO_BODY],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  case "$host_os" in
+    mingw*) gl_cv_have_nonblocking=no ;;
+    *)      gl_cv_have_nonblocking=yes ;;
+  esac
+  case "$host_os" in
+    mingw*) gl_cv_have_open_O_NONBLOCK=no ;;
+    *)      gl_cv_have_open_O_NONBLOCK=yes ;;
+  esac
+])
diff --git a/gnulib/import/m4/sys_ioctl_h.m4 b/gnulib/import/m4/sys_ioctl_h.m4
new file mode 100644
index 000000000000..4d7267fc73c9
--- /dev/null
+++ b/gnulib/import/m4/sys_ioctl_h.m4
@@ -0,0 +1,64 @@
+# sys_ioctl_h.m4 serial 12
+dnl Copyright (C) 2008-2021 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Bruno Haible.
+
+AC_DEFUN([gl_SYS_IOCTL_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+
+  AC_CHECK_HEADERS_ONCE([sys/ioctl.h])
+  if test $ac_cv_header_sys_ioctl_h = yes; then
+    HAVE_SYS_IOCTL_H=1
+    dnl Test whether <sys/ioctl.h> declares ioctl(), or whether some other
+    dnl header file, such as <unistd.h> or <stropts.h>, is needed for that.
+    AC_CACHE_CHECK([whether <sys/ioctl.h> declares ioctl],
+      [gl_cv_decl_ioctl_in_sys_ioctl_h],
+      [dnl We cannot use AC_CHECK_DECL because it produces its own messages.
+       AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <sys/ioctl.h>]],
+            [[(void) ioctl;]])],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=yes],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=no])
+      ])
+  else
+    HAVE_SYS_IOCTL_H=0
+  fi
+  AC_SUBST([HAVE_SYS_IOCTL_H])
+  dnl <sys/ioctl.h> is always overridden, because of GNULIB_POSIXCHECK.
+  gl_CHECK_NEXT_HEADERS([sys/ioctl.h])
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[#include <sys/ioctl.h>
+/* Some platforms declare ioctl in the wrong header.  */
+#if !(defined __GLIBC__ && !defined __UCLIBC__)
+# include <unistd.h>
+#endif
+    ]], [ioctl])
+])
+
+AC_DEFUN([gl_SYS_IOCTL_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_SYS_IOCTL_H_DEFAULTS],
+[
+  GNULIB_IOCTL=0;         AC_SUBST([GNULIB_IOCTL])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  SYS_IOCTL_H_HAVE_WINSOCK2_H=0; AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H])
+  SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
+                        AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
+  REPLACE_IOCTL=0;      AC_SUBST([REPLACE_IOCTL])
+])
diff --git a/gnulib/import/nonblocking.c b/gnulib/import/nonblocking.c
new file mode 100644
index 000000000000..ac6504c72acb
--- /dev/null
+++ b/gnulib/import/nonblocking.c
@@ -0,0 +1,163 @@
+/* Non-blocking I/O for pipe or socket descriptors.
+   Copyright (C) 2011-2021 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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "nonblocking.h"
+
+#include <errno.h>
+
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Native Windows API.  */
+
+# include <sys/ioctl.h>
+# include <sys/socket.h>
+# include <unistd.h>
+
+/* Get declarations of the native Windows API functions.  */
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+# if GNULIB_MSVC_NOTHROW
+#  include "msvc-nothrow.h"
+# else
+#  include <io.h>
+# endif
+
+/* Don't assume that UNICODE is not defined.  */
+# undef GetNamedPipeHandleState
+# define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
+int
+get_nonblocking_flag (int desc)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (desc);
+  if (h == INVALID_HANDLE_VALUE)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  if (GetFileType (h) == FILE_TYPE_PIPE)
+    {
+      /* h is a pipe or socket.  */
+      DWORD state;
+      if (GetNamedPipeHandleState (h, &state, NULL, NULL, NULL, NULL, 0))
+        /* h is a pipe.  */
+        return (state & PIPE_NOWAIT) != 0;
+      else
+        /* h is a socket.  */
+        errno = ENOSYS;
+        return -1;
+    }
+  else
+    /* The native Windows API does not support non-blocking on regular
+       files.  */
+    return 0;
+}
+
+int
+set_nonblocking_flag (int desc, bool value)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (desc);
+  if (h == INVALID_HANDLE_VALUE)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  if (GetFileType (h) == FILE_TYPE_PIPE)
+    {
+      /* h is a pipe or socket.  */
+      DWORD state;
+      if (GetNamedPipeHandleState (h, &state, NULL, NULL, NULL, NULL, 0))
+        {
+          /* h is a pipe.  */
+          if ((state & PIPE_NOWAIT) != 0)
+            {
+              if (value)
+                return 0;
+              state &= ~PIPE_NOWAIT;
+            }
+          else
+            {
+              if (!value)
+                return 0;
+              state |= PIPE_NOWAIT;
+            }
+          if (SetNamedPipeHandleState (h, &state, NULL, NULL))
+            return 0;
+          errno = EINVAL;
+          return -1;
+        }
+      else
+        {
+          /* h is a socket.  */
+          int v = value;
+          return ioctl (desc, FIONBIO, &v);
+        }
+    }
+  else
+    {
+      /* The native Windows API does not support non-blocking on regular
+         files.  */
+      if (!value)
+        return 0;
+      errno = ENOTSUP;
+      return -1;
+    }
+}
+
+#else
+/* Unix API.  */
+
+# include <fcntl.h>
+
+# if GNULIB_defined_O_NONBLOCK
+#  error Please port nonblocking to your platform
+# endif
+
+/* We don't need the gnulib replacement of fcntl() here.  */
+# undef fcntl
+
+int
+get_nonblocking_flag (int desc)
+{
+  int fcntl_flags;
+
+  fcntl_flags = fcntl (desc, F_GETFL, 0);
+  if (fcntl_flags < 0)
+    return -1;
+  return (fcntl_flags & O_NONBLOCK) != 0;
+}
+
+int
+set_nonblocking_flag (int desc, bool value)
+{
+  int fcntl_flags;
+
+  fcntl_flags = fcntl (desc, F_GETFL, 0);
+  if (fcntl_flags < 0)
+    return -1;
+  if (((fcntl_flags & O_NONBLOCK) != 0) == value)
+    return 0;
+  if (value)
+    fcntl_flags |= O_NONBLOCK;
+  else
+    fcntl_flags &= ~O_NONBLOCK;
+  return fcntl (desc, F_SETFL, fcntl_flags);
+}
+
+#endif
diff --git a/gnulib/import/nonblocking.h b/gnulib/import/nonblocking.h
new file mode 100644
index 000000000000..e490dba5bb15
--- /dev/null
+++ b/gnulib/import/nonblocking.h
@@ -0,0 +1,62 @@
+/* Non-blocking I/O for pipe or socket descriptors.
+   Copyright (C) 2011-2021 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 <https://www.gnu.org/licenses/>.  */
+
+#ifndef _NONBLOCKING_H
+#define _NONBLOCKING_H
+
+#include <stdbool.h>
+
+/* Non-blocking I/O is an I/O mode by which read(), write() calls avoid
+   blocking the current thread.  When non-blocking is enabled:
+   - A read() call returns -1 with errno set to EAGAIN when no data or EOF
+     information is immediately available.
+   - A write() call returns -1 with errno set to EAGAIN when it cannot
+     transport the requested amount of data (but at most one pipe buffer)
+     without blocking.
+   Non-blocking I/O is most useful for character devices, pipes, and sockets.
+   Whether it also works on regular files and block devices is platform
+   dependent.
+
+   There are three modern alternatives to non-blocking I/O:
+     - use select() or poll() followed by read() or write() if the descriptor
+       is ready,
+     - call read() or write() in separate threads,
+     - use <aio.h> interfaces.  */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Return 1 if I/O to the descriptor DESC is currently non-blocking, 0
+   it is blocking, or -1 with errno set if fd is invalid or blocking
+   status cannot be determined (such as with sockets on mingw).  */
+extern int get_nonblocking_flag (int desc);
+
+/* Specify the non-blocking flag for the descriptor DESC.
+   Return 0 upon success, or -1 with errno set upon failure.
+   The default depends on the presence of the O_NONBLOCK flag for files
+   or pipes opened with open() or on the presence of the SOCK_NONBLOCK
+   flag for sockets.  */
+extern int set_nonblocking_flag (int desc, bool value);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _NONBLOCKING_H */
diff --git a/gnulib/import/stdio-read.c b/gnulib/import/stdio-read.c
new file mode 100644
index 000000000000..76e0c80a430b
--- /dev/null
+++ b/gnulib/import/stdio-read.c
@@ -0,0 +1,168 @@
+/* POSIX compatible FILE stream read function.
+   Copyright (C) 2008-2021 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2011.
+
+   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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+/* Replace these functions only if module 'nonblocking' is requested.  */
+#if GNULIB_NONBLOCKING
+
+/* On native Windows platforms, when read() is called on a non-blocking pipe
+   with an empty buffer, ReadFile() fails with error GetLastError() =
+   ERROR_NO_DATA, and read() in consequence fails with error EINVAL.  This
+   read() function is at the basis of the function which fills the buffer of
+   a FILE stream.  */
+
+# if defined _WIN32 && ! defined __CYGWIN__
+
+#  include <errno.h>
+#  include <io.h>
+
+#  define WIN32_LEAN_AND_MEAN  /* avoid including junk */
+#  include <windows.h>
+
+#  if GNULIB_MSVC_NOTHROW
+#   include "msvc-nothrow.h"
+#  else
+#   include <io.h>
+#  endif
+
+/* Don't assume that UNICODE is not defined.  */
+#  undef GetNamedPipeHandleState
+#  define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
+#  define CALL_WITH_ERRNO_FIX(RETTYPE, EXPRESSION, FAILED) \
+  if (ferror (stream))                                                        \
+    return (EXPRESSION);                                                      \
+  else                                                                        \
+    {                                                                         \
+      RETTYPE ret;                                                            \
+      SetLastError (0);                                                       \
+      ret = (EXPRESSION);                                                     \
+      if (FAILED)                                                             \
+        {                                                                     \
+          if (GetLastError () == ERROR_NO_DATA && ferror (stream))            \
+            {                                                                 \
+              int fd = fileno (stream);                                       \
+              if (fd >= 0)                                                    \
+                {                                                             \
+                  HANDLE h = (HANDLE) _get_osfhandle (fd);                    \
+                  if (GetFileType (h) == FILE_TYPE_PIPE)                      \
+                    {                                                         \
+                      /* h is a pipe or socket.  */                           \
+                      DWORD state;                                            \
+                      if (GetNamedPipeHandleState (h, &state, NULL, NULL,     \
+                                                   NULL, NULL, 0)             \
+                          && (state & PIPE_NOWAIT) != 0)                      \
+                        /* h is a pipe in non-blocking mode.                  \
+                           Change errno from EINVAL to EAGAIN.  */            \
+                        errno = EAGAIN;                                       \
+                    }                                                         \
+                }                                                             \
+            }                                                                 \
+        }                                                                     \
+      return ret;                                                             \
+    }
+
+/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
+   Otherwise we get a function definition conflict with mingw64's <stdio.h>.  */
+#  if GNULIB_SCANF
+int
+scanf (const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfscanf (stdin, format, args);
+  va_end (args);
+
+  return retval;
+}
+#  endif
+
+/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
+   Otherwise we get a function definition conflict with mingw64's <stdio.h>.  */
+#  if GNULIB_FSCANF
+int
+fscanf (FILE *stream, const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfscanf (stream, format, args);
+  va_end (args);
+
+  return retval;
+}
+#  endif
+
+/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
+   Otherwise we get a function definition conflict with mingw64's <stdio.h>.  */
+#  if GNULIB_VSCANF
+int
+vscanf (const char *format, va_list args)
+{
+  return vfscanf (stdin, format, args);
+}
+#  endif
+
+/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
+   Otherwise we get a function definition conflict with mingw64's <stdio.h>.  */
+#  if GNULIB_VFSCANF
+int
+vfscanf (FILE *stream, const char *format, va_list args)
+#undef vfscanf
+{
+  CALL_WITH_ERRNO_FIX (int, vfscanf (stream, format, args), ret == EOF)
+}
+#  endif
+
+int
+getchar (void)
+{
+  return fgetc (stdin);
+}
+
+int
+fgetc (FILE *stream)
+#undef fgetc
+{
+  CALL_WITH_ERRNO_FIX (int, fgetc (stream), ret == EOF)
+}
+
+char *
+fgets (char *s, int n, FILE *stream)
+#undef fgets
+{
+  CALL_WITH_ERRNO_FIX (char *, fgets (s, n, stream), ret == NULL)
+}
+
+/* We intentionally don't bother to fix gets.  */
+
+size_t
+fread (void *ptr, size_t s, size_t n, FILE *stream)
+#undef fread
+{
+  CALL_WITH_ERRNO_FIX (size_t, fread (ptr, s, n, stream), ret < n)
+}
+
+# endif
+#endif
diff --git a/gnulib/import/stdio-write.c b/gnulib/import/stdio-write.c
new file mode 100644
index 000000000000..b6a59e0dfda4
--- /dev/null
+++ b/gnulib/import/stdio-write.c
@@ -0,0 +1,206 @@
+/* POSIX compatible FILE stream write function.
+   Copyright (C) 2008-2021 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+   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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+/* Replace these functions only if module 'nonblocking' or module 'sigpipe' is
+   requested.  */
+#if GNULIB_NONBLOCKING || GNULIB_SIGPIPE
+
+/* On native Windows platforms, SIGPIPE does not exist.  When write() is
+   called on a pipe with no readers, WriteFile() fails with error
+   GetLastError() = ERROR_NO_DATA, and write() in consequence fails with
+   error EINVAL.  This write() function is at the basis of the function
+   which flushes the buffer of a FILE stream.  */
+
+# if defined _WIN32 && ! defined __CYGWIN__
+
+#  include <errno.h>
+#  include <signal.h>
+#  include <io.h>
+
+#  define WIN32_LEAN_AND_MEAN  /* avoid including junk */
+#  include <windows.h>
+
+#  if GNULIB_MSVC_NOTHROW
+#   include "msvc-nothrow.h"
+#  else
+#   include <io.h>
+#  endif
+
+/* Don't assume that UNICODE is not defined.  */
+#  undef GetNamedPipeHandleState
+#  define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
+#  if GNULIB_NONBLOCKING
+#   define CLEAR_ERRNO \
+      errno = 0;
+#   define HANDLE_ENOSPC \
+          if (errno == ENOSPC && ferror (stream))                             \
+            {                                                                 \
+              int fd = fileno (stream);                                       \
+              if (fd >= 0)                                                    \
+                {                                                             \
+                  HANDLE h = (HANDLE) _get_osfhandle (fd);                    \
+                  if (GetFileType (h) == FILE_TYPE_PIPE)                      \
+                    {                                                         \
+                      /* h is a pipe or socket.  */                           \
+                      DWORD state;                                            \
+                      if (GetNamedPipeHandleState (h, &state, NULL, NULL,     \
+                                                   NULL, NULL, 0)             \
+                          && (state & PIPE_NOWAIT) != 0)                      \
+                        /* h is a pipe in non-blocking mode.                  \
+                           Change errno from ENOSPC to EAGAIN.  */            \
+                        errno = EAGAIN;                                       \
+                    }                                                         \
+                }                                                             \
+            }                                                                 \
+          else
+#  else
+#   define CLEAR_ERRNO
+#   define HANDLE_ENOSPC
+#  endif
+
+#  if GNULIB_SIGPIPE
+#   define CLEAR_LastError \
+      SetLastError (0);
+#   define HANDLE_ERROR_NO_DATA \
+          if (GetLastError () == ERROR_NO_DATA && ferror (stream))            \
+            {                                                                 \
+              int fd = fileno (stream);                                       \
+              if (fd >= 0                                                     \
+                  && GetFileType ((HANDLE) _get_osfhandle (fd))               \
+                     == FILE_TYPE_PIPE)                                       \
+                {                                                             \
+                  /* Try to raise signal SIGPIPE.  */                         \
+                  raise (SIGPIPE);                                            \
+                  /* If it is currently blocked or ignored, change errno from \
+                     EINVAL to EPIPE.  */                                     \
+                  errno = EPIPE;                                              \
+                }                                                             \
+            }                                                                 \
+          else
+#  else
+#   define CLEAR_LastError
+#   define HANDLE_ERROR_NO_DATA
+#  endif
+
+#  define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
+  if (ferror (stream))                                                        \
+    return (EXPRESSION);                                                      \
+  else                                                                        \
+    {                                                                         \
+      RETTYPE ret;                                                            \
+      CLEAR_ERRNO                                                             \
+      CLEAR_LastError                                                         \
+      ret = (EXPRESSION);                                                     \
+      if (FAILED)                                                             \
+        {                                                                     \
+          HANDLE_ENOSPC                                                       \
+          HANDLE_ERROR_NO_DATA                                                \
+          ;                                                                   \
+        }                                                                     \
+      return ret;                                                             \
+    }
+
+#  if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
+int
+printf (const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfprintf (stdout, format, args);
+  va_end (args);
+
+  return retval;
+}
+#  endif
+
+#  if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
+int
+fprintf (FILE *stream, const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfprintf (stream, format, args);
+  va_end (args);
+
+  return retval;
+}
+#  endif
+
+#  if !REPLACE_VPRINTF_POSIX /* avoid collision with vprintf.c */
+int
+vprintf (const char *format, va_list args)
+{
+  return vfprintf (stdout, format, args);
+}
+#  endif
+
+#  if !REPLACE_VFPRINTF_POSIX /* avoid collision with vfprintf.c */
+int
+vfprintf (FILE *stream, const char *format, va_list args)
+#undef vfprintf
+{
+  CALL_WITH_SIGPIPE_EMULATION (int, vfprintf (stream, format, args), ret == EOF)
+}
+#  endif
+
+int
+putchar (int c)
+{
+  return fputc (c, stdout);
+}
+
+int
+fputc (int c, FILE *stream)
+#undef fputc
+{
+  CALL_WITH_SIGPIPE_EMULATION (int, fputc (c, stream), ret == EOF)
+}
+
+int
+fputs (const char *string, FILE *stream)
+#undef fputs
+{
+  CALL_WITH_SIGPIPE_EMULATION (int, fputs (string, stream), ret == EOF)
+}
+
+int
+puts (const char *string)
+#undef puts
+{
+  FILE *stream = stdout;
+  CALL_WITH_SIGPIPE_EMULATION (int, puts (string), ret == EOF)
+}
+
+size_t
+fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
+#undef fwrite
+{
+  CALL_WITH_SIGPIPE_EMULATION (size_t, fwrite (ptr, s, n, stream), ret < n)
+}
+
+# endif
+#endif
diff --git a/gnulib/import/sys_ioctl.in.h b/gnulib/import/sys_ioctl.in.h
new file mode 100644
index 000000000000..12c2cce8f1c8
--- /dev/null
+++ b/gnulib/import/sys_ioctl.in.h
@@ -0,0 +1,79 @@
+/* Substitute for and wrapper around <sys/ioctl.h>.
+   Copyright (C) 2008-2021 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, 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 <https://www.gnu.org/licenses/>.  */
+
+#ifndef _@GUARD_PREFIX@_SYS_IOCTL_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_SYS_IOCTL_H@
+# @INCLUDE_NEXT@ @NEXT_SYS_IOCTL_H@
+#endif
+
+#ifndef _@GUARD_PREFIX@_SYS_IOCTL_H
+#define _@GUARD_PREFIX@_SYS_IOCTL_H
+
+/* AIX 5.1 and Solaris 10 declare ioctl() in <unistd.h> and in <stropts.h>,
+   but not in <sys/ioctl.h>.
+   Haiku declares ioctl() in <unistd.h>, but not in <sys/ioctl.h>.
+   But avoid namespace pollution on glibc systems.  */
+#ifndef __GLIBC__
+# include <unistd.h>
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+
+/* Declare overridden functions.  */
+
+#if @GNULIB_IOCTL@
+# if @REPLACE_IOCTL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef ioctl
+#   define ioctl rpl_ioctl
+#  endif
+_GL_FUNCDECL_RPL (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+_GL_CXXALIAS_RPL (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+# else
+#  if @SYS_IOCTL_H_HAVE_WINSOCK2_H@ || 1
+_GL_FUNCDECL_SYS (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+#  endif
+_GL_CXXALIAS_SYS (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+# endif
+_GL_CXXALIASWARN (ioctl);
+#elif @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
+# undef ioctl
+# define ioctl ioctl_used_without_requesting_gnulib_module_ioctl
+#elif defined GNULIB_POSIXCHECK
+# undef ioctl
+# if HAVE_RAW_DECL_IOCTL
+_GL_WARN_ON_USE (ioctl, "ioctl does not portably work on sockets - "
+                 "use gnulib module ioctl for portability");
+# endif
+#endif
+
+
+#endif /* _@GUARD_PREFIX@_SYS_IOCTL_H */
+#endif /* _@GUARD_PREFIX@_SYS_IOCTL_H */
diff --git a/gnulib/update-gnulib.sh b/gnulib/update-gnulib.sh
index f0f83432b6a4..c77091f4caf8 100755
--- a/gnulib/update-gnulib.sh
+++ b/gnulib/update-gnulib.sh
@@ -60,6 +60,7 @@ IMPORTED_GNULIB_MODULES="\
     mkdtemp \
     mkostemp \
     netdb \
+    nonblocking \
     pathmax \
     rawmemchr \
     readlink \
-- 
2.33.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] sim: use gnulib to set nonblocking mode
  2021-09-09  6:38 [PATCH 1/2] gnulib: import nonblocking module Mike Frysinger
@ 2021-09-09  6:38 ` Mike Frysinger
  2021-09-09  7:24   ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2021-09-09  6:38 UTC (permalink / raw)
  To: gdb-patches

Replace various custom ad-hoc fcntl/O_NONBLOCK implementations with
the gnulib nonblocking module.  This makes our code much tidier and
portable to other systems (e.g. Windows).
---
 sim/bfin/dv-bfin_emac.c |  5 +++--
 sim/common/dv-sockser.c | 11 +++--------
 sim/common/sim-io.c     | 22 +++++++---------------
 sim/ppc/main.c          | 20 ++++++--------------
 4 files changed, 19 insertions(+), 39 deletions(-)

diff --git a/sim/bfin/dv-bfin_emac.c b/sim/bfin/dv-bfin_emac.c
index e5ceedbef514..b53191d3838a 100644
--- a/sim/bfin/dv-bfin_emac.c
+++ b/sim/bfin/dv-bfin_emac.c
@@ -35,6 +35,8 @@
 #include <linux/if_tun.h>
 #endif
 
+#include "nonblocking.h"
+
 #ifdef HAVE_LINUX_IF_TUN_H
 # define WITH_TUN 1
 #else
@@ -570,8 +572,7 @@ bfin_emac_tap_init (struct hw *me)
       return;
     }
 
-  flags = fcntl (emac->tap, F_GETFL);
-  fcntl (emac->tap, F_SETFL, flags | O_NONBLOCK);
+  set_nonblocking_flag (emac->tap, true);
 #endif
 }
 
diff --git a/sim/common/dv-sockser.c b/sim/common/dv-sockser.c
index 477e8f681af7..5423765c66a3 100644
--- a/sim/common/dv-sockser.c
+++ b/sim/common/dv-sockser.c
@@ -24,9 +24,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <string.h>
 #include <signal.h>
 #include <stdlib.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -40,6 +37,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <sys/select.h>
 #include <sys/socket.h>
 
+#include "nonblocking.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 #include "sim-options.h"
@@ -256,17 +255,13 @@ connected_p (SIM_DESC sd)
     return 0;
 
   /* Set non-blocking i/o.  */
-#if defined(F_GETFL) && defined(O_NONBLOCK)
-  flags = fcntl (sockser_fd, F_GETFL);
-  flags |= O_NONBLOCK;
-  if (fcntl (sockser_fd, F_SETFL, flags) == -1)
+  if (set_nonblocking_flag (sockser_fd, true))
     {
       sim_io_eprintf (sd, "unable to set nonblocking i/o");
       close (sockser_fd);
       sockser_fd = -1;
       return 0;
     }
-#endif
   return 1;
 }
 
diff --git a/sim/common/sim-io.c b/sim/common/sim-io.c
index a5a7ff17b067..9398cba57233 100644
--- a/sim/common/sim-io.c
+++ b/sim/common/sim-io.c
@@ -22,15 +22,14 @@
 /* This must come before any other includes.  */
 #include "defs.h"
 
+#include "nonblocking.h"
+
 #include "sim-main.h"
 #include "sim-io.h"
 #include "sim/callback.h"
 #include "targ-vals.h"
 
 #include <errno.h>
-#if HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
 
 #if HAVE_UNISTD_H
 #include <unistd.h>
@@ -350,23 +349,20 @@ sim_io_poll_read (SIM_DESC sd,
 		  char *buf,
 		  int sizeof_buf)
 {
-#if defined(O_NONBLOCK) && defined(F_GETFL) && defined(F_SETFL)
   int fd = STATE_CALLBACK (sd)->fdmap[sim_io_fd];
-  int flags;
   int status;
   int nr_read;
   int result;
   STATE_CALLBACK (sd)->last_errno = 0;
   /* get the old status */
-  flags = fcntl (fd, F_GETFL, 0);
-  if (flags == -1)
+  status = get_nonblocking_flag (fd);
+  if (status == -1)
     {
-      perror ("sim_io_poll_read");
+      perror ("sim_io_read_stdin");
       return 0;
     }
   /* temp, disable blocking IO */
-  status = fcntl (fd, F_SETFL, flags | O_NONBLOCK);
-  if (status == -1)
+  if (status == 0 && set_nonblocking_flag (fd, true) == -1)
     {
       perror ("sim_io_read_stdin");
       return 0;
@@ -384,16 +380,12 @@ sim_io_poll_read (SIM_DESC sd,
       STATE_CALLBACK (sd)->last_errno = errno;
     }
   /* return to regular vewing */
-  status = fcntl (fd, F_SETFL, flags);
-  if (status == -1)
+  if (status == 0 && set_nonblocking_flag (fd, false) == -1)
     {
       perror ("sim_io_read_stdin");
       /* return 0; */
     }
   return result;
-#else
-  return sim_io_read (sd, sim_io_fd, buf, sizeof_buf);
-#endif
 }
 
 int
diff --git a/sim/ppc/main.c b/sim/ppc/main.c
index d9a40700973d..f64b163afea7 100644
--- a/sim/ppc/main.c
+++ b/sim/ppc/main.c
@@ -26,6 +26,8 @@
 
 #include <signal.h>
 
+#include "nonblocking.h"
+
 #include "psim.h"
 #include "options.h"
 #include "device.h" /* FIXME: psim should provide the interface */
@@ -42,11 +44,6 @@
 #include <string.h>
 #include <errno.h>
 
-#if !defined(O_NONBLOCK) || !defined(F_GETFL) || !defined(F_SETFL)
-#undef WITH_STDIO
-#define WITH_STDIO DO_USE_STDIO
-#endif
-
 
 extern char **environ;
 
@@ -152,22 +149,19 @@ sim_io_read_stdin(char *buf,
     return sim_io_eof;
     break;
   case DONT_USE_STDIO:
-#if defined(O_NONBLOCK) && defined(F_GETFL) && defined(F_SETFL)
     {
       /* check for input */
-      int flags;
       int status;
       int nr_read;
       int result;
       /* get the old status */
-      flags = fcntl(0, F_GETFL, 0);
-      if (flags == -1) {
+      status = get_nonblocking_flag (0);
+      if (status == -1) {
 	perror("sim_io_read_stdin");
 	return sim_io_eof;
       }
       /* temp, disable blocking IO */
-      status = fcntl(0, F_SETFL, flags | O_NONBLOCK);
-      if (status == -1) {
+      if (status == 0 && set_nonblocking_flag (0, true) == -1) {
 	perror("sim_io_read_stdin");
 	return sim_io_eof;
       }
@@ -185,15 +179,13 @@ sim_io_read_stdin(char *buf,
 	  result = sim_io_eof;
       }
       /* return to regular vewing */
-      status = fcntl(0, F_SETFL, flags);
-      if (status == -1) {
+      if (status == 0 && set_nonblocking_flag (0, false) == -1) {
 	perror("sim_io_read_stdin");
 	return sim_io_eof;
       }
       return result;
     }
     break;
-#endif
   default:
     error("sim_io_read_stdin: invalid switch\n");
     break;
-- 
2.33.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] sim: use gnulib to set nonblocking mode
  2021-09-09  6:38 ` [PATCH 2/2] sim: use gnulib to set nonblocking mode Mike Frysinger
@ 2021-09-09  7:24   ` Eli Zaretskii
  2021-09-09  7:33     ` Mike Frysinger
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2021-09-09  7:24 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: gdb-patches

> Date: Thu,  9 Sep 2021 02:38:36 -0400
> From: Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org>
> 
> Replace various custom ad-hoc fcntl/O_NONBLOCK implementations with
> the gnulib nonblocking module.  This makes our code much tidier and
> portable to other systems (e.g. Windows).

I'm not familiar with the sim's code, but Gnulib AFAIK supports
non-blocking flag on MinGW only for named pipes and sockets, not for
real files.  Are all the file descriptors in the places where you make
the changes of one of those kinds?  E.g., I see the fcntl calls on
file descriptor zero in some places.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] sim: use gnulib to set nonblocking mode
  2021-09-09  7:24   ` Eli Zaretskii
@ 2021-09-09  7:33     ` Mike Frysinger
  2021-09-09  7:44       ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2021-09-09  7:33 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 871 bytes --]

On 09 Sep 2021 10:24, Eli Zaretskii wrote:
> > Date: Thu,  9 Sep 2021 02:38:36 -0400
> > From: Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org>
> > 
> > Replace various custom ad-hoc fcntl/O_NONBLOCK implementations with
> > the gnulib nonblocking module.  This makes our code much tidier and
> > portable to other systems (e.g. Windows).
> 
> I'm not familiar with the sim's code, but Gnulib AFAIK supports
> non-blocking flag on MinGW only for named pipes and sockets, not for
> real files.  Are all the file descriptors in the places where you make
> the changes of one of those kinds?  E.g., I see the fcntl calls on
> file descriptor zero in some places.

sim only uses nonblocking on sockets or tty's (e.g. stdin), not files on disk.
i don't know offhand about the specifics of Windows stdio and whether those are
actually pipes.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] sim: use gnulib to set nonblocking mode
  2021-09-09  7:33     ` Mike Frysinger
@ 2021-09-09  7:44       ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2021-09-09  7:44 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: gdb-patches

> Date: Thu, 9 Sep 2021 03:33:23 -0400
> From: Mike Frysinger <vapier@gentoo.org>
> Cc: gdb-patches@sourceware.org
> 
> > I'm not familiar with the sim's code, but Gnulib AFAIK supports
> > non-blocking flag on MinGW only for named pipes and sockets, not for
> > real files.  Are all the file descriptors in the places where you make
> > the changes of one of those kinds?  E.g., I see the fcntl calls on
> > file descriptor zero in some places.
> 
> sim only uses nonblocking on sockets or tty's (e.g. stdin), not files on disk.
> i don't know offhand about the specifics of Windows stdio and whether those are
> actually pipes.

I don't think Gnulib's set_nonblocking_flag works on descriptors for
the console devices, so I think the code should be prepared to see
ENOSYS and ENOTSUP in errno in those cases.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] gnulib: import nonblocking module
@ 2021-09-04  7:49 Mike Frysinger
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2021-09-04  7:49 UTC (permalink / raw)
  To: gdb-patches

This provides a portable API for managing O_NONBLOCK settings.
---
 gnulib/Makefile.in                 |  12 +
 gnulib/aclocal.m4                  |   4 +
 gnulib/config.in                   |  20 ++
 gnulib/configure                   | 390 +++++++++++++++++++++++++++++
 gnulib/import/Makefile.am          |  52 ++++
 gnulib/import/Makefile.in          | 137 ++++++----
 gnulib/import/ioctl.c              |  92 +++++++
 gnulib/import/m4/asm-underscore.m4 |  83 ++++++
 gnulib/import/m4/gnulib-cache.m4   |   2 +
 gnulib/import/m4/gnulib-comp.m4    |  31 +++
 gnulib/import/m4/ioctl.m4          |  44 ++++
 gnulib/import/m4/nonblocking.m4    |  29 +++
 gnulib/import/m4/sys_ioctl_h.m4    |  64 +++++
 gnulib/import/nonblocking.c        | 163 ++++++++++++
 gnulib/import/nonblocking.h        |  62 +++++
 gnulib/import/stdio-read.c         | 168 +++++++++++++
 gnulib/import/stdio-write.c        | 206 +++++++++++++++
 gnulib/import/sys_ioctl.in.h       |  79 ++++++
 gnulib/update-gnulib.sh            |   1 +
 19 files changed, 1592 insertions(+), 47 deletions(-)
 create mode 100644 gnulib/import/ioctl.c
 create mode 100644 gnulib/import/m4/asm-underscore.m4
 create mode 100644 gnulib/import/m4/ioctl.m4
 create mode 100644 gnulib/import/m4/nonblocking.m4
 create mode 100644 gnulib/import/m4/sys_ioctl_h.m4
 create mode 100644 gnulib/import/nonblocking.c
 create mode 100644 gnulib/import/nonblocking.h
 create mode 100644 gnulib/import/stdio-read.c
 create mode 100644 gnulib/import/stdio-write.c
 create mode 100644 gnulib/import/sys_ioctl.in.h

diff --git a/gnulib/Makefile.in b/gnulib/Makefile.in
index af264c3c12de..4868d7253760 100644
--- a/gnulib/Makefile.in
+++ b/gnulib/Makefile.in
@@ -117,6 +117,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/absolute-header.m4 \
 	$(top_srcdir)/import/m4/alloca.m4 \
 	$(top_srcdir)/import/m4/arpa_inet_h.m4 \
+	$(top_srcdir)/import/m4/asm-underscore.m4 \
 	$(top_srcdir)/import/m4/btowc.m4 \
 	$(top_srcdir)/import/m4/builtin-expect.m4 \
 	$(top_srcdir)/import/m4/canonicalize.m4 \
@@ -177,6 +178,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/include_next.m4 \
 	$(top_srcdir)/import/m4/inet_ntop.m4 \
 	$(top_srcdir)/import/m4/inttypes.m4 \
+	$(top_srcdir)/import/m4/ioctl.m4 \
 	$(top_srcdir)/import/m4/isblank.m4 \
 	$(top_srcdir)/import/m4/isnand.m4 \
 	$(top_srcdir)/import/m4/isnanl.m4 \
@@ -213,6 +215,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/netdb_h.m4 \
 	$(top_srcdir)/import/m4/netinet_in_h.m4 \
 	$(top_srcdir)/import/m4/nocrash.m4 \
+	$(top_srcdir)/import/m4/nonblocking.m4 \
 	$(top_srcdir)/import/m4/off_t.m4 \
 	$(top_srcdir)/import/m4/open-cloexec.m4 \
 	$(top_srcdir)/import/m4/open-slash.m4 \
@@ -258,6 +261,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/strnlen.m4 \
 	$(top_srcdir)/import/m4/strstr.m4 \
 	$(top_srcdir)/import/m4/strtok_r.m4 \
+	$(top_srcdir)/import/m4/sys_ioctl_h.m4 \
 	$(top_srcdir)/import/m4/sys_random_h.m4 \
 	$(top_srcdir)/import/m4/sys_select_h.m4 \
 	$(top_srcdir)/import/m4/sys_socket_h.m4 \
@@ -355,6 +359,7 @@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
 APPLE_UNIVERSAL_BUILD = @APPLE_UNIVERSAL_BUILD@
 AR = @AR@
 ARFLAGS = @ARFLAGS@
+ASM_SYMBOL_PREFIX = @ASM_SYMBOL_PREFIX@
 AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
@@ -539,6 +544,7 @@ GNULIB_IMAXABS = @GNULIB_IMAXABS@
 GNULIB_IMAXDIV = @GNULIB_IMAXDIV@
 GNULIB_INET_NTOP = @GNULIB_INET_NTOP@
 GNULIB_INET_PTON = @GNULIB_INET_PTON@
+GNULIB_IOCTL = @GNULIB_IOCTL@
 GNULIB_ISATTY = @GNULIB_ISATTY@
 GNULIB_ISBLANK = @GNULIB_ISBLANK@
 GNULIB_ISFINITE = @GNULIB_ISFINITE@
@@ -1167,6 +1173,7 @@ HAVE_SYMLINK = @HAVE_SYMLINK@
 HAVE_SYMLINKAT = @HAVE_SYMLINKAT@
 HAVE_SYS_BITYPES_H = @HAVE_SYS_BITYPES_H@
 HAVE_SYS_INTTYPES_H = @HAVE_SYS_INTTYPES_H@
+HAVE_SYS_IOCTL_H = @HAVE_SYS_IOCTL_H@
 HAVE_SYS_LOADAVG_H = @HAVE_SYS_LOADAVG_H@
 HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@
 HAVE_SYS_RANDOM_H = @HAVE_SYS_RANDOM_H@
@@ -1302,6 +1309,7 @@ NEXT_AS_FIRST_DIRECTIVE_STDIO_H = @NEXT_AS_FIRST_DIRECTIVE_STDIO_H@
 NEXT_AS_FIRST_DIRECTIVE_STDLIB_H = @NEXT_AS_FIRST_DIRECTIVE_STDLIB_H@
 NEXT_AS_FIRST_DIRECTIVE_STRINGS_H = @NEXT_AS_FIRST_DIRECTIVE_STRINGS_H@
 NEXT_AS_FIRST_DIRECTIVE_STRING_H = @NEXT_AS_FIRST_DIRECTIVE_STRING_H@
+NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H@
@@ -1334,6 +1342,7 @@ NEXT_STDIO_H = @NEXT_STDIO_H@
 NEXT_STDLIB_H = @NEXT_STDLIB_H@
 NEXT_STRINGS_H = @NEXT_STRINGS_H@
 NEXT_STRING_H = @NEXT_STRING_H@
+NEXT_SYS_IOCTL_H = @NEXT_SYS_IOCTL_H@
 NEXT_SYS_RANDOM_H = @NEXT_SYS_RANDOM_H@
 NEXT_SYS_SELECT_H = @NEXT_SYS_SELECT_H@
 NEXT_SYS_SOCKET_H = @NEXT_SYS_SOCKET_H@
@@ -1464,6 +1473,7 @@ REPLACE_ILOGBL = @REPLACE_ILOGBL@
 REPLACE_INET_NTOP = @REPLACE_INET_NTOP@
 REPLACE_INET_PTON = @REPLACE_INET_PTON@
 REPLACE_INITSTATE = @REPLACE_INITSTATE@
+REPLACE_IOCTL = @REPLACE_IOCTL@
 REPLACE_ISATTY = @REPLACE_ISATTY@
 REPLACE_ISFINITE = @REPLACE_ISFINITE@
 REPLACE_ISINF = @REPLACE_ISINF@
@@ -1635,6 +1645,8 @@ STDBOOL_H = @STDBOOL_H@
 STDDEF_H = @STDDEF_H@
 STDINT_H = @STDINT_H@
 STRIP = @STRIP@
+SYS_IOCTL_H_HAVE_WINSOCK2_H = @SYS_IOCTL_H_HAVE_WINSOCK2_H@
+SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS = @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC = @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
 TIME_H_DEFINES_STRUCT_TIMESPEC = @TIME_H_DEFINES_STRUCT_TIMESPEC@
 TIME_H_DEFINES_TIME_UTC = @TIME_H_DEFINES_TIME_UTC@
diff --git a/gnulib/aclocal.m4 b/gnulib/aclocal.m4
index c03dc8bcafa7..bc3a30278b5d 100644
--- a/gnulib/aclocal.m4
+++ b/gnulib/aclocal.m4
@@ -1189,6 +1189,7 @@ m4_include([import/m4/__inline.m4])
 m4_include([import/m4/absolute-header.m4])
 m4_include([import/m4/alloca.m4])
 m4_include([import/m4/arpa_inet_h.m4])
+m4_include([import/m4/asm-underscore.m4])
 m4_include([import/m4/btowc.m4])
 m4_include([import/m4/builtin-expect.m4])
 m4_include([import/m4/canonicalize.m4])
@@ -1250,6 +1251,7 @@ m4_include([import/m4/gnulib-comp.m4])
 m4_include([import/m4/include_next.m4])
 m4_include([import/m4/inet_ntop.m4])
 m4_include([import/m4/inttypes.m4])
+m4_include([import/m4/ioctl.m4])
 m4_include([import/m4/isblank.m4])
 m4_include([import/m4/isnand.m4])
 m4_include([import/m4/isnanl.m4])
@@ -1286,6 +1288,7 @@ m4_include([import/m4/multiarch.m4])
 m4_include([import/m4/netdb_h.m4])
 m4_include([import/m4/netinet_in_h.m4])
 m4_include([import/m4/nocrash.m4])
+m4_include([import/m4/nonblocking.m4])
 m4_include([import/m4/off_t.m4])
 m4_include([import/m4/open-cloexec.m4])
 m4_include([import/m4/open-slash.m4])
@@ -1331,6 +1334,7 @@ m4_include([import/m4/strings_h.m4])
 m4_include([import/m4/strnlen.m4])
 m4_include([import/m4/strstr.m4])
 m4_include([import/m4/strtok_r.m4])
+m4_include([import/m4/sys_ioctl_h.m4])
 m4_include([import/m4/sys_random_h.m4])
 m4_include([import/m4/sys_select_h.m4])
 m4_include([import/m4/sys_socket_h.m4])
diff --git a/gnulib/config.in b/gnulib/config.in
index dd960bf6e0b6..5863675b8ec7 100644
--- a/gnulib/config.in
+++ b/gnulib/config.in
@@ -119,6 +119,10 @@
    whether the gnulib module msvc-nothrow shall be considered present. */
 #undef GNULIB_MSVC_NOTHROW
 
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+   whether the gnulib module nonblocking shall be considered present. */
+#undef GNULIB_NONBLOCKING
+
 /* Define to a C preprocessor expression that evaluates to 1 or 0, depending
    whether the gnulib module openat shall be considered present. */
 #undef GNULIB_OPENAT
@@ -237,6 +241,9 @@
 /* Define to 1 when the gnulib module glob should be tested. */
 #undef GNULIB_TEST_GLOB
 
+/* Define to 1 when the gnulib module ioctl should be tested. */
+#undef GNULIB_TEST_IOCTL
+
 /* Define to 1 when the gnulib module listen should be tested. */
 #undef GNULIB_TEST_LISTEN
 
@@ -279,6 +286,9 @@
 /* Define to 1 when the gnulib module mkostemp should be tested. */
 #undef GNULIB_TEST_MKOSTEMP
 
+/* Define to 1 when the gnulib module nonblocking should be tested. */
+#undef GNULIB_TEST_NONBLOCKING
+
 /* Define to 1 when the gnulib module open should be tested. */
 #undef GNULIB_TEST_OPEN
 
@@ -643,6 +653,9 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
+/* Define to 1 if you have the `ioctl' function. */
+#undef HAVE_IOCTL
+
 /* Define to 1 if <sys/socket.h> defines AF_INET. */
 #undef HAVE_IPV4
 
@@ -892,6 +905,9 @@
 /* Define to 1 if you have the <sys/inttypes.h> header file. */
 #undef HAVE_SYS_INTTYPES_H
 
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#undef HAVE_SYS_IOCTL_H
+
 /* Define to 1 if you have the <sys/mman.h> header file. */
 #undef HAVE_SYS_MMAN_H
 
@@ -1167,6 +1183,10 @@
    timespec. */
 #undef TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC
 
+/* Define to the prefix of C symbols at the assembler and linker level, either
+   an underscore or empty. */
+#undef USER_LABEL_PREFIX
+
 /* Define if the combination of the ISO C and POSIX multithreading APIs can be
    used. */
 #undef USE_ISOC_AND_POSIX_THREADS
diff --git a/gnulib/configure b/gnulib/configure
index 39555afe9f01..54e1f19115f1 100644
--- a/gnulib/configure
+++ b/gnulib/configure
@@ -745,6 +745,9 @@ NEXT_SYS_TYPES_H
 HAVE_SYS_RANDOM_H
 NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H
 NEXT_SYS_RANDOM_H
+NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H
+NEXT_SYS_IOCTL_H
+HAVE_SYS_IOCTL_H
 HAVE_STRINGS_H
 NEXT_AS_FIRST_DIRECTIVE_STRINGS_H
 NEXT_STRINGS_H
@@ -789,6 +792,7 @@ REPLACE_PSELECT
 HAVE_PSELECT
 GNULIB_SELECT
 GNULIB_PSELECT
+ASM_SYMBOL_PREFIX
 GL_GENERATE_NETINET_IN_H_FALSE
 GL_GENERATE_NETINET_IN_H_TRUE
 NETINET_IN_H
@@ -1745,6 +1749,10 @@ GL_GENERATE_ALLOCA_H_TRUE
 ALLOCA_H
 ALLOCA
 HAVE_WINSOCK2_H
+REPLACE_IOCTL
+SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS
+SYS_IOCTL_H_HAVE_WINSOCK2_H
+GNULIB_IOCTL
 UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS
 UNISTD_H_HAVE_WINSOCK2_H
 UNISTD_H_HAVE_SYS_RANDOM_H
@@ -3803,6 +3811,7 @@ as_fn_append ac_func_list " __xpg_strerror_r"
 as_fn_append ac_func_list " catgets"
 as_fn_append ac_func_list " snprintf"
 as_fn_append ac_header_list " strings.h"
+as_fn_append ac_header_list " sys/ioctl.h"
 as_fn_append ac_header_list " sys/random.h"
 as_fn_append ac_header_list " sys/uio.h"
 as_fn_append ac_header_list " sys/wait.h"
@@ -6781,6 +6790,7 @@ fi
   # Code from module intprops:
   # Code from module inttypes:
   # Code from module inttypes-incomplete:
+  # Code from module ioctl:
   # Code from module isblank:
   # Code from module isnand-nolibm:
   # Code from module isnanl-nolibm:
@@ -6815,6 +6825,7 @@ fi
   # Code from module netdb:
   # Code from module netinet_in:
   # Code from module nocrash:
+  # Code from module nonblocking:
   # Code from module open:
   # Code from module openat:
   # Code from module openat-die:
@@ -6868,6 +6879,7 @@ fi
   # Code from module strstr:
   # Code from module strstr-simple:
   # Code from module strtok_r:
+  # Code from module sys_ioctl:
   # Code from module sys_random:
   # Code from module sys_select:
   # Code from module sys_socket:
@@ -7297,6 +7309,13 @@ $as_echo "$gl_cv_source_line_length_unlimited" >&6; }
   UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
 
 
+
+  GNULIB_IOCTL=0;
+    SYS_IOCTL_H_HAVE_WINSOCK2_H=0;
+  SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
+
+  REPLACE_IOCTL=0;
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
 $as_echo_n "checking for C/C++ restrict keyword... " >&6; }
 if ${ac_cv_c_restrict+:} false; then :
@@ -16428,6 +16447,97 @@ $as_echo "#define HAVE_MINMAX_IN_SYS_PARAM_H 1" >>confdefs.h
   REPLACE_GETADDRINFO=0;
 
 
+
+  case "$host_os" in
+    mingw*) gl_cv_have_nonblocking=no ;;
+    *)      gl_cv_have_nonblocking=yes ;;
+  esac
+  case "$host_os" in
+    mingw*) gl_cv_have_open_O_NONBLOCK=no ;;
+    *)      gl_cv_have_open_O_NONBLOCK=yes ;;
+  esac
+
+
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#ifdef _MSC_VER
+MicrosoftCompiler
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "MicrosoftCompiler" >/dev/null 2>&1; then :
+            rm -f conftest*
+     echo 'int dummy;' > conftest.c
+     { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; } >/dev/null 2>&1
+     if test -f conftest.o; then
+       gl_asmext='s'
+       gl_c_asm_opt='-S'
+     else
+       gl_asmext='asm'
+       gl_c_asm_opt='-c -Fa'
+     fi
+     rm -f conftest*
+
+else
+  gl_asmext='s'
+     gl_c_asm_opt='-S'
+
+fi
+rm -f conftest*
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C symbols are prefixed with underscore at the linker level" >&5
+$as_echo_n "checking whether C symbols are prefixed with underscore at the linker level... " >&6; }
+if ${gl_cv_prog_as_underscore+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat > conftest.c <<EOF
+#ifdef __cplusplus
+extern "C" int foo (void);
+#endif
+int foo(void) { return 0; }
+EOF
+     # Look for the assembly language name in the .s file.
+     { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; } >/dev/null 2>&1
+     if LC_ALL=C $EGREP '(^|[^a-zA-Z0-9_])_foo([^a-zA-Z0-9_]|$)' conftest.$gl_asmext >/dev/null; then
+       gl_cv_prog_as_underscore=yes
+     else
+       gl_cv_prog_as_underscore=no
+     fi
+     rm -f conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_prog_as_underscore" >&5
+$as_echo "$gl_cv_prog_as_underscore" >&6; }
+  if test $gl_cv_prog_as_underscore = yes; then
+    USER_LABEL_PREFIX=_
+  else
+    USER_LABEL_PREFIX=
+  fi
+
+cat >>confdefs.h <<_ACEOF
+#define USER_LABEL_PREFIX $USER_LABEL_PREFIX
+_ACEOF
+
+  ASM_SYMBOL_PREFIX='"'${USER_LABEL_PREFIX}'"'
+
+
+
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for O_CLOEXEC" >&5
 $as_echo_n "checking for O_CLOEXEC... " >&6; }
 if ${gl_cv_macro_O_CLOEXEC+:} false; then :
@@ -17686,6 +17796,8 @@ _ACEOF
 
 
 
+
+
 $as_echo "#define _USE_STD_STAT 1" >>confdefs.h
 
 
@@ -23248,6 +23360,91 @@ $as_echo "$gl_cv_test_UINT64_MAX_EQ_ULONG_MAX" >&6; }
 
 
 
+  HAVE_IOCTL=1
+  if test "$ac_cv_header_winsock2_h" = yes; then
+                HAVE_IOCTL=0
+  else
+    for ac_func in ioctl
+do :
+  ac_fn_c_check_func "$LINENO" "ioctl" "ac_cv_func_ioctl"
+if test "x$ac_cv_func_ioctl" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_IOCTL 1
+_ACEOF
+
+fi
+done
+
+                { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ioctl with POSIX signature" >&5
+$as_echo_n "checking for ioctl with POSIX signature... " >&6; }
+if ${gl_cv_func_ioctl_posix_signature+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/ioctl.h>
+              /* On some platforms, ioctl() is declared in <unistd.h>.  */
+              #include <unistd.h>
+
+int
+main ()
+{
+extern
+              #ifdef __cplusplus
+              "C"
+              #endif
+              int ioctl (int, int, ...);
+
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_func_ioctl_posix_signature=yes
+else
+  gl_cv_func_ioctl_posix_signature=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_ioctl_posix_signature" >&5
+$as_echo "$gl_cv_func_ioctl_posix_signature" >&6; }
+    if test $gl_cv_func_ioctl_posix_signature != yes; then
+      REPLACE_IOCTL=1
+    fi
+  fi
+
+  if test $HAVE_IOCTL = 0 || test $REPLACE_IOCTL = 1; then
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS ioctl.$ac_objext"
+
+  fi
+
+
+
+
+
+          GNULIB_IOCTL=1
+
+
+
+
+
+$as_echo "#define GNULIB_TEST_IOCTL 1" >>confdefs.h
+
+
+
+
+
+
 
 
   if test $ac_cv_func_isblank = no; then
@@ -27053,6 +27250,36 @@ fi
 
 
 
+
+
+
+
+
+          GNULIB_NONBLOCKING=1
+
+
+
+
+
+$as_echo "#define GNULIB_TEST_NONBLOCKING 1" >>confdefs.h
+
+
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define GNULIB_NONBLOCKING 1
+_ACEOF
+
+
+
+
+  GNULIB_STDIO_H_NONBLOCKING=1
+
+  GNULIB_UNISTD_H_NONBLOCKING=1
+
+
+
   case "$host_os" in
     mingw* | pw*)
       REPLACE_OPEN=1
@@ -27151,6 +27378,15 @@ $as_echo "#define OPEN_TRAILING_SLASH_BUG 1" >>confdefs.h
     fi
 
 
+    if test $REPLACE_OPEN = 0; then
+
+
+
+      if test $gl_cv_have_open_O_NONBLOCK != yes; then
+        REPLACE_OPEN=1
+      fi
+    fi
+
 
   if test $REPLACE_OPEN = 1; then
 
@@ -29688,6 +29924,23 @@ _ACEOF
   GNULIB_FREAD=1
 
 
+
+
+    if test $gl_cv_have_nonblocking != yes; then
+      REPLACE_STDIO_READ_FUNCS=1
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS stdio-read.$ac_objext"
+
+    fi
+
+
       GNULIB_FPRINTF=1
   GNULIB_PRINTF=1
   GNULIB_VFPRINTF=1
@@ -29703,6 +29956,23 @@ _ACEOF
 
 
 
+    if test $gl_cv_have_nonblocking != yes; then
+      REPLACE_STDIO_WRITE_FUNCS=1
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS stdio-write.$ac_objext"
+
+    fi
+
+
+
+
 
 
 
@@ -30607,6 +30877,126 @@ $as_echo "#define GNULIB_TEST_STRTOK_R 1" >>confdefs.h
 
 
 
+  if test $ac_cv_header_sys_ioctl_h = yes; then
+    HAVE_SYS_IOCTL_H=1
+            { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether <sys/ioctl.h> declares ioctl" >&5
+$as_echo_n "checking whether <sys/ioctl.h> declares ioctl... " >&6; }
+if ${gl_cv_decl_ioctl_in_sys_ioctl_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+         cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/ioctl.h>
+int
+main ()
+{
+(void) ioctl;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_decl_ioctl_in_sys_ioctl_h=yes
+else
+  gl_cv_decl_ioctl_in_sys_ioctl_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_decl_ioctl_in_sys_ioctl_h" >&5
+$as_echo "$gl_cv_decl_ioctl_in_sys_ioctl_h" >&6; }
+  else
+    HAVE_SYS_IOCTL_H=0
+  fi
+
+
+
+
+
+
+
+
+
+
+     if test $gl_cv_have_include_next = yes; then
+       gl_cv_next_sys_ioctl_h='<'sys/ioctl.h'>'
+     else
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking absolute name of <sys/ioctl.h>" >&5
+$as_echo_n "checking absolute name of <sys/ioctl.h>... " >&6; }
+if ${gl_cv_next_sys_ioctl_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+             if test $ac_cv_header_sys_ioctl_h = yes; then
+
+
+
+
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/ioctl.h>
+_ACEOF
+                case "$host_os" in
+    aix*) gl_absname_cpp="$ac_cpp -C" ;;
+    *)    gl_absname_cpp="$ac_cpp" ;;
+  esac
+
+  case "$host_os" in
+    mingw*)
+                                          gl_dirsep_regex='[/\\]'
+      ;;
+    *)
+      gl_dirsep_regex='\/'
+      ;;
+  esac
+      gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
+  gl_header_literal_regex=`echo 'sys/ioctl.h' \
+                           | sed -e "$gl_make_literal_regex_sed"`
+  gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
+      s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
+      s|^/[^/]|//&|
+      p
+      q
+    }'
+
+        gl_cv_absolute_sys_ioctl_h=`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&5 |
+  sed -n "$gl_absolute_header_sed"`
+
+           gl_header=$gl_cv_absolute_sys_ioctl_h
+           gl_cv_next_sys_ioctl_h='"'$gl_header'"'
+          else
+               gl_cv_next_sys_ioctl_h='<'sys/ioctl.h'>'
+             fi
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_next_sys_ioctl_h" >&5
+$as_echo "$gl_cv_next_sys_ioctl_h" >&6; }
+     fi
+     NEXT_SYS_IOCTL_H=$gl_cv_next_sys_ioctl_h
+
+     if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
+       gl_next_as_first_directive='<'sys/ioctl.h'>'
+     else
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
+       gl_next_as_first_directive=$gl_cv_next_sys_ioctl_h
+     fi
+     NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H=$gl_next_as_first_directive
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
 
 
diff --git a/gnulib/import/Makefile.am b/gnulib/import/Makefile.am
index 5a405cfc3683..685be26bf7b9 100644
--- a/gnulib/import/Makefile.am
+++ b/gnulib/import/Makefile.am
@@ -63,6 +63,7 @@
 #  mkdtemp \
 #  mkostemp \
 #  netdb \
+#  nonblocking \
 #  pathmax \
 #  rawmemchr \
 #  readlink \
@@ -947,6 +948,15 @@ EXTRA_DIST += inttypes.in.h
 
 ## end   gnulib module inttypes-incomplete
 
+## begin gnulib module ioctl
+
+
+EXTRA_DIST += ioctl.c w32sock.h
+
+EXTRA_libgnu_a_SOURCES += ioctl.c
+
+## end   gnulib module ioctl
+
 ## begin gnulib module isblank
 
 
@@ -1603,6 +1613,16 @@ EXTRA_DIST += netinet_in.in.h
 
 ## end   gnulib module netinet_in
 
+## begin gnulib module nonblocking
+
+libgnu_a_SOURCES += nonblocking.c
+
+EXTRA_DIST += nonblocking.h stdio-read.c stdio-write.c
+
+EXTRA_libgnu_a_SOURCES += stdio-read.c stdio-write.c
+
+## end   gnulib module nonblocking
+
 ## begin gnulib module open
 
 
@@ -2539,6 +2559,38 @@ EXTRA_libgnu_a_SOURCES += strtok_r.c
 
 ## end   gnulib module strtok_r
 
+## begin gnulib module sys_ioctl
+
+BUILT_SOURCES += sys/ioctl.h
+
+# We need the following in order to create <sys/ioctl.h> when the system
+# does not have a complete one.
+sys/ioctl.h: sys_ioctl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
+	$(AM_V_at)$(MKDIR_P) sys
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's|@''HAVE_SYS_IOCTL_H''@|$(HAVE_SYS_IOCTL_H)|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_SYS_IOCTL_H''@|$(NEXT_SYS_IOCTL_H)|g' \
+	      -e 's/@''GNULIB_IOCTL''@/$(GNULIB_IOCTL)/g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
+	      -e 's|@''REPLACE_IOCTL''@|$(REPLACE_IOCTL)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/sys_ioctl.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+MOSTLYCLEANFILES += sys/ioctl.h sys/ioctl.h-t
+MOSTLYCLEANDIRS += sys
+
+EXTRA_DIST += sys_ioctl.in.h
+
+## end   gnulib module sys_ioctl
+
 ## begin gnulib module sys_random
 
 BUILT_SOURCES += sys/random.h
diff --git a/gnulib/import/Makefile.in b/gnulib/import/Makefile.in
index 3393458f4e66..990b64186c1f 100644
--- a/gnulib/import/Makefile.in
+++ b/gnulib/import/Makefile.in
@@ -77,6 +77,7 @@
 #  mkdtemp \
 #  mkostemp \
 #  netdb \
+#  nonblocking \
 #  pathmax \
 #  rawmemchr \
 #  readlink \
@@ -188,6 +189,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/absolute-header.m4 \
 	$(top_srcdir)/import/m4/alloca.m4 \
 	$(top_srcdir)/import/m4/arpa_inet_h.m4 \
+	$(top_srcdir)/import/m4/asm-underscore.m4 \
 	$(top_srcdir)/import/m4/btowc.m4 \
 	$(top_srcdir)/import/m4/builtin-expect.m4 \
 	$(top_srcdir)/import/m4/canonicalize.m4 \
@@ -248,6 +250,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/include_next.m4 \
 	$(top_srcdir)/import/m4/inet_ntop.m4 \
 	$(top_srcdir)/import/m4/inttypes.m4 \
+	$(top_srcdir)/import/m4/ioctl.m4 \
 	$(top_srcdir)/import/m4/isblank.m4 \
 	$(top_srcdir)/import/m4/isnand.m4 \
 	$(top_srcdir)/import/m4/isnanl.m4 \
@@ -284,6 +287,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/netdb_h.m4 \
 	$(top_srcdir)/import/m4/netinet_in_h.m4 \
 	$(top_srcdir)/import/m4/nocrash.m4 \
+	$(top_srcdir)/import/m4/nonblocking.m4 \
 	$(top_srcdir)/import/m4/off_t.m4 \
 	$(top_srcdir)/import/m4/open-cloexec.m4 \
 	$(top_srcdir)/import/m4/open-slash.m4 \
@@ -329,6 +333,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/strnlen.m4 \
 	$(top_srcdir)/import/m4/strstr.m4 \
 	$(top_srcdir)/import/m4/strtok_r.m4 \
+	$(top_srcdir)/import/m4/sys_ioctl_h.m4 \
 	$(top_srcdir)/import/m4/sys_random_h.m4 \
 	$(top_srcdir)/import/m4/sys_select_h.m4 \
 	$(top_srcdir)/import/m4/sys_socket_h.m4 \
@@ -374,8 +379,9 @@ am_libgnu_a_OBJECTS = openat-proc.$(OBJEXT) basename-lgpl.$(OBJEXT) \
 	dup-safer-flag.$(OBJEXT) filenamecat-lgpl.$(OBJEXT) \
 	getprogname.$(OBJEXT) hard-locale.$(OBJEXT) \
 	localcharset.$(OBJEXT) glthread/lock.$(OBJEXT) \
-	malloca.$(OBJEXT) math.$(OBJEXT) openat-die.$(OBJEXT) \
-	save-cwd.$(OBJEXT) malloc/scratch_buffer_dupfree.$(OBJEXT) \
+	malloca.$(OBJEXT) math.$(OBJEXT) nonblocking.$(OBJEXT) \
+	openat-die.$(OBJEXT) save-cwd.$(OBJEXT) \
+	malloc/scratch_buffer_dupfree.$(OBJEXT) \
 	malloc/scratch_buffer_grow.$(OBJEXT) \
 	malloc/scratch_buffer_grow_preserve.$(OBJEXT) \
 	malloc/scratch_buffer_set_array_size.$(OBJEXT) \
@@ -464,6 +470,7 @@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
 APPLE_UNIVERSAL_BUILD = @APPLE_UNIVERSAL_BUILD@
 AR = @AR@
 ARFLAGS = @ARFLAGS@
+ASM_SYMBOL_PREFIX = @ASM_SYMBOL_PREFIX@
 AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
@@ -648,6 +655,7 @@ GNULIB_IMAXABS = @GNULIB_IMAXABS@
 GNULIB_IMAXDIV = @GNULIB_IMAXDIV@
 GNULIB_INET_NTOP = @GNULIB_INET_NTOP@
 GNULIB_INET_PTON = @GNULIB_INET_PTON@
+GNULIB_IOCTL = @GNULIB_IOCTL@
 GNULIB_ISATTY = @GNULIB_ISATTY@
 GNULIB_ISBLANK = @GNULIB_ISBLANK@
 GNULIB_ISFINITE = @GNULIB_ISFINITE@
@@ -1276,6 +1284,7 @@ HAVE_SYMLINK = @HAVE_SYMLINK@
 HAVE_SYMLINKAT = @HAVE_SYMLINKAT@
 HAVE_SYS_BITYPES_H = @HAVE_SYS_BITYPES_H@
 HAVE_SYS_INTTYPES_H = @HAVE_SYS_INTTYPES_H@
+HAVE_SYS_IOCTL_H = @HAVE_SYS_IOCTL_H@
 HAVE_SYS_LOADAVG_H = @HAVE_SYS_LOADAVG_H@
 HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@
 HAVE_SYS_RANDOM_H = @HAVE_SYS_RANDOM_H@
@@ -1411,6 +1420,7 @@ NEXT_AS_FIRST_DIRECTIVE_STDIO_H = @NEXT_AS_FIRST_DIRECTIVE_STDIO_H@
 NEXT_AS_FIRST_DIRECTIVE_STDLIB_H = @NEXT_AS_FIRST_DIRECTIVE_STDLIB_H@
 NEXT_AS_FIRST_DIRECTIVE_STRINGS_H = @NEXT_AS_FIRST_DIRECTIVE_STRINGS_H@
 NEXT_AS_FIRST_DIRECTIVE_STRING_H = @NEXT_AS_FIRST_DIRECTIVE_STRING_H@
+NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_IOCTL_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H@
@@ -1443,6 +1453,7 @@ NEXT_STDIO_H = @NEXT_STDIO_H@
 NEXT_STDLIB_H = @NEXT_STDLIB_H@
 NEXT_STRINGS_H = @NEXT_STRINGS_H@
 NEXT_STRING_H = @NEXT_STRING_H@
+NEXT_SYS_IOCTL_H = @NEXT_SYS_IOCTL_H@
 NEXT_SYS_RANDOM_H = @NEXT_SYS_RANDOM_H@
 NEXT_SYS_SELECT_H = @NEXT_SYS_SELECT_H@
 NEXT_SYS_SOCKET_H = @NEXT_SYS_SOCKET_H@
@@ -1573,6 +1584,7 @@ REPLACE_ILOGBL = @REPLACE_ILOGBL@
 REPLACE_INET_NTOP = @REPLACE_INET_NTOP@
 REPLACE_INET_PTON = @REPLACE_INET_PTON@
 REPLACE_INITSTATE = @REPLACE_INITSTATE@
+REPLACE_IOCTL = @REPLACE_IOCTL@
 REPLACE_ISATTY = @REPLACE_ISATTY@
 REPLACE_ISFINITE = @REPLACE_ISFINITE@
 REPLACE_ISINF = @REPLACE_ISINF@
@@ -1744,6 +1756,8 @@ STDBOOL_H = @STDBOOL_H@
 STDDEF_H = @STDDEF_H@
 STDINT_H = @STDINT_H@
 STRIP = @STRIP@
+SYS_IOCTL_H_HAVE_WINSOCK2_H = @SYS_IOCTL_H_HAVE_WINSOCK2_H@
+SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS = @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC = @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
 TIME_H_DEFINES_STRUCT_TIMESPEC = @TIME_H_DEFINES_STRUCT_TIMESPEC@
 TIME_H_DEFINES_TIME_UTC = @TIME_H_DEFINES_TIME_UTC@
@@ -1843,30 +1857,32 @@ EXTRA_DIST = m4/gnulib-cache.m4 accept.c w32sock.h alloca.c \
 	gettimeofday.c $(top_srcdir)/import/extra/gitlog-to-changelog \
 	glob.c glob_internal.h glob_pattern_p.c globfree.c glob-libc.h \
 	glob.in.h hard-locale.h inet_ntop.c intprops.h inttypes.in.h \
-	isblank.c float+.h isnan.c isnand-nolibm.h isnand.c float+.h \
-	isnan.c isnanl-nolibm.h isnanl.c cdefs.h libc-config.h \
-	limits.in.h listen.c w32sock.h localcharset.h locale.in.h \
-	lstat.c malloc.c malloca.h math.in.h lc-charset-dispatch.c \
-	lc-charset-dispatch.h mbrtowc-impl-utf8.h mbrtowc-impl.h \
-	mbrtowc.c mbtowc-lock.c mbtowc-lock.h windows-initguard.h \
-	mbsinit.c mbsrtowcs-impl.h mbsrtowcs-state.c mbsrtowcs.c \
-	mbtowc-impl.h mbtowc.c memchr.c memchr.valgrind memmem.c \
-	memmem.c str-two-way.h mempcpy.c memrchr.c mkdir.c mkdtemp.c \
-	mkostemp.c msvc-inval.c msvc-inval.h msvc-nothrow.c \
-	msvc-nothrow.h netdb.in.h netinet_in.in.h open.c openat.c \
-	openat.h dirent-private.h opendir.c pathmax.h pipe.c \
-	rawmemchr.c rawmemchr.valgrind dirent-private.h readdir.c \
-	readlink.c realloc.c rename.c dirent-private.h rewinddir.c \
-	rmdir.c same-inode.h save-cwd.h malloc/scratch_buffer.h \
-	scratch_buffer.h select.c setenv.c setlocale-lock.c \
-	setlocale_null.h windows-initguard.h setsockopt.c w32sock.h \
-	signal.in.h _Noreturn.h arg-nonnull.h c++defs.h warn-on-use.h \
-	socket.c w32sock.h w32sock.h stat-w32.c stat-w32.h stat.c \
-	stat-time.h stdalign.in.h stdbool.in.h stddef.in.h stdint.in.h \
-	stdio.in.h stdlib.in.h strchrnul.c strchrnul.valgrind strdup.c \
-	streq.h strerror.c strerror-override.c strerror-override.h \
-	strerror_r.c string.in.h strings.in.h strnlen.c strstr.c \
-	str-two-way.h strstr.c strtok_r.c sys_random.in.h \
+	ioctl.c w32sock.h isblank.c float+.h isnan.c isnand-nolibm.h \
+	isnand.c float+.h isnan.c isnanl-nolibm.h isnanl.c cdefs.h \
+	libc-config.h limits.in.h listen.c w32sock.h localcharset.h \
+	locale.in.h lstat.c malloc.c malloca.h math.in.h \
+	lc-charset-dispatch.c lc-charset-dispatch.h \
+	mbrtowc-impl-utf8.h mbrtowc-impl.h mbrtowc.c mbtowc-lock.c \
+	mbtowc-lock.h windows-initguard.h mbsinit.c mbsrtowcs-impl.h \
+	mbsrtowcs-state.c mbsrtowcs.c mbtowc-impl.h mbtowc.c memchr.c \
+	memchr.valgrind memmem.c memmem.c str-two-way.h mempcpy.c \
+	memrchr.c mkdir.c mkdtemp.c mkostemp.c msvc-inval.c \
+	msvc-inval.h msvc-nothrow.c msvc-nothrow.h netdb.in.h \
+	netinet_in.in.h nonblocking.h stdio-read.c stdio-write.c \
+	open.c openat.c openat.h dirent-private.h opendir.c pathmax.h \
+	pipe.c rawmemchr.c rawmemchr.valgrind dirent-private.h \
+	readdir.c readlink.c realloc.c rename.c dirent-private.h \
+	rewinddir.c rmdir.c same-inode.h save-cwd.h \
+	malloc/scratch_buffer.h scratch_buffer.h select.c setenv.c \
+	setlocale-lock.c setlocale_null.h windows-initguard.h \
+	setsockopt.c w32sock.h signal.in.h _Noreturn.h arg-nonnull.h \
+	c++defs.h warn-on-use.h socket.c w32sock.h w32sock.h \
+	stat-w32.c stat-w32.h stat.c stat-time.h stdalign.in.h \
+	stdbool.in.h stddef.in.h stdint.in.h stdio.in.h stdlib.in.h \
+	strchrnul.c strchrnul.valgrind strdup.c streq.h strerror.c \
+	strerror-override.c strerror-override.h strerror_r.c \
+	string.in.h strings.in.h strnlen.c strstr.c str-two-way.h \
+	strstr.c strtok_r.c sys_ioctl.in.h sys_random.in.h \
 	sys_select.in.h sys_socket.in.h sys_stat.in.h sys_time.in.h \
 	sys_types.in.h sys_uio.in.h sys_wait.in.h tempname.h time.in.h \
 	time_r.c unistd.in.h unistd--.h unistd-safer.h unsetenv.c \
@@ -1880,9 +1896,9 @@ BUILT_SOURCES = $(ALLOCA_H) arpa/inet.h ctype.h dirent.h $(ERRNO_H) \
 	fcntl.h $(FLOAT_H) $(FNMATCH_H) $(GLOB_H) inttypes.h \
 	$(LIMITS_H) locale.h math.h netdb.h $(NETINET_IN_H) signal.h \
 	$(STDALIGN_H) $(STDBOOL_H) $(STDDEF_H) $(STDINT_H) stdio.h \
-	stdlib.h string.h strings.h sys/random.h sys/select.h \
-	sys/socket.h sys/stat.h sys/time.h sys/types.h sys/uio.h \
-	sys/wait.h time.h unistd.h wchar.h wctype.h
+	stdlib.h string.h strings.h sys/ioctl.h sys/random.h \
+	sys/select.h sys/socket.h sys/stat.h sys/time.h sys/types.h \
+	sys/uio.h sys/wait.h time.h unistd.h wchar.h wctype.h
 SUFFIXES = 
 MOSTLYCLEANFILES = core *.stackdump alloca.h alloca.h-t arpa/inet.h \
 	arpa/inet.h-t ctype.h ctype.h-t dirent.h dirent.h-t errno.h \
@@ -1893,12 +1909,13 @@ MOSTLYCLEANFILES = core *.stackdump alloca.h alloca.h-t arpa/inet.h \
 	stdalign.h stdalign.h-t stdbool.h stdbool.h-t stddef.h \
 	stddef.h-t stdint.h stdint.h-t stdio.h stdio.h-t stdlib.h \
 	stdlib.h-t string.h string.h-t strings.h strings.h-t \
-	sys/random.h sys/random.h-t sys/select.h sys/select.h-t \
-	sys/socket.h sys/socket.h-t sys/stat.h sys/stat.h-t sys/time.h \
-	sys/time.h-t sys/types.h sys/types.h-t sys/uio.h sys/uio.h-t \
-	sys/wait.h sys/wait.h-t time.h time.h-t unistd.h unistd.h-t \
-	wchar.h wchar.h-t wctype.h wctype.h-t
-MOSTLYCLEANDIRS = arpa netinet sys sys sys sys sys sys
+	sys/ioctl.h sys/ioctl.h-t sys/random.h sys/random.h-t \
+	sys/select.h sys/select.h-t sys/socket.h sys/socket.h-t \
+	sys/stat.h sys/stat.h-t sys/time.h sys/time.h-t sys/types.h \
+	sys/types.h-t sys/uio.h sys/uio.h-t sys/wait.h sys/wait.h-t \
+	time.h time.h-t unistd.h unistd.h-t wchar.h wchar.h-t wctype.h \
+	wctype.h-t
+MOSTLYCLEANDIRS = arpa netinet sys sys sys sys sys sys sys
 CLEANFILES = 
 DISTCLEANFILES = 
 MAINTAINERCLEANFILES = 
@@ -1909,8 +1926,8 @@ libgnu_a_SOURCES = openat-priv.h openat-proc.c basename-lgpl.c \
 	exitfail.c fd-hook.c fd-safer-flag.c dup-safer-flag.c \
 	filenamecat-lgpl.c getprogname.h getprogname.c gettext.h \
 	hard-locale.c idx.h localcharset.c glthread/lock.h \
-	glthread/lock.c malloca.c math.c minmax.h openat-die.c \
-	save-cwd.c malloc/scratch_buffer_dupfree.c \
+	glthread/lock.c malloca.c math.c minmax.h nonblocking.c \
+	openat-die.c save-cwd.c malloc/scratch_buffer_dupfree.c \
 	malloc/scratch_buffer_grow.c \
 	malloc/scratch_buffer_grow_preserve.c \
 	malloc/scratch_buffer_set_array_size.c setlocale_null.c \
@@ -1927,18 +1944,18 @@ EXTRA_libgnu_a_SOURCES = accept.c alloca.c bind.c btowc.c \
 	fstat.c stat-w32.c at-func.c fstatat.c getcwd.c getcwd-lgpl.c \
 	getdelim.c getdtablesize.c getline.c getlogin_r.c getrandom.c \
 	gettimeofday.c glob.c glob_pattern_p.c globfree.c inet_ntop.c \
-	isblank.c isnan.c isnand.c isnan.c isnanl.c listen.c lstat.c \
-	malloc.c lc-charset-dispatch.c mbrtowc.c mbtowc-lock.c \
+	ioctl.c isblank.c isnan.c isnand.c isnan.c isnanl.c listen.c \
+	lstat.c malloc.c lc-charset-dispatch.c mbrtowc.c mbtowc-lock.c \
 	mbsinit.c mbsrtowcs-state.c mbsrtowcs.c mbtowc.c memchr.c \
 	memmem.c memmem.c mempcpy.c memrchr.c mkdir.c mkdtemp.c \
-	mkostemp.c msvc-inval.c msvc-nothrow.c open.c openat.c \
-	opendir.c pipe.c rawmemchr.c readdir.c readlink.c realloc.c \
-	rename.c rewinddir.c rmdir.c select.c setenv.c \
-	setlocale-lock.c setsockopt.c socket.c stat-w32.c stat.c \
-	strchrnul.c strdup.c strerror.c strerror-override.c \
-	strerror_r.c strnlen.c strstr.c strstr.c strtok_r.c time_r.c \
-	unsetenv.c windows-mutex.c windows-once.c windows-recmutex.c \
-	windows-rwlock.c wmemchr.c wmempcpy.c
+	mkostemp.c msvc-inval.c msvc-nothrow.c stdio-read.c \
+	stdio-write.c open.c openat.c opendir.c pipe.c rawmemchr.c \
+	readdir.c readlink.c realloc.c rename.c rewinddir.c rmdir.c \
+	select.c setenv.c setlocale-lock.c setsockopt.c socket.c \
+	stat-w32.c stat.c strchrnul.c strdup.c strerror.c \
+	strerror-override.c strerror_r.c strnlen.c strstr.c strstr.c \
+	strtok_r.c time_r.c unsetenv.c windows-mutex.c windows-once.c \
+	windows-recmutex.c windows-rwlock.c wmemchr.c wmempcpy.c
 
 # Use this preprocessor expression to decide whether #include_next works.
 # Do not rely on a 'configure'-time test for this, since the expression
@@ -2103,6 +2120,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/globfree.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hard-locale.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet_ntop.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ioctl.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isblank.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isnan.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isnand.Po@am__quote@
@@ -2130,6 +2148,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkostemp.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msvc-inval.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msvc-nothrow.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nonblocking.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openat-die.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openat-proc.Po@am__quote@
@@ -2155,6 +2174,8 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat-time.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat-w32.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdio-read.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdio-write.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strchrnul.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strdup.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strerror-override.Po@am__quote@
@@ -3555,6 +3576,28 @@ strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE
 	} > $@-t && \
 	mv $@-t $@
 
+# We need the following in order to create <sys/ioctl.h> when the system
+# does not have a complete one.
+sys/ioctl.h: sys_ioctl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
+	$(AM_V_at)$(MKDIR_P) sys
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's|@''HAVE_SYS_IOCTL_H''@|$(HAVE_SYS_IOCTL_H)|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_SYS_IOCTL_H''@|$(NEXT_SYS_IOCTL_H)|g' \
+	      -e 's/@''GNULIB_IOCTL''@/$(GNULIB_IOCTL)/g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
+	      -e 's|@''REPLACE_IOCTL''@|$(REPLACE_IOCTL)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/sys_ioctl.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+
 # We need the following in order to create <sys/random.h> when the system
 # doesn't have one.
 sys/random.h: sys_random.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
diff --git a/gnulib/import/ioctl.c b/gnulib/import/ioctl.c
new file mode 100644
index 000000000000..5c5e7a474370
--- /dev/null
+++ b/gnulib/import/ioctl.c
@@ -0,0 +1,92 @@
+/* ioctl.c --- wrappers for Windows ioctl function
+
+   Copyright (C) 2008-2021 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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#include <sys/ioctl.h>
+
+#include <stdarg.h>
+
+#if HAVE_IOCTL
+
+/* Provide a wrapper with the POSIX prototype.  */
+# undef ioctl
+int
+rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */)
+{
+  void *buf;
+  va_list args;
+
+  va_start (args, request);
+  buf = va_arg (args, void *);
+  va_end (args);
+
+  /* Cast 'request' so that when the system's ioctl function takes a 64-bit
+     request argument, the value gets zero-extended, not sign-extended.  */
+  return ioctl (fd, (unsigned int) request, buf);
+}
+
+#else /* mingw */
+
+# include <errno.h>
+
+/* Get HANDLE.  */
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+# include "fd-hook.h"
+/* Get _get_osfhandle.  */
+# if GNULIB_MSVC_NOTHROW
+#  include "msvc-nothrow.h"
+# else
+#  include <io.h>
+# endif
+
+static int
+primary_ioctl (int fd, int request, void *arg)
+{
+  /* We don't support FIONBIO on pipes here.  If you want to make pipe
+     fds non-blocking, use the gnulib 'nonblocking' module, until
+     gnulib implements fcntl F_GETFL / F_SETFL with O_NONBLOCK.  */
+
+  if ((HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE)
+    errno = ENOSYS;
+  else
+    errno = EBADF;
+  return -1;
+}
+
+int
+ioctl (int fd, int request, ... /* {void *,char *} arg */)
+{
+  void *arg;
+  va_list args;
+
+  va_start (args, request);
+  arg = va_arg (args, void *);
+  va_end (args);
+
+# if WINDOWS_SOCKETS
+  return execute_all_ioctl_hooks (primary_ioctl, fd, request, arg);
+# else
+  return primary_ioctl (fd, request, arg);
+# endif
+}
+
+#endif
diff --git a/gnulib/import/m4/asm-underscore.m4 b/gnulib/import/m4/asm-underscore.m4
new file mode 100644
index 000000000000..93b98bea8f6e
--- /dev/null
+++ b/gnulib/import/m4/asm-underscore.m4
@@ -0,0 +1,83 @@
+# asm-underscore.m4 serial 5
+dnl Copyright (C) 2010-2021 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible. Based on as-underscore.m4 in GNU clisp.
+
+# gl_ASM_SYMBOL_PREFIX
+# Tests for the prefix of C symbols at the assembly language level and the
+# linker level. This prefix is either an underscore or empty. Defines the
+# C macro USER_LABEL_PREFIX to this prefix, and sets ASM_SYMBOL_PREFIX to
+# a stringified variant of this prefix.
+
+AC_DEFUN([gl_ASM_SYMBOL_PREFIX],
+[
+  AC_REQUIRE([AC_PROG_EGREP])
+  dnl We don't use GCC's __USER_LABEL_PREFIX__ here, because
+  dnl 1. It works only for GCC.
+  dnl 2. It is incorrectly defined on some platforms, in some GCC versions.
+  AC_REQUIRE([gl_C_ASM])
+  AC_CACHE_CHECK(
+    [whether C symbols are prefixed with underscore at the linker level],
+    [gl_cv_prog_as_underscore],
+    [cat > conftest.c <<EOF
+#ifdef __cplusplus
+extern "C" int foo (void);
+#endif
+int foo(void) { return 0; }
+EOF
+     # Look for the assembly language name in the .s file.
+     AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1
+     if LC_ALL=C $EGREP '(^|[[^a-zA-Z0-9_]])_foo([[^a-zA-Z0-9_]]|$)' conftest.$gl_asmext >/dev/null; then
+       gl_cv_prog_as_underscore=yes
+     else
+       gl_cv_prog_as_underscore=no
+     fi
+     rm -f conftest*
+    ])
+  if test $gl_cv_prog_as_underscore = yes; then
+    USER_LABEL_PREFIX=_
+  else
+    USER_LABEL_PREFIX=
+  fi
+  AC_DEFINE_UNQUOTED([USER_LABEL_PREFIX], [$USER_LABEL_PREFIX],
+    [Define to the prefix of C symbols at the assembler and linker level,
+     either an underscore or empty.])
+  ASM_SYMBOL_PREFIX='"'${USER_LABEL_PREFIX}'"'
+  AC_SUBST([ASM_SYMBOL_PREFIX])
+])
+
+# gl_C_ASM
+# Determines how to produce an assembly language file from C source code.
+# Sets the variables:
+#   gl_asmext - the extension of assembly language output,
+#   gl_c_asm_opt - the C compiler option that produces assembly language output.
+
+AC_DEFUN([gl_C_ASM],
+[
+  AC_EGREP_CPP([MicrosoftCompiler],
+    [
+#ifdef _MSC_VER
+MicrosoftCompiler
+#endif
+    ],
+    [dnl Microsoft's 'cl' and 'clang-cl' produce an .asm file, whereas 'clang'
+     dnl produces a .s file. Need to distinguish 'clang' and 'clang-cl'.
+     rm -f conftest*
+     echo 'int dummy;' > conftest.c
+     AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c) >/dev/null 2>&1
+     if test -f conftest.o; then
+       gl_asmext='s'
+       gl_c_asm_opt='-S'
+     else
+       gl_asmext='asm'
+       gl_c_asm_opt='-c -Fa'
+     fi
+     rm -f conftest*
+    ],
+    [gl_asmext='s'
+     gl_c_asm_opt='-S'
+    ])
+])
diff --git a/gnulib/import/m4/gnulib-cache.m4 b/gnulib/import/m4/gnulib-cache.m4
index 381cdde68f2b..bb91d4dce7a5 100644
--- a/gnulib/import/m4/gnulib-cache.m4
+++ b/gnulib/import/m4/gnulib-cache.m4
@@ -68,6 +68,7 @@
 #  mkdtemp \
 #  mkostemp \
 #  netdb \
+#  nonblocking \
 #  pathmax \
 #  rawmemchr \
 #  readlink \
@@ -123,6 +124,7 @@ gl_MODULES([
   mkdtemp
   mkostemp
   netdb
+  nonblocking
   pathmax
   rawmemchr
   readlink
diff --git a/gnulib/import/m4/gnulib-comp.m4 b/gnulib/import/m4/gnulib-comp.m4
index 5376a93c7924..4b3b0fc117ad 100644
--- a/gnulib/import/m4/gnulib-comp.m4
+++ b/gnulib/import/m4/gnulib-comp.m4
@@ -125,6 +125,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module intprops:
   # Code from module inttypes:
   # Code from module inttypes-incomplete:
+  # Code from module ioctl:
   # Code from module isblank:
   # Code from module isnand-nolibm:
   # Code from module isnanl-nolibm:
@@ -159,6 +160,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module netdb:
   # Code from module netinet_in:
   # Code from module nocrash:
+  # Code from module nonblocking:
   # Code from module open:
   # Code from module openat:
   # Code from module openat-die:
@@ -212,6 +214,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module strstr:
   # Code from module strstr-simple:
   # Code from module strtok_r:
+  # Code from module sys_ioctl:
   # Code from module sys_random:
   # Code from module sys_select:
   # Code from module sys_socket:
@@ -500,6 +503,11 @@ AC_DEFUN([gl_INIT],
   gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
   gl_INTTYPES_H
   gl_INTTYPES_INCOMPLETE
+  gl_FUNC_IOCTL
+  if test $HAVE_IOCTL = 0 || test $REPLACE_IOCTL = 1; then
+    AC_LIBOBJ([ioctl])
+  fi
+  gl_SYS_IOCTL_MODULE_INDICATOR([ioctl])
   gl_FUNC_ISBLANK
   if test $HAVE_ISBLANK = 0; then
     AC_LIBOBJ([isblank])
@@ -633,6 +641,17 @@ AC_DEFUN([gl_INIT],
   gl_HEADER_NETDB
   gl_HEADER_NETINET_IN
   AC_PROG_MKDIR_P
+  gl_NONBLOCKING_IO
+  gl_FCNTL_MODULE_INDICATOR([nonblocking])
+  dnl Define the C macro GNULIB_NONBLOCKING to 1.
+  gl_MODULE_INDICATOR([nonblocking])
+  dnl Define the substituted variable GNULIB_STDIO_H_NONBLOCKING to 1.
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_REQUIRE([gl_ASM_SYMBOL_PREFIX])
+  GNULIB_STDIO_H_NONBLOCKING=1
+  dnl Define the substituted variable GNULIB_UNISTD_H_NONBLOCKING to 1.
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  GNULIB_UNISTD_H_NONBLOCKING=1
   gl_FUNC_OPEN
   if test $REPLACE_OPEN = 1; then
     AC_LIBOBJ([open])
@@ -809,6 +828,8 @@ AC_DEFUN([gl_INIT],
     gl_PREREQ_STRTOK_R
   fi
   gl_STRING_MODULE_INDICATOR([strtok_r])
+  gl_SYS_IOCTL_H
+  AC_PROG_MKDIR_P
   gl_HEADER_SYS_RANDOM
   AC_PROG_MKDIR_P
   AC_REQUIRE([gl_HEADER_SYS_SELECT])
@@ -1118,6 +1139,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/inet_ntop.c
   lib/intprops.h
   lib/inttypes.in.h
+  lib/ioctl.c
   lib/isblank.c
   lib/isnan.c
   lib/isnand-nolibm.h
@@ -1170,6 +1192,8 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/msvc-nothrow.h
   lib/netdb.in.h
   lib/netinet_in.in.h
+  lib/nonblocking.c
+  lib/nonblocking.h
   lib/open.c
   lib/openat-die.c
   lib/openat-priv.h
@@ -1211,6 +1235,8 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/stdbool.in.h
   lib/stddef.in.h
   lib/stdint.in.h
+  lib/stdio-read.c
+  lib/stdio-write.c
   lib/stdio.in.h
   lib/stdlib.in.h
   lib/str-two-way.h
@@ -1230,6 +1256,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/strnlen1.h
   lib/strstr.c
   lib/strtok_r.c
+  lib/sys_ioctl.in.h
   lib/sys_random.in.h
   lib/sys_select.in.h
   lib/sys_socket.c
@@ -1272,6 +1299,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/absolute-header.m4
   m4/alloca.m4
   m4/arpa_inet_h.m4
+  m4/asm-underscore.m4
   m4/btowc.m4
   m4/builtin-expect.m4
   m4/canonicalize.m4
@@ -1332,6 +1360,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/include_next.m4
   m4/inet_ntop.m4
   m4/inttypes.m4
+  m4/ioctl.m4
   m4/isblank.m4
   m4/isnand.m4
   m4/isnanl.m4
@@ -1368,6 +1397,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/netdb_h.m4
   m4/netinet_in_h.m4
   m4/nocrash.m4
+  m4/nonblocking.m4
   m4/off_t.m4
   m4/open-cloexec.m4
   m4/open-slash.m4
@@ -1413,6 +1443,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/strnlen.m4
   m4/strstr.m4
   m4/strtok_r.m4
+  m4/sys_ioctl_h.m4
   m4/sys_random_h.m4
   m4/sys_select_h.m4
   m4/sys_socket_h.m4
diff --git a/gnulib/import/m4/ioctl.m4 b/gnulib/import/m4/ioctl.m4
new file mode 100644
index 000000000000..18286783a88b
--- /dev/null
+++ b/gnulib/import/m4/ioctl.m4
@@ -0,0 +1,44 @@
+# ioctl.m4 serial 5
+dnl Copyright (C) 2008-2021 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_IOCTL],
+[
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+  HAVE_IOCTL=1
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    dnl Even if the 'socket' module is not used here, another part of the
+    dnl application may use it and pass file descriptors that refer to
+    dnl sockets to the ioctl() function. So enable the support for sockets.
+    HAVE_IOCTL=0
+  else
+    AC_CHECK_FUNCS([ioctl])
+    dnl On glibc systems, the second parameter is 'unsigned long int request',
+    dnl not 'int request'. We cannot simply cast the function pointer, but
+    dnl instead need a wrapper.
+    AC_CACHE_CHECK([for ioctl with POSIX signature],
+      [gl_cv_func_ioctl_posix_signature],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <sys/ioctl.h>
+              /* On some platforms, ioctl() is declared in <unistd.h>.  */
+              #include <unistd.h>
+            ]],
+            [[extern
+              #ifdef __cplusplus
+              "C"
+              #endif
+              int ioctl (int, int, ...);
+            ]])
+         ],
+         [gl_cv_func_ioctl_posix_signature=yes],
+         [gl_cv_func_ioctl_posix_signature=no])
+      ])
+    if test $gl_cv_func_ioctl_posix_signature != yes; then
+      REPLACE_IOCTL=1
+    fi
+  fi
+])
diff --git a/gnulib/import/m4/nonblocking.m4 b/gnulib/import/m4/nonblocking.m4
new file mode 100644
index 000000000000..5f988b1c9bcd
--- /dev/null
+++ b/gnulib/import/m4/nonblocking.m4
@@ -0,0 +1,29 @@
+# nonblocking.m4 serial 2
+dnl Copyright (C) 2011-2021 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Tests whether non-blocking I/O is natively supported by read(), write().
+dnl Sets gl_cv_have_nonblocking.
+dnl Also tests whether open() supports O_NONBLOCK.
+dnl Sets gl_cv_have_open_O_NONBLOCK.
+AC_DEFUN([gl_NONBLOCKING_IO],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_NONBLOCKING_IO_BODY])
+])
+
+AC_DEFUN([gl_NONBLOCKING_IO_BODY],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  case "$host_os" in
+    mingw*) gl_cv_have_nonblocking=no ;;
+    *)      gl_cv_have_nonblocking=yes ;;
+  esac
+  case "$host_os" in
+    mingw*) gl_cv_have_open_O_NONBLOCK=no ;;
+    *)      gl_cv_have_open_O_NONBLOCK=yes ;;
+  esac
+])
diff --git a/gnulib/import/m4/sys_ioctl_h.m4 b/gnulib/import/m4/sys_ioctl_h.m4
new file mode 100644
index 000000000000..4d7267fc73c9
--- /dev/null
+++ b/gnulib/import/m4/sys_ioctl_h.m4
@@ -0,0 +1,64 @@
+# sys_ioctl_h.m4 serial 12
+dnl Copyright (C) 2008-2021 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Bruno Haible.
+
+AC_DEFUN([gl_SYS_IOCTL_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+
+  AC_CHECK_HEADERS_ONCE([sys/ioctl.h])
+  if test $ac_cv_header_sys_ioctl_h = yes; then
+    HAVE_SYS_IOCTL_H=1
+    dnl Test whether <sys/ioctl.h> declares ioctl(), or whether some other
+    dnl header file, such as <unistd.h> or <stropts.h>, is needed for that.
+    AC_CACHE_CHECK([whether <sys/ioctl.h> declares ioctl],
+      [gl_cv_decl_ioctl_in_sys_ioctl_h],
+      [dnl We cannot use AC_CHECK_DECL because it produces its own messages.
+       AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <sys/ioctl.h>]],
+            [[(void) ioctl;]])],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=yes],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=no])
+      ])
+  else
+    HAVE_SYS_IOCTL_H=0
+  fi
+  AC_SUBST([HAVE_SYS_IOCTL_H])
+  dnl <sys/ioctl.h> is always overridden, because of GNULIB_POSIXCHECK.
+  gl_CHECK_NEXT_HEADERS([sys/ioctl.h])
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[#include <sys/ioctl.h>
+/* Some platforms declare ioctl in the wrong header.  */
+#if !(defined __GLIBC__ && !defined __UCLIBC__)
+# include <unistd.h>
+#endif
+    ]], [ioctl])
+])
+
+AC_DEFUN([gl_SYS_IOCTL_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_SYS_IOCTL_H_DEFAULTS],
+[
+  GNULIB_IOCTL=0;         AC_SUBST([GNULIB_IOCTL])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  SYS_IOCTL_H_HAVE_WINSOCK2_H=0; AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H])
+  SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
+                        AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
+  REPLACE_IOCTL=0;      AC_SUBST([REPLACE_IOCTL])
+])
diff --git a/gnulib/import/nonblocking.c b/gnulib/import/nonblocking.c
new file mode 100644
index 000000000000..ac6504c72acb
--- /dev/null
+++ b/gnulib/import/nonblocking.c
@@ -0,0 +1,163 @@
+/* Non-blocking I/O for pipe or socket descriptors.
+   Copyright (C) 2011-2021 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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "nonblocking.h"
+
+#include <errno.h>
+
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Native Windows API.  */
+
+# include <sys/ioctl.h>
+# include <sys/socket.h>
+# include <unistd.h>
+
+/* Get declarations of the native Windows API functions.  */
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+# if GNULIB_MSVC_NOTHROW
+#  include "msvc-nothrow.h"
+# else
+#  include <io.h>
+# endif
+
+/* Don't assume that UNICODE is not defined.  */
+# undef GetNamedPipeHandleState
+# define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
+int
+get_nonblocking_flag (int desc)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (desc);
+  if (h == INVALID_HANDLE_VALUE)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  if (GetFileType (h) == FILE_TYPE_PIPE)
+    {
+      /* h is a pipe or socket.  */
+      DWORD state;
+      if (GetNamedPipeHandleState (h, &state, NULL, NULL, NULL, NULL, 0))
+        /* h is a pipe.  */
+        return (state & PIPE_NOWAIT) != 0;
+      else
+        /* h is a socket.  */
+        errno = ENOSYS;
+        return -1;
+    }
+  else
+    /* The native Windows API does not support non-blocking on regular
+       files.  */
+    return 0;
+}
+
+int
+set_nonblocking_flag (int desc, bool value)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (desc);
+  if (h == INVALID_HANDLE_VALUE)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  if (GetFileType (h) == FILE_TYPE_PIPE)
+    {
+      /* h is a pipe or socket.  */
+      DWORD state;
+      if (GetNamedPipeHandleState (h, &state, NULL, NULL, NULL, NULL, 0))
+        {
+          /* h is a pipe.  */
+          if ((state & PIPE_NOWAIT) != 0)
+            {
+              if (value)
+                return 0;
+              state &= ~PIPE_NOWAIT;
+            }
+          else
+            {
+              if (!value)
+                return 0;
+              state |= PIPE_NOWAIT;
+            }
+          if (SetNamedPipeHandleState (h, &state, NULL, NULL))
+            return 0;
+          errno = EINVAL;
+          return -1;
+        }
+      else
+        {
+          /* h is a socket.  */
+          int v = value;
+          return ioctl (desc, FIONBIO, &v);
+        }
+    }
+  else
+    {
+      /* The native Windows API does not support non-blocking on regular
+         files.  */
+      if (!value)
+        return 0;
+      errno = ENOTSUP;
+      return -1;
+    }
+}
+
+#else
+/* Unix API.  */
+
+# include <fcntl.h>
+
+# if GNULIB_defined_O_NONBLOCK
+#  error Please port nonblocking to your platform
+# endif
+
+/* We don't need the gnulib replacement of fcntl() here.  */
+# undef fcntl
+
+int
+get_nonblocking_flag (int desc)
+{
+  int fcntl_flags;
+
+  fcntl_flags = fcntl (desc, F_GETFL, 0);
+  if (fcntl_flags < 0)
+    return -1;
+  return (fcntl_flags & O_NONBLOCK) != 0;
+}
+
+int
+set_nonblocking_flag (int desc, bool value)
+{
+  int fcntl_flags;
+
+  fcntl_flags = fcntl (desc, F_GETFL, 0);
+  if (fcntl_flags < 0)
+    return -1;
+  if (((fcntl_flags & O_NONBLOCK) != 0) == value)
+    return 0;
+  if (value)
+    fcntl_flags |= O_NONBLOCK;
+  else
+    fcntl_flags &= ~O_NONBLOCK;
+  return fcntl (desc, F_SETFL, fcntl_flags);
+}
+
+#endif
diff --git a/gnulib/import/nonblocking.h b/gnulib/import/nonblocking.h
new file mode 100644
index 000000000000..e490dba5bb15
--- /dev/null
+++ b/gnulib/import/nonblocking.h
@@ -0,0 +1,62 @@
+/* Non-blocking I/O for pipe or socket descriptors.
+   Copyright (C) 2011-2021 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 <https://www.gnu.org/licenses/>.  */
+
+#ifndef _NONBLOCKING_H
+#define _NONBLOCKING_H
+
+#include <stdbool.h>
+
+/* Non-blocking I/O is an I/O mode by which read(), write() calls avoid
+   blocking the current thread.  When non-blocking is enabled:
+   - A read() call returns -1 with errno set to EAGAIN when no data or EOF
+     information is immediately available.
+   - A write() call returns -1 with errno set to EAGAIN when it cannot
+     transport the requested amount of data (but at most one pipe buffer)
+     without blocking.
+   Non-blocking I/O is most useful for character devices, pipes, and sockets.
+   Whether it also works on regular files and block devices is platform
+   dependent.
+
+   There are three modern alternatives to non-blocking I/O:
+     - use select() or poll() followed by read() or write() if the descriptor
+       is ready,
+     - call read() or write() in separate threads,
+     - use <aio.h> interfaces.  */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Return 1 if I/O to the descriptor DESC is currently non-blocking, 0
+   it is blocking, or -1 with errno set if fd is invalid or blocking
+   status cannot be determined (such as with sockets on mingw).  */
+extern int get_nonblocking_flag (int desc);
+
+/* Specify the non-blocking flag for the descriptor DESC.
+   Return 0 upon success, or -1 with errno set upon failure.
+   The default depends on the presence of the O_NONBLOCK flag for files
+   or pipes opened with open() or on the presence of the SOCK_NONBLOCK
+   flag for sockets.  */
+extern int set_nonblocking_flag (int desc, bool value);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _NONBLOCKING_H */
diff --git a/gnulib/import/stdio-read.c b/gnulib/import/stdio-read.c
new file mode 100644
index 000000000000..76e0c80a430b
--- /dev/null
+++ b/gnulib/import/stdio-read.c
@@ -0,0 +1,168 @@
+/* POSIX compatible FILE stream read function.
+   Copyright (C) 2008-2021 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2011.
+
+   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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+/* Replace these functions only if module 'nonblocking' is requested.  */
+#if GNULIB_NONBLOCKING
+
+/* On native Windows platforms, when read() is called on a non-blocking pipe
+   with an empty buffer, ReadFile() fails with error GetLastError() =
+   ERROR_NO_DATA, and read() in consequence fails with error EINVAL.  This
+   read() function is at the basis of the function which fills the buffer of
+   a FILE stream.  */
+
+# if defined _WIN32 && ! defined __CYGWIN__
+
+#  include <errno.h>
+#  include <io.h>
+
+#  define WIN32_LEAN_AND_MEAN  /* avoid including junk */
+#  include <windows.h>
+
+#  if GNULIB_MSVC_NOTHROW
+#   include "msvc-nothrow.h"
+#  else
+#   include <io.h>
+#  endif
+
+/* Don't assume that UNICODE is not defined.  */
+#  undef GetNamedPipeHandleState
+#  define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
+#  define CALL_WITH_ERRNO_FIX(RETTYPE, EXPRESSION, FAILED) \
+  if (ferror (stream))                                                        \
+    return (EXPRESSION);                                                      \
+  else                                                                        \
+    {                                                                         \
+      RETTYPE ret;                                                            \
+      SetLastError (0);                                                       \
+      ret = (EXPRESSION);                                                     \
+      if (FAILED)                                                             \
+        {                                                                     \
+          if (GetLastError () == ERROR_NO_DATA && ferror (stream))            \
+            {                                                                 \
+              int fd = fileno (stream);                                       \
+              if (fd >= 0)                                                    \
+                {                                                             \
+                  HANDLE h = (HANDLE) _get_osfhandle (fd);                    \
+                  if (GetFileType (h) == FILE_TYPE_PIPE)                      \
+                    {                                                         \
+                      /* h is a pipe or socket.  */                           \
+                      DWORD state;                                            \
+                      if (GetNamedPipeHandleState (h, &state, NULL, NULL,     \
+                                                   NULL, NULL, 0)             \
+                          && (state & PIPE_NOWAIT) != 0)                      \
+                        /* h is a pipe in non-blocking mode.                  \
+                           Change errno from EINVAL to EAGAIN.  */            \
+                        errno = EAGAIN;                                       \
+                    }                                                         \
+                }                                                             \
+            }                                                                 \
+        }                                                                     \
+      return ret;                                                             \
+    }
+
+/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
+   Otherwise we get a function definition conflict with mingw64's <stdio.h>.  */
+#  if GNULIB_SCANF
+int
+scanf (const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfscanf (stdin, format, args);
+  va_end (args);
+
+  return retval;
+}
+#  endif
+
+/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
+   Otherwise we get a function definition conflict with mingw64's <stdio.h>.  */
+#  if GNULIB_FSCANF
+int
+fscanf (FILE *stream, const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfscanf (stream, format, args);
+  va_end (args);
+
+  return retval;
+}
+#  endif
+
+/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
+   Otherwise we get a function definition conflict with mingw64's <stdio.h>.  */
+#  if GNULIB_VSCANF
+int
+vscanf (const char *format, va_list args)
+{
+  return vfscanf (stdin, format, args);
+}
+#  endif
+
+/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
+   Otherwise we get a function definition conflict with mingw64's <stdio.h>.  */
+#  if GNULIB_VFSCANF
+int
+vfscanf (FILE *stream, const char *format, va_list args)
+#undef vfscanf
+{
+  CALL_WITH_ERRNO_FIX (int, vfscanf (stream, format, args), ret == EOF)
+}
+#  endif
+
+int
+getchar (void)
+{
+  return fgetc (stdin);
+}
+
+int
+fgetc (FILE *stream)
+#undef fgetc
+{
+  CALL_WITH_ERRNO_FIX (int, fgetc (stream), ret == EOF)
+}
+
+char *
+fgets (char *s, int n, FILE *stream)
+#undef fgets
+{
+  CALL_WITH_ERRNO_FIX (char *, fgets (s, n, stream), ret == NULL)
+}
+
+/* We intentionally don't bother to fix gets.  */
+
+size_t
+fread (void *ptr, size_t s, size_t n, FILE *stream)
+#undef fread
+{
+  CALL_WITH_ERRNO_FIX (size_t, fread (ptr, s, n, stream), ret < n)
+}
+
+# endif
+#endif
diff --git a/gnulib/import/stdio-write.c b/gnulib/import/stdio-write.c
new file mode 100644
index 000000000000..b6a59e0dfda4
--- /dev/null
+++ b/gnulib/import/stdio-write.c
@@ -0,0 +1,206 @@
+/* POSIX compatible FILE stream write function.
+   Copyright (C) 2008-2021 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+   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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+/* Replace these functions only if module 'nonblocking' or module 'sigpipe' is
+   requested.  */
+#if GNULIB_NONBLOCKING || GNULIB_SIGPIPE
+
+/* On native Windows platforms, SIGPIPE does not exist.  When write() is
+   called on a pipe with no readers, WriteFile() fails with error
+   GetLastError() = ERROR_NO_DATA, and write() in consequence fails with
+   error EINVAL.  This write() function is at the basis of the function
+   which flushes the buffer of a FILE stream.  */
+
+# if defined _WIN32 && ! defined __CYGWIN__
+
+#  include <errno.h>
+#  include <signal.h>
+#  include <io.h>
+
+#  define WIN32_LEAN_AND_MEAN  /* avoid including junk */
+#  include <windows.h>
+
+#  if GNULIB_MSVC_NOTHROW
+#   include "msvc-nothrow.h"
+#  else
+#   include <io.h>
+#  endif
+
+/* Don't assume that UNICODE is not defined.  */
+#  undef GetNamedPipeHandleState
+#  define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
+#  if GNULIB_NONBLOCKING
+#   define CLEAR_ERRNO \
+      errno = 0;
+#   define HANDLE_ENOSPC \
+          if (errno == ENOSPC && ferror (stream))                             \
+            {                                                                 \
+              int fd = fileno (stream);                                       \
+              if (fd >= 0)                                                    \
+                {                                                             \
+                  HANDLE h = (HANDLE) _get_osfhandle (fd);                    \
+                  if (GetFileType (h) == FILE_TYPE_PIPE)                      \
+                    {                                                         \
+                      /* h is a pipe or socket.  */                           \
+                      DWORD state;                                            \
+                      if (GetNamedPipeHandleState (h, &state, NULL, NULL,     \
+                                                   NULL, NULL, 0)             \
+                          && (state & PIPE_NOWAIT) != 0)                      \
+                        /* h is a pipe in non-blocking mode.                  \
+                           Change errno from ENOSPC to EAGAIN.  */            \
+                        errno = EAGAIN;                                       \
+                    }                                                         \
+                }                                                             \
+            }                                                                 \
+          else
+#  else
+#   define CLEAR_ERRNO
+#   define HANDLE_ENOSPC
+#  endif
+
+#  if GNULIB_SIGPIPE
+#   define CLEAR_LastError \
+      SetLastError (0);
+#   define HANDLE_ERROR_NO_DATA \
+          if (GetLastError () == ERROR_NO_DATA && ferror (stream))            \
+            {                                                                 \
+              int fd = fileno (stream);                                       \
+              if (fd >= 0                                                     \
+                  && GetFileType ((HANDLE) _get_osfhandle (fd))               \
+                     == FILE_TYPE_PIPE)                                       \
+                {                                                             \
+                  /* Try to raise signal SIGPIPE.  */                         \
+                  raise (SIGPIPE);                                            \
+                  /* If it is currently blocked or ignored, change errno from \
+                     EINVAL to EPIPE.  */                                     \
+                  errno = EPIPE;                                              \
+                }                                                             \
+            }                                                                 \
+          else
+#  else
+#   define CLEAR_LastError
+#   define HANDLE_ERROR_NO_DATA
+#  endif
+
+#  define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
+  if (ferror (stream))                                                        \
+    return (EXPRESSION);                                                      \
+  else                                                                        \
+    {                                                                         \
+      RETTYPE ret;                                                            \
+      CLEAR_ERRNO                                                             \
+      CLEAR_LastError                                                         \
+      ret = (EXPRESSION);                                                     \
+      if (FAILED)                                                             \
+        {                                                                     \
+          HANDLE_ENOSPC                                                       \
+          HANDLE_ERROR_NO_DATA                                                \
+          ;                                                                   \
+        }                                                                     \
+      return ret;                                                             \
+    }
+
+#  if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
+int
+printf (const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfprintf (stdout, format, args);
+  va_end (args);
+
+  return retval;
+}
+#  endif
+
+#  if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
+int
+fprintf (FILE *stream, const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfprintf (stream, format, args);
+  va_end (args);
+
+  return retval;
+}
+#  endif
+
+#  if !REPLACE_VPRINTF_POSIX /* avoid collision with vprintf.c */
+int
+vprintf (const char *format, va_list args)
+{
+  return vfprintf (stdout, format, args);
+}
+#  endif
+
+#  if !REPLACE_VFPRINTF_POSIX /* avoid collision with vfprintf.c */
+int
+vfprintf (FILE *stream, const char *format, va_list args)
+#undef vfprintf
+{
+  CALL_WITH_SIGPIPE_EMULATION (int, vfprintf (stream, format, args), ret == EOF)
+}
+#  endif
+
+int
+putchar (int c)
+{
+  return fputc (c, stdout);
+}
+
+int
+fputc (int c, FILE *stream)
+#undef fputc
+{
+  CALL_WITH_SIGPIPE_EMULATION (int, fputc (c, stream), ret == EOF)
+}
+
+int
+fputs (const char *string, FILE *stream)
+#undef fputs
+{
+  CALL_WITH_SIGPIPE_EMULATION (int, fputs (string, stream), ret == EOF)
+}
+
+int
+puts (const char *string)
+#undef puts
+{
+  FILE *stream = stdout;
+  CALL_WITH_SIGPIPE_EMULATION (int, puts (string), ret == EOF)
+}
+
+size_t
+fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
+#undef fwrite
+{
+  CALL_WITH_SIGPIPE_EMULATION (size_t, fwrite (ptr, s, n, stream), ret < n)
+}
+
+# endif
+#endif
diff --git a/gnulib/import/sys_ioctl.in.h b/gnulib/import/sys_ioctl.in.h
new file mode 100644
index 000000000000..12c2cce8f1c8
--- /dev/null
+++ b/gnulib/import/sys_ioctl.in.h
@@ -0,0 +1,79 @@
+/* Substitute for and wrapper around <sys/ioctl.h>.
+   Copyright (C) 2008-2021 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, 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 <https://www.gnu.org/licenses/>.  */
+
+#ifndef _@GUARD_PREFIX@_SYS_IOCTL_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_SYS_IOCTL_H@
+# @INCLUDE_NEXT@ @NEXT_SYS_IOCTL_H@
+#endif
+
+#ifndef _@GUARD_PREFIX@_SYS_IOCTL_H
+#define _@GUARD_PREFIX@_SYS_IOCTL_H
+
+/* AIX 5.1 and Solaris 10 declare ioctl() in <unistd.h> and in <stropts.h>,
+   but not in <sys/ioctl.h>.
+   Haiku declares ioctl() in <unistd.h>, but not in <sys/ioctl.h>.
+   But avoid namespace pollution on glibc systems.  */
+#ifndef __GLIBC__
+# include <unistd.h>
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+
+/* Declare overridden functions.  */
+
+#if @GNULIB_IOCTL@
+# if @REPLACE_IOCTL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef ioctl
+#   define ioctl rpl_ioctl
+#  endif
+_GL_FUNCDECL_RPL (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+_GL_CXXALIAS_RPL (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+# else
+#  if @SYS_IOCTL_H_HAVE_WINSOCK2_H@ || 1
+_GL_FUNCDECL_SYS (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+#  endif
+_GL_CXXALIAS_SYS (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+# endif
+_GL_CXXALIASWARN (ioctl);
+#elif @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
+# undef ioctl
+# define ioctl ioctl_used_without_requesting_gnulib_module_ioctl
+#elif defined GNULIB_POSIXCHECK
+# undef ioctl
+# if HAVE_RAW_DECL_IOCTL
+_GL_WARN_ON_USE (ioctl, "ioctl does not portably work on sockets - "
+                 "use gnulib module ioctl for portability");
+# endif
+#endif
+
+
+#endif /* _@GUARD_PREFIX@_SYS_IOCTL_H */
+#endif /* _@GUARD_PREFIX@_SYS_IOCTL_H */
diff --git a/gnulib/update-gnulib.sh b/gnulib/update-gnulib.sh
index f0f83432b6a4..c77091f4caf8 100755
--- a/gnulib/update-gnulib.sh
+++ b/gnulib/update-gnulib.sh
@@ -60,6 +60,7 @@ IMPORTED_GNULIB_MODULES="\
     mkdtemp \
     mkostemp \
     netdb \
+    nonblocking \
     pathmax \
     rawmemchr \
     readlink \
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-09-09  7:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09  6:38 [PATCH 1/2] gnulib: import nonblocking module Mike Frysinger
2021-09-09  6:38 ` [PATCH 2/2] sim: use gnulib to set nonblocking mode Mike Frysinger
2021-09-09  7:24   ` Eli Zaretskii
2021-09-09  7:33     ` Mike Frysinger
2021-09-09  7:44       ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2021-09-04  7:49 [PATCH 1/2] gnulib: import nonblocking module Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).