From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id 87282386FC37 for ; Sat, 29 May 2021 17:25:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 87282386FC37 Received: from vapier.lan (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id AAECE335D12 for ; Sat, 29 May 2021 17:25:13 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH 4/4] gnulib: import select Date: Sat, 29 May 2021 13:25:10 -0400 Message-Id: <20210529172510.16285-4-vapier@gentoo.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210529172510.16285-1-vapier@gentoo.org> References: <20210529172510.16285-1-vapier@gentoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LINEPADDING, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 May 2021 17:25:23 -0000 A few sims use this to emulate the syscall & provide network functionality. --- gnulib/Makefile.gnulib.inc.in | 2 +- gnulib/Makefile.in | 14 + gnulib/aclocal.m4 | 4 + gnulib/config.in | 9 + gnulib/configure | 604 +++++++++++++++++++++++++++++++ gnulib/import/Makefile.am | 52 +++ gnulib/import/Makefile.in | 93 +++-- gnulib/import/m4/gnulib-cache.m4 | 2 + gnulib/import/m4/gnulib-comp.m4 | 22 ++ gnulib/import/m4/select.m4 | 117 ++++++ gnulib/import/m4/socketlib.m4 | 96 +++++ gnulib/import/m4/sockets.m4 | 17 + gnulib/import/m4/sys_select_h.m4 | 95 +++++ gnulib/import/select.c | 597 ++++++++++++++++++++++++++++++ gnulib/import/sockets.c | 161 ++++++++ gnulib/import/sockets.h | 66 ++++ gnulib/import/sys_select.in.h | 326 +++++++++++++++++ gnulib/import/w32sock.h | 140 +++++++ gnulib/update-gnulib.sh | 1 + 19 files changed, 2392 insertions(+), 26 deletions(-) create mode 100644 gnulib/import/m4/select.m4 create mode 100644 gnulib/import/m4/socketlib.m4 create mode 100644 gnulib/import/m4/sockets.m4 create mode 100644 gnulib/import/m4/sys_select_h.m4 create mode 100644 gnulib/import/select.c create mode 100644 gnulib/import/sockets.c create mode 100644 gnulib/import/sockets.h create mode 100644 gnulib/import/sys_select.in.h create mode 100644 gnulib/import/w32sock.h diff --git a/gnulib/Makefile.gnulib.inc.in b/gnulib/Makefile.gnulib.inc.in index 8cac19fca0d1..822f892a189a 100644 --- a/gnulib/Makefile.gnulib.inc.in +++ b/gnulib/Makefile.gnulib.inc.in @@ -40,5 +40,5 @@ LIBGNU = $(GNULIB_BUILDDIR)/import/libgnu.a LIBGNU_EXTRA_LIBS = @FREXPL_LIBM@ @FREXP_LIBM@ @INET_NTOP_LIB@ \ @LIBTHREAD@ @LIB_GETLOGIN@ @LIB_GETRANDOM@ \ @LIB_HARD_LOCALE@ @LIB_MBRTOWC@ \ - @LIB_SETLOCALE_NULL@ @LIBINTL@ + @LIB_SETLOCALE_NULL@ @LIBINTL@ @LIB_SELECT@ @LIBSOCKET@ INCGNU = -I$(srcdir)/../gnulib/import -I$(GNULIB_BUILDDIR)/import diff --git a/gnulib/Makefile.in b/gnulib/Makefile.in index be154720295d..e1b9b34a794e 100644 --- a/gnulib/Makefile.in +++ b/gnulib/Makefile.in @@ -231,9 +231,12 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \ $(top_srcdir)/import/m4/rewinddir.m4 \ $(top_srcdir)/import/m4/rmdir.m4 \ $(top_srcdir)/import/m4/save-cwd.m4 \ + $(top_srcdir)/import/m4/select.m4 \ $(top_srcdir)/import/m4/setenv.m4 \ $(top_srcdir)/import/m4/setlocale_null.m4 \ $(top_srcdir)/import/m4/signal_h.m4 \ + $(top_srcdir)/import/m4/socketlib.m4 \ + $(top_srcdir)/import/m4/sockets.m4 \ $(top_srcdir)/import/m4/socklen.m4 \ $(top_srcdir)/import/m4/sockpfaf.m4 \ $(top_srcdir)/import/m4/ssize_t.m4 \ @@ -256,6 +259,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \ $(top_srcdir)/import/m4/strstr.m4 \ $(top_srcdir)/import/m4/strtok_r.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 \ $(top_srcdir)/import/m4/sys_stat_h.m4 \ $(top_srcdir)/import/m4/sys_time_h.m4 \ @@ -680,6 +684,7 @@ GNULIB_POWF = @GNULIB_POWF@ GNULIB_PREAD = @GNULIB_PREAD@ GNULIB_PRINTF = @GNULIB_PRINTF@ GNULIB_PRINTF_POSIX = @GNULIB_PRINTF_POSIX@ +GNULIB_PSELECT = @GNULIB_PSELECT@ GNULIB_PTHREAD_SIGMASK = @GNULIB_PTHREAD_SIGMASK@ GNULIB_PTSNAME = @GNULIB_PTSNAME@ GNULIB_PTSNAME_R = @GNULIB_PTSNAME_R@ @@ -720,6 +725,7 @@ GNULIB_RPMATCH = @GNULIB_RPMATCH@ GNULIB_SCANDIR = @GNULIB_SCANDIR@ GNULIB_SCANF = @GNULIB_SCANF@ GNULIB_SECURE_GETENV = @GNULIB_SECURE_GETENV@ +GNULIB_SELECT = @GNULIB_SELECT@ GNULIB_SEND = @GNULIB_SEND@ GNULIB_SENDTO = @GNULIB_SENDTO@ GNULIB_SETENV = @GNULIB_SETENV@ @@ -1088,6 +1094,7 @@ HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@ HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@ HAVE_POWF = @HAVE_POWF@ HAVE_PREAD = @HAVE_PREAD@ +HAVE_PSELECT = @HAVE_PSELECT@ HAVE_PTHREAD_SIGMASK = @HAVE_PTHREAD_SIGMASK@ HAVE_PTSNAME = @HAVE_PTSNAME@ HAVE_PTSNAME_R = @HAVE_PTSNAME_R@ @@ -1161,6 +1168,7 @@ HAVE_SYS_INTTYPES_H = @HAVE_SYS_INTTYPES_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@ +HAVE_SYS_SELECT_H = @HAVE_SYS_SELECT_H@ HAVE_SYS_SOCKET_H = @HAVE_SYS_SOCKET_H@ HAVE_SYS_TIME_H = @HAVE_SYS_TIME_H@ HAVE_SYS_TYPES_H = @HAVE_SYS_TYPES_H@ @@ -1244,6 +1252,7 @@ LIBOBJS = @LIBOBJS@ LIBPMULTITHREAD = @LIBPMULTITHREAD@ LIBPTHREAD = @LIBPTHREAD@ LIBS = @LIBS@ +LIBSOCKET = @LIBSOCKET@ LIBSTDTHREAD = @LIBSTDTHREAD@ LIBTHREAD = @LIBTHREAD@ LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@ @@ -1252,6 +1261,7 @@ LIB_GETRANDOM = @LIB_GETRANDOM@ LIB_HARD_LOCALE = @LIB_HARD_LOCALE@ LIB_MBRTOWC = @LIB_MBRTOWC@ LIB_SCHED_YIELD = @LIB_SCHED_YIELD@ +LIB_SELECT = @LIB_SELECT@ LIB_SETLOCALE_NULL = @LIB_SETLOCALE_NULL@ LIMITS_H = @LIMITS_H@ LN_S = @LN_S@ @@ -1291,6 +1301,7 @@ 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_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@ NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H@ NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H@ @@ -1321,6 +1332,7 @@ NEXT_STDLIB_H = @NEXT_STDLIB_H@ NEXT_STRINGS_H = @NEXT_STRINGS_H@ NEXT_STRING_H = @NEXT_STRING_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@ NEXT_SYS_STAT_H = @NEXT_SYS_STAT_H@ NEXT_SYS_TIME_H = @NEXT_SYS_TIME_H@ @@ -1514,6 +1526,7 @@ REPLACE_POPEN = @REPLACE_POPEN@ REPLACE_POSIX_MEMALIGN = @REPLACE_POSIX_MEMALIGN@ REPLACE_PREAD = @REPLACE_PREAD@ REPLACE_PRINTF = @REPLACE_PRINTF@ +REPLACE_PSELECT = @REPLACE_PSELECT@ REPLACE_PTHREAD_SIGMASK = @REPLACE_PTHREAD_SIGMASK@ REPLACE_PTSNAME = @REPLACE_PTSNAME@ REPLACE_PTSNAME_R = @REPLACE_PTSNAME_R@ @@ -1539,6 +1552,7 @@ REPLACE_RMDIR = @REPLACE_RMDIR@ REPLACE_ROUND = @REPLACE_ROUND@ REPLACE_ROUNDF = @REPLACE_ROUNDF@ REPLACE_ROUNDL = @REPLACE_ROUNDL@ +REPLACE_SELECT = @REPLACE_SELECT@ REPLACE_SETENV = @REPLACE_SETENV@ REPLACE_SETLOCALE = @REPLACE_SETLOCALE@ REPLACE_SETSTATE = @REPLACE_SETSTATE@ diff --git a/gnulib/aclocal.m4 b/gnulib/aclocal.m4 index 96f7dc60af7f..83780b641ac4 100644 --- a/gnulib/aclocal.m4 +++ b/gnulib/aclocal.m4 @@ -1304,9 +1304,12 @@ m4_include([import/m4/rename.m4]) m4_include([import/m4/rewinddir.m4]) m4_include([import/m4/rmdir.m4]) m4_include([import/m4/save-cwd.m4]) +m4_include([import/m4/select.m4]) m4_include([import/m4/setenv.m4]) m4_include([import/m4/setlocale_null.m4]) m4_include([import/m4/signal_h.m4]) +m4_include([import/m4/socketlib.m4]) +m4_include([import/m4/sockets.m4]) m4_include([import/m4/socklen.m4]) m4_include([import/m4/sockpfaf.m4]) m4_include([import/m4/ssize_t.m4]) @@ -1329,6 +1332,7 @@ m4_include([import/m4/strnlen.m4]) m4_include([import/m4/strstr.m4]) m4_include([import/m4/strtok_r.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]) m4_include([import/m4/sys_stat_h.m4]) m4_include([import/m4/sys_time_h.m4]) diff --git a/gnulib/config.in b/gnulib/config.in index 15abb17cb445..a90ddd611823 100644 --- a/gnulib/config.in +++ b/gnulib/config.in @@ -303,6 +303,9 @@ /* Define to 1 when the gnulib module rmdir should be tested. */ #undef GNULIB_TEST_RMDIR +/* Define to 1 when the gnulib module select should be tested. */ +#undef GNULIB_TEST_SELECT + /* Define to 1 when the gnulib module setenv should be tested. */ #undef GNULIB_TEST_SETENV @@ -880,6 +883,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_RANDOM_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SELECT_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SOCKET_H @@ -1252,6 +1258,9 @@ 'wchar_t'. */ #undef WCHAR_T_SUFFIX +/* Define if WSAStartup is needed. */ +#undef WINDOWS_SOCKETS + /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type 'wint_t'. */ #undef WINT_T_SUFFIX diff --git a/gnulib/configure b/gnulib/configure index d447121f4f16..73a38082960a 100644 --- a/gnulib/configure +++ b/gnulib/configure @@ -776,6 +776,16 @@ GNULIB_SIGPROCMASK GNULIB_SIGNAL_H_SIGPIPE GNULIB_RAISE GNULIB_PTHREAD_SIGMASK +LIB_SELECT +LIBSOCKET +HAVE_SYS_SELECT_H +NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H +NEXT_SYS_SELECT_H +REPLACE_SELECT +REPLACE_PSELECT +HAVE_PSELECT +GNULIB_SELECT +GNULIB_PSELECT GL_GENERATE_NETINET_IN_H_FALSE GL_GENERATE_NETINET_IN_H_TRUE NETINET_IN_H @@ -3783,6 +3793,7 @@ as_fn_append ac_func_list " openat" as_fn_append ac_func_list " pipe" as_fn_append ac_func_list " readlink" as_fn_append ac_func_list " link" +as_fn_append ac_header_list " sys/select.h" as_fn_append ac_func_list " setenv" as_fn_append ac_func_list " strerror_r" as_fn_append ac_func_list " __xpg_strerror_r" @@ -6813,6 +6824,7 @@ fi # Code from module same-inode: # Code from module save-cwd: # Code from module scratch_buffer: + # Code from module select: # Code from module setenv: # Code from module setlocale-null: # Code from module signal-h: @@ -6820,6 +6832,8 @@ fi # Code from module snippet/arg-nonnull: # Code from module snippet/c++defs: # Code from module snippet/warn-on-use: + # Code from module socketlib: + # Code from module sockets: # Code from module socklen: # Code from module ssize_t: # Code from module stat: @@ -6845,6 +6859,7 @@ fi # Code from module strstr-simple: # Code from module strtok_r: # Code from module sys_random: + # Code from module sys_select: # Code from module sys_socket: # Code from module sys_stat: # Code from module sys_time: @@ -16475,6 +16490,409 @@ _ACEOF + + GNULIB_PSELECT=0; + GNULIB_SELECT=0; + HAVE_PSELECT=1; + REPLACE_PSELECT=0; + REPLACE_SELECT=0; + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether is self-contained" >&5 +$as_echo_n "checking whether is self-contained... " >&6; } +if ${gl_cv_header_sys_select_h_selfcontained+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +struct timeval b; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + gl_cv_header_sys_select_h_selfcontained=yes +else + gl_cv_header_sys_select_h_selfcontained=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + if test $gl_cv_header_sys_select_h_selfcontained = yes; then + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +int memset; int bzero; + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ + + #undef memset + #define memset nonexistent_memset + extern + #ifdef __cplusplus + "C" + #endif + void *memset (void *, int, unsigned long); + #undef bzero + #define bzero nonexistent_bzero + extern + #ifdef __cplusplus + "C" + #endif + void bzero (void *, unsigned long); + fd_set fds; + FD_ZERO (&fds); + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + +else + gl_cv_header_sys_select_h_selfcontained=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_header_sys_select_h_selfcontained" >&5 +$as_echo "$gl_cv_header_sys_select_h_selfcontained" >&6; } + + + + + + + + + + if test $gl_cv_have_include_next = yes; then + gl_cv_next_sys_select_h='<'sys/select.h'>' + else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking absolute name of " >&5 +$as_echo_n "checking absolute name of ... " >&6; } +if ${gl_cv_next_sys_select_h+:} false; then : + $as_echo_n "(cached) " >&6 +else + + if test $ac_cv_header_sys_select_h = yes; then + + + + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_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/select.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_select_h=`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&5 | + sed -n "$gl_absolute_header_sed"` + + gl_header=$gl_cv_absolute_sys_select_h + gl_cv_next_sys_select_h='"'$gl_header'"' + else + gl_cv_next_sys_select_h='<'sys/select.h'>' + fi + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_next_sys_select_h" >&5 +$as_echo "$gl_cv_next_sys_select_h" >&6; } + fi + NEXT_SYS_SELECT_H=$gl_cv_next_sys_select_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/select.h'>' + else + # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include' + gl_next_as_first_directive=$gl_cv_next_sys_select_h + fi + NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H=$gl_next_as_first_directive + + + + + if test $ac_cv_header_sys_select_h = yes; then + HAVE_SYS_SELECT_H=1 + else + HAVE_SYS_SELECT_H=0 + fi + + + + + + if test $ac_cv_header_sys_socket_h != yes; then + for ac_header in winsock2.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "winsock2.h" "ac_cv_header_winsock2_h" "$ac_includes_default" +if test "x$ac_cv_header_winsock2_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_WINSOCK2_H 1 +_ACEOF + +fi + +done + + fi + if test "$ac_cv_header_winsock2_h" = yes; then + HAVE_WINSOCK2_H=1 + UNISTD_H_HAVE_WINSOCK2_H=1 + SYS_IOCTL_H_HAVE_WINSOCK2_H=1 + else + HAVE_WINSOCK2_H=0 + fi + + + + + + + + + + + + + if test $ac_cv_header_sys_socket_h != yes; then + for ac_header in winsock2.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "winsock2.h" "ac_cv_header_winsock2_h" "$ac_includes_default" +if test "x$ac_cv_header_winsock2_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_WINSOCK2_H 1 +_ACEOF + +fi + +done + + fi + if test "$ac_cv_header_winsock2_h" = yes; then + HAVE_WINSOCK2_H=1 + UNISTD_H_HAVE_WINSOCK2_H=1 + SYS_IOCTL_H_HAVE_WINSOCK2_H=1 + else + HAVE_WINSOCK2_H=0 + fi + + LIBSOCKET= + if test $HAVE_WINSOCK2_H = 1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for WSAStartup" >&5 +$as_echo_n "checking for WSAStartup... " >&6; } +if ${gl_cv_func_wsastartup+:} false; then : + $as_echo_n "(cached) " >&6 +else + + gl_save_LIBS="$LIBS" + LIBS="$LIBS -lws2_32" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#ifdef HAVE_WINSOCK2_H +# include +#endif +int +main () +{ + + WORD wVersionRequested = MAKEWORD(1, 1); + WSADATA wsaData; + int err = WSAStartup(wVersionRequested, &wsaData); + WSACleanup (); + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gl_cv_func_wsastartup=yes +else + gl_cv_func_wsastartup=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LIBS="$gl_save_LIBS" + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_wsastartup" >&5 +$as_echo "$gl_cv_func_wsastartup" >&6; } + if test "$gl_cv_func_wsastartup" = "yes"; then + +$as_echo "#define WINDOWS_SOCKETS 1" >>confdefs.h + + LIBSOCKET='-lws2_32' + fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing setsockopt" >&5 +$as_echo_n "checking for library containing setsockopt... " >&6; } +if ${gl_cv_lib_socket+:} false; then : + $as_echo_n "(cached) " >&6 +else + + gl_cv_lib_socket= + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +extern +#ifdef __cplusplus +"C" +#endif +char setsockopt(); +int +main () +{ +setsockopt(); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + +else + gl_save_LIBS="$LIBS" + LIBS="$gl_save_LIBS -lsocket" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +extern +#ifdef __cplusplus +"C" +#endif +char setsockopt(); +int +main () +{ +setsockopt(); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gl_cv_lib_socket="-lsocket" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$gl_cv_lib_socket"; then + LIBS="$gl_save_LIBS -lnetwork" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +extern +#ifdef __cplusplus +"C" +#endif +char setsockopt(); +int +main () +{ +setsockopt(); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gl_cv_lib_socket="-lnetwork" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$gl_cv_lib_socket"; then + LIBS="$gl_save_LIBS -lnet" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +extern +#ifdef __cplusplus +"C" +#endif +char setsockopt(); +int +main () +{ +setsockopt(); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gl_cv_lib_socket="-lnet" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + fi + fi + LIBS="$gl_save_LIBS" + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$gl_cv_lib_socket"; then + gl_cv_lib_socket="none needed" + fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_lib_socket" >&5 +$as_echo "$gl_cv_lib_socket" >&6; } + if test "$gl_cv_lib_socket" != "none needed"; then + LIBSOCKET="$gl_cv_lib_socket" + fi + fi + + + + + + + : + + ac_fn_c_check_decl "$LINENO" "setenv" "ac_cv_have_decl_setenv" "$ac_includes_default" if test "x$ac_cv_have_decl_setenv" = xyes; then : ac_have_decl=1 @@ -27598,6 +28016,188 @@ $as_echo "#define GNULIB_TEST_RMDIR 1" >>confdefs.h + + + if test "$ac_cv_header_winsock2_h" = yes; then + REPLACE_SELECT=1 + else + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether select supports a 0 argument" >&5 +$as_echo_n "checking whether select supports a 0 argument... " >&6; } +if ${gl_cv_func_select_supports0+:} false; then : + $as_echo_n "(cached) " >&6 +else + + if test "$cross_compiling" = yes; then : + + case "$host_os" in + # Guess no on Interix. + interix*) gl_cv_func_select_supports0="guessing no";; + # Guess yes otherwise. + *) gl_cv_func_select_supports0="guessing yes";; + esac + +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include +#if HAVE_SYS_SELECT_H +#include +#endif +int main () +{ + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 5; + return select (0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout) < 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + gl_cv_func_select_supports0=yes +else + gl_cv_func_select_supports0=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_select_supports0" >&5 +$as_echo "$gl_cv_func_select_supports0" >&6; } + case "$gl_cv_func_select_supports0" in + *yes) ;; + *) REPLACE_SELECT=1 ;; + esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether select detects invalid fds" >&5 +$as_echo_n "checking whether select detects invalid fds... " >&6; } +if ${gl_cv_func_select_detects_ebadf+:} false; then : + $as_echo_n "(cached) " >&6 +else + + if test "$cross_compiling" = yes; then : + + case "$host_os" in + # Guess yes on Linux systems. + linux-* | linux) gl_cv_func_select_detects_ebadf="guessing yes" ;; + # Guess yes on glibc systems. + *-gnu* | gnu*) gl_cv_func_select_detects_ebadf="guessing yes" ;; + # If we don't know, obey --enable-cross-guesses. + *) gl_cv_func_select_detects_ebadf="$gl_cross_guess_normal" ;; + esac + +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include +#if HAVE_SYS_SELECT_H +# include +#endif +#include +#include + + +$gl_mda_defines + +int +main () +{ + + fd_set set; + dup2(0, 16); + FD_ZERO(&set); + FD_SET(16, &set); + close(16); + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 5; + return select (17, &set, NULL, NULL, &timeout) != -1 || errno != EBADF; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + gl_cv_func_select_detects_ebadf=yes +else + gl_cv_func_select_detects_ebadf=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_select_detects_ebadf" >&5 +$as_echo "$gl_cv_func_select_detects_ebadf" >&6; } + case $gl_cv_func_select_detects_ebadf in + *yes) ;; + *) REPLACE_SELECT=1 ;; + esac + fi + + LIB_SELECT="$LIBSOCKET" + if test $REPLACE_SELECT = 1; then + case "$host_os" in + mingw*) + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#define WIN32_LEAN_AND_MEAN +#include +int +main () +{ + MsgWaitForMultipleObjects (0, NULL, 0, 0, 0); + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + +else + LIB_SELECT="$LIB_SELECT -luser32" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + ;; + esac + fi + + + if test $REPLACE_SELECT = 1; then + + + + + + + + + gl_LIBOBJS="$gl_LIBOBJS select.$ac_objext" + + fi + + + + + + GNULIB_SELECT=1 + + + + + +$as_echo "#define GNULIB_TEST_SELECT 1" >>confdefs.h + + + + + if test $ac_cv_func_setenv = no; then HAVE_SETENV=0 else @@ -28113,6 +28713,8 @@ fi + + ac_fn_c_check_type "$LINENO" "socklen_t" "ac_cv_type_socklen_t" " /* is not needed according to POSIX, but the in i386-unknown-freebsd4.10 and @@ -29918,6 +30520,8 @@ $as_echo "$gl_cv_next_sys_random_h" >&6; } + + diff --git a/gnulib/import/Makefile.am b/gnulib/import/Makefile.am index 2a11accc8d61..1ae25ac28050 100644 --- a/gnulib/import/Makefile.am +++ b/gnulib/import/Makefile.am @@ -63,6 +63,7 @@ # rawmemchr \ # readlink \ # rename \ +# select \ # setenv \ # signal-h \ # strchrnul \ @@ -1701,6 +1702,15 @@ EXTRA_DIST += malloc/scratch_buffer.h scratch_buffer.h ## end gnulib module scratch_buffer +## begin gnulib module select + + +EXTRA_DIST += select.c + +EXTRA_libgnu_a_SOURCES += select.c + +## end gnulib module select + ## begin gnulib module setenv @@ -1810,6 +1820,14 @@ EXTRA_DIST += warn-on-use.h ## end gnulib module snippet/warn-on-use +## begin gnulib module sockets + +libgnu_a_SOURCES += sockets.h sockets.c + +EXTRA_DIST += w32sock.h + +## end gnulib module sockets + ## begin gnulib module stat @@ -2492,6 +2510,40 @@ EXTRA_DIST += sys_random.in.h ## end gnulib module sys_random +## begin gnulib module sys_select + +BUILT_SOURCES += sys/select.h + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +sys/select.h: sys_select.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|@''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_SELECT_H''@|$(NEXT_SYS_SELECT_H)|g' \ + -e 's|@''HAVE_SYS_SELECT_H''@|$(HAVE_SYS_SELECT_H)|g' \ + -e 's/@''GNULIB_PSELECT''@/$(GNULIB_PSELECT)/g' \ + -e 's/@''GNULIB_SELECT''@/$(GNULIB_SELECT)/g' \ + -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ + -e 's|@''HAVE_PSELECT''@|$(HAVE_PSELECT)|g' \ + -e 's|@''REPLACE_PSELECT''@|$(REPLACE_PSELECT)|g' \ + -e 's|@''REPLACE_SELECT''@|$(REPLACE_SELECT)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/sys_select.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += sys/select.h sys/select.h-t +MOSTLYCLEANDIRS += sys + +EXTRA_DIST += sys_select.in.h + +## end gnulib module sys_select + ## begin gnulib module sys_socket BUILT_SOURCES += sys/socket.h diff --git a/gnulib/import/Makefile.in b/gnulib/import/Makefile.in index 96606cf73f31..e9b52a7d4fc3 100644 --- a/gnulib/import/Makefile.in +++ b/gnulib/import/Makefile.in @@ -77,6 +77,7 @@ # rawmemchr \ # readlink \ # rename \ +# select \ # setenv \ # signal-h \ # strchrnul \ @@ -294,9 +295,12 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \ $(top_srcdir)/import/m4/rewinddir.m4 \ $(top_srcdir)/import/m4/rmdir.m4 \ $(top_srcdir)/import/m4/save-cwd.m4 \ + $(top_srcdir)/import/m4/select.m4 \ $(top_srcdir)/import/m4/setenv.m4 \ $(top_srcdir)/import/m4/setlocale_null.m4 \ $(top_srcdir)/import/m4/signal_h.m4 \ + $(top_srcdir)/import/m4/socketlib.m4 \ + $(top_srcdir)/import/m4/sockets.m4 \ $(top_srcdir)/import/m4/socklen.m4 \ $(top_srcdir)/import/m4/sockpfaf.m4 \ $(top_srcdir)/import/m4/ssize_t.m4 \ @@ -319,6 +323,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \ $(top_srcdir)/import/m4/strstr.m4 \ $(top_srcdir)/import/m4/strtok_r.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 \ $(top_srcdir)/import/m4/sys_stat_h.m4 \ $(top_srcdir)/import/m4/sys_time_h.m4 \ @@ -366,7 +371,7 @@ am_libgnu_a_OBJECTS = openat-proc.$(OBJEXT) basename-lgpl.$(OBJEXT) \ malloc/scratch_buffer_grow.$(OBJEXT) \ malloc/scratch_buffer_grow_preserve.$(OBJEXT) \ malloc/scratch_buffer_set_array_size.$(OBJEXT) \ - setlocale_null.$(OBJEXT) stat-time.$(OBJEXT) \ + setlocale_null.$(OBJEXT) sockets.$(OBJEXT) stat-time.$(OBJEXT) \ strnlen1.$(OBJEXT) sys_socket.$(OBJEXT) tempname.$(OBJEXT) \ glthread/threadlib.$(OBJEXT) unistd.$(OBJEXT) \ dup-safer.$(OBJEXT) fd-safer.$(OBJEXT) pipe-safer.$(OBJEXT) \ @@ -781,6 +786,7 @@ GNULIB_POWF = @GNULIB_POWF@ GNULIB_PREAD = @GNULIB_PREAD@ GNULIB_PRINTF = @GNULIB_PRINTF@ GNULIB_PRINTF_POSIX = @GNULIB_PRINTF_POSIX@ +GNULIB_PSELECT = @GNULIB_PSELECT@ GNULIB_PTHREAD_SIGMASK = @GNULIB_PTHREAD_SIGMASK@ GNULIB_PTSNAME = @GNULIB_PTSNAME@ GNULIB_PTSNAME_R = @GNULIB_PTSNAME_R@ @@ -821,6 +827,7 @@ GNULIB_RPMATCH = @GNULIB_RPMATCH@ GNULIB_SCANDIR = @GNULIB_SCANDIR@ GNULIB_SCANF = @GNULIB_SCANF@ GNULIB_SECURE_GETENV = @GNULIB_SECURE_GETENV@ +GNULIB_SELECT = @GNULIB_SELECT@ GNULIB_SEND = @GNULIB_SEND@ GNULIB_SENDTO = @GNULIB_SENDTO@ GNULIB_SETENV = @GNULIB_SETENV@ @@ -1189,6 +1196,7 @@ HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@ HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@ HAVE_POWF = @HAVE_POWF@ HAVE_PREAD = @HAVE_PREAD@ +HAVE_PSELECT = @HAVE_PSELECT@ HAVE_PTHREAD_SIGMASK = @HAVE_PTHREAD_SIGMASK@ HAVE_PTSNAME = @HAVE_PTSNAME@ HAVE_PTSNAME_R = @HAVE_PTSNAME_R@ @@ -1262,6 +1270,7 @@ HAVE_SYS_INTTYPES_H = @HAVE_SYS_INTTYPES_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@ +HAVE_SYS_SELECT_H = @HAVE_SYS_SELECT_H@ HAVE_SYS_SOCKET_H = @HAVE_SYS_SOCKET_H@ HAVE_SYS_TIME_H = @HAVE_SYS_TIME_H@ HAVE_SYS_TYPES_H = @HAVE_SYS_TYPES_H@ @@ -1345,6 +1354,7 @@ LIBOBJS = @LIBOBJS@ LIBPMULTITHREAD = @LIBPMULTITHREAD@ LIBPTHREAD = @LIBPTHREAD@ LIBS = @LIBS@ +LIBSOCKET = @LIBSOCKET@ LIBSTDTHREAD = @LIBSTDTHREAD@ LIBTHREAD = @LIBTHREAD@ LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@ @@ -1353,6 +1363,7 @@ LIB_GETRANDOM = @LIB_GETRANDOM@ LIB_HARD_LOCALE = @LIB_HARD_LOCALE@ LIB_MBRTOWC = @LIB_MBRTOWC@ LIB_SCHED_YIELD = @LIB_SCHED_YIELD@ +LIB_SELECT = @LIB_SELECT@ LIB_SETLOCALE_NULL = @LIB_SETLOCALE_NULL@ LIMITS_H = @LIMITS_H@ LN_S = @LN_S@ @@ -1392,6 +1403,7 @@ 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_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@ NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H@ NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H@ @@ -1422,6 +1434,7 @@ NEXT_STDLIB_H = @NEXT_STDLIB_H@ NEXT_STRINGS_H = @NEXT_STRINGS_H@ NEXT_STRING_H = @NEXT_STRING_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@ NEXT_SYS_STAT_H = @NEXT_SYS_STAT_H@ NEXT_SYS_TIME_H = @NEXT_SYS_TIME_H@ @@ -1615,6 +1628,7 @@ REPLACE_POPEN = @REPLACE_POPEN@ REPLACE_POSIX_MEMALIGN = @REPLACE_POSIX_MEMALIGN@ REPLACE_PREAD = @REPLACE_PREAD@ REPLACE_PRINTF = @REPLACE_PRINTF@ +REPLACE_PSELECT = @REPLACE_PSELECT@ REPLACE_PTHREAD_SIGMASK = @REPLACE_PTHREAD_SIGMASK@ REPLACE_PTSNAME = @REPLACE_PTSNAME@ REPLACE_PTSNAME_R = @REPLACE_PTSNAME_R@ @@ -1640,6 +1654,7 @@ REPLACE_RMDIR = @REPLACE_RMDIR@ REPLACE_ROUND = @REPLACE_ROUND@ REPLACE_ROUNDF = @REPLACE_ROUNDF@ REPLACE_ROUNDL = @REPLACE_ROUNDL@ +REPLACE_SELECT = @REPLACE_SELECT@ REPLACE_SETENV = @REPLACE_SETENV@ REPLACE_SETLOCALE = @REPLACE_SETLOCALE@ REPLACE_SETSTATE = @REPLACE_SETSTATE@ @@ -1831,14 +1846,15 @@ EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h arpa_inet.in.h \ 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 setenv.c setlocale-lock.c setlocale_null.h \ - windows-initguard.h signal.in.h _Noreturn.h arg-nonnull.h \ - c++defs.h warn-on-use.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 \ + scratch_buffer.h select.c setenv.c setlocale-lock.c \ + setlocale_null.h windows-initguard.h signal.in.h _Noreturn.h \ + arg-nonnull.h c++defs.h warn-on-use.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 sys_select.in.h \ sys_socket.in.h sys_stat.in.h sys_time.in.h sys_types.in.h \ sys_uio.in.h tempname.h time.in.h time_r.c unistd.in.h \ unistd--.h unistd-safer.h unsetenv.c \ @@ -1852,9 +1868,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/socket.h \ - sys/stat.h sys/time.h sys/types.h sys/uio.h time.h unistd.h \ - wchar.h wctype.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 \ + 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 \ @@ -1865,11 +1881,12 @@ 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/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 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/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 \ + 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 CLEANFILES = DISTCLEANFILES = MAINTAINERCLEANFILES = @@ -1885,9 +1902,9 @@ libgnu_a_SOURCES = openat-priv.h openat-proc.c basename-lgpl.c \ malloc/scratch_buffer_grow.c \ malloc/scratch_buffer_grow_preserve.c \ malloc/scratch_buffer_set_array_size.c setlocale_null.c \ - stat-time.c strnlen1.h strnlen1.c sys_socket.c tempname.c \ - glthread/threadlib.c unistd.c dup-safer.c fd-safer.c \ - pipe-safer.c wctype-h.c + sockets.h sockets.c stat-time.c strnlen1.h strnlen1.c \ + sys_socket.c tempname.c glthread/threadlib.c unistd.c \ + dup-safer.c fd-safer.c pipe-safer.c wctype-h.c libgnu_a_LIBADD = $(gl_LIBOBJS) @ALLOCA@ libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) @ALLOCA@ EXTRA_libgnu_a_SOURCES = alloca.c btowc.c canonicalize-lgpl.c \ @@ -1904,11 +1921,11 @@ EXTRA_libgnu_a_SOURCES = alloca.c btowc.c canonicalize-lgpl.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 setenv.c setlocale-lock.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 + rewinddir.c rmdir.c select.c setenv.c setlocale-lock.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 @@ -2111,9 +2128,11 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rewinddir.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rmdir.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/save-cwd.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/select.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setenv.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setlocale-lock.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setlocale_null.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sockets.Po@am__quote@ @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@ @@ -3539,6 +3558,30 @@ sys/random.h: sys_random.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_N } > $@-t && \ mv -f $@-t $@ +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +sys/select.h: sys_select.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|@''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_SELECT_H''@|$(NEXT_SYS_SELECT_H)|g' \ + -e 's|@''HAVE_SYS_SELECT_H''@|$(HAVE_SYS_SELECT_H)|g' \ + -e 's/@''GNULIB_PSELECT''@/$(GNULIB_PSELECT)/g' \ + -e 's/@''GNULIB_SELECT''@/$(GNULIB_SELECT)/g' \ + -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ + -e 's|@''HAVE_PSELECT''@|$(HAVE_PSELECT)|g' \ + -e 's|@''REPLACE_PSELECT''@|$(REPLACE_PSELECT)|g' \ + -e 's|@''REPLACE_SELECT''@|$(REPLACE_SELECT)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/sys_select.in.h; \ + } > $@-t && \ + mv $@-t $@ + # We need the following in order to create when the system # doesn't have one that works with the given compiler. sys/socket.h: sys_socket.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) diff --git a/gnulib/import/m4/gnulib-cache.m4 b/gnulib/import/m4/gnulib-cache.m4 index 54ee8ca68bb9..689ebd3e5ba9 100644 --- a/gnulib/import/m4/gnulib-cache.m4 +++ b/gnulib/import/m4/gnulib-cache.m4 @@ -68,6 +68,7 @@ # rawmemchr \ # readlink \ # rename \ +# select \ # setenv \ # signal-h \ # strchrnul \ @@ -115,6 +116,7 @@ gl_MODULES([ rawmemchr readlink rename + select setenv signal-h strchrnul diff --git a/gnulib/import/m4/gnulib-comp.m4 b/gnulib/import/m4/gnulib-comp.m4 index 0bf0d171ee49..03eff90b6b2d 100644 --- a/gnulib/import/m4/gnulib-comp.m4 +++ b/gnulib/import/m4/gnulib-comp.m4 @@ -172,6 +172,7 @@ AC_DEFUN([gl_EARLY], # Code from module same-inode: # Code from module save-cwd: # Code from module scratch_buffer: + # Code from module select: # Code from module setenv: # Code from module setlocale-null: # Code from module signal-h: @@ -179,6 +180,8 @@ AC_DEFUN([gl_EARLY], # Code from module snippet/arg-nonnull: # Code from module snippet/c++defs: # Code from module snippet/warn-on-use: + # Code from module socketlib: + # Code from module sockets: # Code from module socklen: # Code from module ssize_t: # Code from module stat: @@ -204,6 +207,7 @@ AC_DEFUN([gl_EARLY], # Code from module strstr-simple: # Code from module strtok_r: # Code from module sys_random: + # Code from module sys_select: # Code from module sys_socket: # Code from module sys_stat: # Code from module sys_time: @@ -664,6 +668,11 @@ AC_DEFUN([gl_INIT], fi gl_UNISTD_MODULE_INDICATOR([rmdir]) gl_SAVE_CWD + gl_FUNC_SELECT + if test $REPLACE_SELECT = 1; then + AC_LIBOBJ([select]) + fi + gl_SYS_SELECT_MODULE_INDICATOR([select]) gl_FUNC_SETENV if test $HAVE_SETENV = 0 || test $REPLACE_SETENV = 1; then AC_LIBOBJ([setenv]) @@ -676,6 +685,8 @@ AC_DEFUN([gl_INIT], fi gl_LOCALE_MODULE_INDICATOR([setlocale_null]) gl_SIGNAL_H + AC_REQUIRE([gl_SOCKETLIB]) + AC_REQUIRE([gl_SOCKETS]) gl_TYPE_SOCKLEN_T gt_TYPE_SSIZE_T gl_FUNC_STAT @@ -754,6 +765,8 @@ AC_DEFUN([gl_INIT], gl_STRING_MODULE_INDICATOR([strtok_r]) gl_HEADER_SYS_RANDOM AC_PROG_MKDIR_P + AC_REQUIRE([gl_HEADER_SYS_SELECT]) + AC_PROG_MKDIR_P AC_REQUIRE([gl_HEADER_SYS_SOCKET]) AC_PROG_MKDIR_P gl_HEADER_SYS_STAT_H @@ -1127,11 +1140,14 @@ AC_DEFUN([gl_FILE_LIST], [ lib/save-cwd.c lib/save-cwd.h lib/scratch_buffer.h + lib/select.c lib/setenv.c lib/setlocale-lock.c lib/setlocale_null.c lib/setlocale_null.h lib/signal.in.h + lib/sockets.c + lib/sockets.h lib/stat-time.c lib/stat-time.h lib/stat-w32.c @@ -1161,6 +1177,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/strstr.c lib/strtok_r.c lib/sys_random.in.h + lib/sys_select.in.h lib/sys_socket.c lib/sys_socket.in.h lib/sys_stat.in.h @@ -1177,6 +1194,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/unistd.in.h lib/unsetenv.c lib/verify.h + lib/w32sock.h lib/warn-on-use.h lib/wchar.in.h lib/wctype-h.c @@ -1313,9 +1331,12 @@ AC_DEFUN([gl_FILE_LIST], [ m4/rewinddir.m4 m4/rmdir.m4 m4/save-cwd.m4 + m4/select.m4 m4/setenv.m4 m4/setlocale_null.m4 m4/signal_h.m4 + m4/socketlib.m4 + m4/sockets.m4 m4/socklen.m4 m4/sockpfaf.m4 m4/ssize_t.m4 @@ -1338,6 +1359,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/strstr.m4 m4/strtok_r.m4 m4/sys_random_h.m4 + m4/sys_select_h.m4 m4/sys_socket_h.m4 m4/sys_stat_h.m4 m4/sys_time_h.m4 diff --git a/gnulib/import/m4/select.m4 b/gnulib/import/m4/select.m4 new file mode 100644 index 000000000000..c7409d2041d1 --- /dev/null +++ b/gnulib/import/m4/select.m4 @@ -0,0 +1,117 @@ +# select.m4 serial 12 +dnl Copyright (C) 2009-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_SELECT], +[ + AC_REQUIRE([gl_HEADER_SYS_SELECT]) + AC_REQUIRE([AC_C_RESTRICT]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([gl_SOCKETS]) + if test "$ac_cv_header_winsock2_h" = yes; then + REPLACE_SELECT=1 + else + dnl On Interix 3.5, select(0, NULL, NULL, NULL, timeout) fails with error + dnl EFAULT. + AC_CHECK_HEADERS_ONCE([sys/select.h]) + AC_CACHE_CHECK([whether select supports a 0 argument], + [gl_cv_func_select_supports0], + [ + AC_RUN_IFELSE([AC_LANG_SOURCE([[ +#include +#include +#if HAVE_SYS_SELECT_H +#include +#endif +int main () +{ + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 5; + return select (0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout) < 0; +}]])], [gl_cv_func_select_supports0=yes], [gl_cv_func_select_supports0=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess no on Interix. + interix*) gl_cv_func_select_supports0="guessing no";; + # Guess yes otherwise. + *) gl_cv_func_select_supports0="guessing yes";; + esac +changequote([,])dnl + ]) + ]) + case "$gl_cv_func_select_supports0" in + *yes) ;; + *) REPLACE_SELECT=1 ;; + esac + + dnl On FreeBSD 8.2, select() doesn't always reject bad fds. + AC_CACHE_CHECK([whether select detects invalid fds], + [gl_cv_func_select_detects_ebadf], + [ + AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +#if HAVE_SYS_SELECT_H +# include +#endif +#include +#include +]GL_MDA_DEFINES], +[[ + fd_set set; + dup2(0, 16); + FD_ZERO(&set); + FD_SET(16, &set); + close(16); + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 5; + return select (17, &set, NULL, NULL, &timeout) != -1 || errno != EBADF; +]])], [gl_cv_func_select_detects_ebadf=yes], + [gl_cv_func_select_detects_ebadf=no], + [ + case "$host_os" in + # Guess yes on Linux systems. + linux-* | linux) gl_cv_func_select_detects_ebadf="guessing yes" ;; + # Guess yes on glibc systems. + *-gnu* | gnu*) gl_cv_func_select_detects_ebadf="guessing yes" ;; + # If we don't know, obey --enable-cross-guesses. + *) gl_cv_func_select_detects_ebadf="$gl_cross_guess_normal" ;; + esac + ]) + ]) + case $gl_cv_func_select_detects_ebadf in + *yes) ;; + *) REPLACE_SELECT=1 ;; + esac + fi + + dnl Determine the needed libraries. + LIB_SELECT="$LIBSOCKET" + if test $REPLACE_SELECT = 1; then + case "$host_os" in + mingw*) + dnl On the MSVC platform, the function MsgWaitForMultipleObjects + dnl (used in lib/select.c) requires linking with -luser32. On mingw, + dnl it is implicit. + AC_LINK_IFELSE( + [AC_LANG_SOURCE([[ +#define WIN32_LEAN_AND_MEAN +#include +int +main () +{ + MsgWaitForMultipleObjects (0, NULL, 0, 0, 0); + return 0; +}]])], + [], + [LIB_SELECT="$LIB_SELECT -luser32"]) + ;; + esac + fi + AC_SUBST([LIB_SELECT]) +]) diff --git a/gnulib/import/m4/socketlib.m4 b/gnulib/import/m4/socketlib.m4 new file mode 100644 index 000000000000..0f8a0829c7ba --- /dev/null +++ b/gnulib/import/m4/socketlib.m4 @@ -0,0 +1,96 @@ +# socketlib.m4 serial 3 +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 gl_SOCKETLIB +dnl Determines the library to use for socket functions. +dnl Sets and AC_SUBSTs LIBSOCKET. + +AC_DEFUN([gl_SOCKETLIB], +[ + gl_PREREQ_SYS_H_WINSOCK2 dnl for HAVE_WINSOCK2_H + LIBSOCKET= + if test $HAVE_WINSOCK2_H = 1; then + dnl Native Windows API (not Cygwin). + dnl If the function WSAStartup exists (declared in and + dnl defined through -lws2_32), we need to call it. + AC_CACHE_CHECK([for WSAStartup], + [gl_cv_func_wsastartup], [ + gl_save_LIBS="$LIBS" + LIBS="$LIBS -lws2_32" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[ +#ifdef HAVE_WINSOCK2_H +# include +#endif]], [[ + WORD wVersionRequested = MAKEWORD(1, 1); + WSADATA wsaData; + int err = WSAStartup(wVersionRequested, &wsaData); + WSACleanup (); + ]]) + ], + [gl_cv_func_wsastartup=yes], + [gl_cv_func_wsastartup=no]) + LIBS="$gl_save_LIBS" + ]) + if test "$gl_cv_func_wsastartup" = "yes"; then + AC_DEFINE([WINDOWS_SOCKETS], [1], [Define if WSAStartup is needed.]) + LIBSOCKET='-lws2_32' + fi + else + dnl Unix API. + dnl Solaris has most socket functions in libsocket. + dnl Haiku has most socket functions in libnetwork. + dnl BeOS has most socket functions in libnet. + dnl On HP-UX, do NOT link with libxnet, because in 64-bit mode this would + dnl break code (e.g. in libraries) that invokes accept(), getpeername(), + dnl getsockname(), getsockopt(), or recvfrom() with a 32-bit addrlen. See + dnl "man xopen_networking" for details. + AC_CACHE_CHECK([for library containing setsockopt], [gl_cv_lib_socket], [ + gl_cv_lib_socket= + AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern +#ifdef __cplusplus +"C" +#endif +char setsockopt();]], [[setsockopt();]])], + [], + [gl_save_LIBS="$LIBS" + LIBS="$gl_save_LIBS -lsocket" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern +#ifdef __cplusplus +"C" +#endif +char setsockopt();]], [[setsockopt();]])], + [gl_cv_lib_socket="-lsocket"]) + if test -z "$gl_cv_lib_socket"; then + LIBS="$gl_save_LIBS -lnetwork" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern +#ifdef __cplusplus +"C" +#endif +char setsockopt();]], [[setsockopt();]])], + [gl_cv_lib_socket="-lnetwork"]) + if test -z "$gl_cv_lib_socket"; then + LIBS="$gl_save_LIBS -lnet" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern +#ifdef __cplusplus +"C" +#endif +char setsockopt();]], [[setsockopt();]])], + [gl_cv_lib_socket="-lnet"]) + fi + fi + LIBS="$gl_save_LIBS" + ]) + if test -z "$gl_cv_lib_socket"; then + gl_cv_lib_socket="none needed" + fi + ]) + if test "$gl_cv_lib_socket" != "none needed"; then + LIBSOCKET="$gl_cv_lib_socket" + fi + fi + AC_SUBST([LIBSOCKET]) +]) diff --git a/gnulib/import/m4/sockets.m4 b/gnulib/import/m4/sockets.m4 new file mode 100644 index 000000000000..02b43b6e7fe5 --- /dev/null +++ b/gnulib/import/m4/sockets.m4 @@ -0,0 +1,17 @@ +# sockets.m4 serial 7 +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_SOCKETS], +[ + AC_REQUIRE([AC_C_INLINE]) + AC_REQUIRE([gl_SOCKETLIB]) + gl_PREREQ_SOCKETS +]) + +# Prerequisites of lib/sockets.c. +AC_DEFUN([gl_PREREQ_SOCKETS], [ + : +]) diff --git a/gnulib/import/m4/sys_select_h.m4 b/gnulib/import/m4/sys_select_h.m4 new file mode 100644 index 000000000000..4b33d312e55d --- /dev/null +++ b/gnulib/import/m4/sys_select_h.m4 @@ -0,0 +1,95 @@ +# sys_select_h.m4 serial 20 +dnl Copyright (C) 2006-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_HEADER_SYS_SELECT], +[ + AC_REQUIRE([AC_C_RESTRICT]) + AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS]) + AC_CACHE_CHECK([whether is self-contained], + [gl_cv_header_sys_select_h_selfcontained], + [ + dnl Test against two bugs: + dnl 1. On many platforms, assumes prior inclusion of + dnl . + dnl 2. On OSF/1 4.0, provides only a forward declaration + dnl of 'struct timeval', and no definition of this type. + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[struct timeval b;]])], + [gl_cv_header_sys_select_h_selfcontained=yes], + [gl_cv_header_sys_select_h_selfcontained=no]) + dnl Test against another bug: + dnl 3. On Solaris 10, provides an FD_ZERO implementation + dnl that relies on memset(), but without including . + if test $gl_cv_header_sys_select_h_selfcontained = yes; then + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include ]], + [[int memset; int bzero;]]) + ], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[#include ]], [[ + #undef memset + #define memset nonexistent_memset + extern + #ifdef __cplusplus + "C" + #endif + void *memset (void *, int, unsigned long); + #undef bzero + #define bzero nonexistent_bzero + extern + #ifdef __cplusplus + "C" + #endif + void bzero (void *, unsigned long); + fd_set fds; + FD_ZERO (&fds); + ]]) + ], + [], + [gl_cv_header_sys_select_h_selfcontained=no]) + ]) + fi + ]) + dnl is always overridden, because of GNULIB_POSIXCHECK. + gl_CHECK_NEXT_HEADERS([sys/select.h]) + if test $ac_cv_header_sys_select_h = yes; then + HAVE_SYS_SELECT_H=1 + else + HAVE_SYS_SELECT_H=0 + fi + AC_SUBST([HAVE_SYS_SELECT_H]) + gl_PREREQ_SYS_H_WINSOCK2 + + 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([[ +/* Some systems require prerequisite headers. */ +#include +#if !(defined __GLIBC__ && !defined __UCLIBC__) && HAVE_SYS_TIME_H +# include +#endif +#include + ]], [pselect select]) +]) + +AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_SYS_SELECT_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_SELECT_H_DEFAULTS], +[ + GNULIB_PSELECT=0; AC_SUBST([GNULIB_PSELECT]) + GNULIB_SELECT=0; AC_SUBST([GNULIB_SELECT]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_PSELECT=1; AC_SUBST([HAVE_PSELECT]) + REPLACE_PSELECT=0; AC_SUBST([REPLACE_PSELECT]) + REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT]) +]) diff --git a/gnulib/import/select.c b/gnulib/import/select.c new file mode 100644 index 000000000000..56ac8bb7b586 --- /dev/null +++ b/gnulib/import/select.c @@ -0,0 +1,597 @@ +/* Emulation for select(2) + Contributed by Paolo Bonzini. + + Copyright 2008-2021 Free Software Foundation, Inc. + + This file is part of gnulib. + + 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 . */ + +#include + +/* Specification. */ +#include + +#if defined _WIN32 && ! defined __CYGWIN__ +/* Native Windows. */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/* Get the overridden 'struct timeval'. */ +#include + +#if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +#else +# include +#endif + +#undef select + +/* Don't assume that UNICODE is not defined. */ +#undef GetModuleHandle +#define GetModuleHandle GetModuleHandleA +#undef PeekConsoleInput +#define PeekConsoleInput PeekConsoleInputA +#undef CreateEvent +#define CreateEvent CreateEventA +#undef PeekMessage +#define PeekMessage PeekMessageA +#undef DispatchMessage +#define DispatchMessage DispatchMessageA + +/* Avoid warnings from gcc -Wcast-function-type. */ +#define GetProcAddress \ + (void *) GetProcAddress + +struct bitset { + unsigned char in[FD_SETSIZE / CHAR_BIT]; + unsigned char out[FD_SETSIZE / CHAR_BIT]; +}; + +/* Declare data structures for ntdll functions. */ +typedef struct _FILE_PIPE_LOCAL_INFORMATION { + ULONG NamedPipeType; + ULONG NamedPipeConfiguration; + ULONG MaximumInstances; + ULONG CurrentInstances; + ULONG InboundQuota; + ULONG ReadDataAvailable; + ULONG OutboundQuota; + ULONG WriteQuotaAvailable; + ULONG NamedPipeState; + ULONG NamedPipeEnd; +} FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION; + +typedef struct _IO_STATUS_BLOCK +{ + union { + DWORD Status; + PVOID Pointer; + } u; + ULONG_PTR Information; +} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; + +typedef enum _FILE_INFORMATION_CLASS { + FilePipeLocalInformation = 24 +} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS; + +typedef DWORD (WINAPI *PNtQueryInformationFile) + (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS); + +#ifndef PIPE_BUF +#define PIPE_BUF 512 +#endif + +static BOOL IsConsoleHandle (HANDLE h) +{ + DWORD mode; + return GetConsoleMode (h, &mode) != 0; +} + +static BOOL +IsSocketHandle (HANDLE h) +{ + WSANETWORKEVENTS ev; + + if (IsConsoleHandle (h)) + return FALSE; + + /* Under Wine, it seems that getsockopt returns 0 for pipes too. + WSAEnumNetworkEvents instead distinguishes the two correctly. */ + ev.lNetworkEvents = 0xDEADBEEF; + WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev); + return ev.lNetworkEvents != 0xDEADBEEF; +} + +/* Compute output fd_sets for libc descriptor FD (whose Windows handle is + H). */ + +static int +windows_poll_handle (HANDLE h, int fd, + struct bitset *rbits, + struct bitset *wbits, + struct bitset *xbits) +{ + BOOL read, write, except; + int i, ret; + INPUT_RECORD *irbuffer; + DWORD avail, nbuffer; + BOOL bRet; + IO_STATUS_BLOCK iosb; + FILE_PIPE_LOCAL_INFORMATION fpli; + static PNtQueryInformationFile NtQueryInformationFile; + static BOOL once_only; + + read = write = except = FALSE; + switch (GetFileType (h)) + { + case FILE_TYPE_DISK: + read = TRUE; + write = TRUE; + break; + + case FILE_TYPE_PIPE: + if (!once_only) + { + NtQueryInformationFile = (PNtQueryInformationFile) + GetProcAddress (GetModuleHandle ("ntdll.dll"), + "NtQueryInformationFile"); + once_only = TRUE; + } + + if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0) + { + if (avail) + read = TRUE; + } + else if (GetLastError () == ERROR_BROKEN_PIPE) + ; + + else + { + /* It was the write-end of the pipe. Check if it is writable. + If NtQueryInformationFile fails, optimistically assume the pipe is + writable. This could happen on Windows 9x, where + NtQueryInformationFile is not available, or if we inherit a pipe + that doesn't permit FILE_READ_ATTRIBUTES access on the write end + (I think this should not happen since Windows XP SP2; WINE seems + fine too). Otherwise, ensure that enough space is available for + atomic writes. */ + memset (&iosb, 0, sizeof (iosb)); + memset (&fpli, 0, sizeof (fpli)); + + if (!NtQueryInformationFile + || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli), + FilePipeLocalInformation) + || fpli.WriteQuotaAvailable >= PIPE_BUF + || (fpli.OutboundQuota < PIPE_BUF && + fpli.WriteQuotaAvailable == fpli.OutboundQuota)) + write = TRUE; + } + break; + + case FILE_TYPE_CHAR: + write = TRUE; + if (!(rbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1))))) + break; + + ret = WaitForSingleObject (h, 0); + if (ret == WAIT_OBJECT_0) + { + if (!IsConsoleHandle (h)) + { + read = TRUE; + break; + } + + nbuffer = avail = 0; + bRet = GetNumberOfConsoleInputEvents (h, &nbuffer); + + /* Screen buffers handles are filtered earlier. */ + assert (bRet); + if (nbuffer == 0) + { + except = TRUE; + break; + } + + irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD)); + bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail); + if (!bRet || avail == 0) + { + except = TRUE; + break; + } + + for (i = 0; i < avail; i++) + if (irbuffer[i].EventType == KEY_EVENT) + read = TRUE; + } + break; + + default: + ret = WaitForSingleObject (h, 0); + write = TRUE; + if (ret == WAIT_OBJECT_0) + read = TRUE; + + break; + } + + ret = 0; + if (read && (rbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1))))) + { + rbits->out[fd / CHAR_BIT] |= (1 << (fd & (CHAR_BIT - 1))); + ret++; + } + + if (write && (wbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1))))) + { + wbits->out[fd / CHAR_BIT] |= (1 << (fd & (CHAR_BIT - 1))); + ret++; + } + + if (except && (xbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1))))) + { + xbits->out[fd / CHAR_BIT] |= (1 << (fd & (CHAR_BIT - 1))); + ret++; + } + + return ret; +} + +int +rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, + struct timeval *timeout) +#undef timeval +{ + static struct timeval tv0; + static HANDLE hEvent; + HANDLE h, handle_array[FD_SETSIZE + 2]; + fd_set handle_rfds, handle_wfds, handle_xfds; + struct bitset rbits, wbits, xbits; + unsigned char anyfds_in[FD_SETSIZE / CHAR_BIT]; + DWORD ret, wait_timeout, nhandles, nsock, nbuffer; + MSG msg; + int i, fd, rc; + clock_t tend; + + if (nfds > FD_SETSIZE) + nfds = FD_SETSIZE; + + if (!timeout) + wait_timeout = INFINITE; + else + { + wait_timeout = timeout->tv_sec * 1000 + timeout->tv_usec / 1000; + + /* select is also used as a portable usleep. */ + if (!rfds && !wfds && !xfds) + { + Sleep (wait_timeout); + return 0; + } + } + + if (!hEvent) + hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); + + handle_array[0] = hEvent; + nhandles = 1; + nsock = 0; + + /* Copy descriptors to bitsets. At the same time, eliminate + bits in the "wrong" direction for console input buffers + and screen buffers, because screen buffers are waitable + and they will block until a character is available. */ + memset (&rbits, 0, sizeof (rbits)); + memset (&wbits, 0, sizeof (wbits)); + memset (&xbits, 0, sizeof (xbits)); + memset (anyfds_in, 0, sizeof (anyfds_in)); + if (rfds) + for (i = 0; i < rfds->fd_count; i++) + { + fd = rfds->fd_array[i]; + h = (HANDLE) _get_osfhandle (fd); + if (IsConsoleHandle (h) + && !GetNumberOfConsoleInputEvents (h, &nbuffer)) + continue; + + rbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1)); + anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1)); + } + else + rfds = (fd_set *) alloca (sizeof (fd_set)); + + if (wfds) + for (i = 0; i < wfds->fd_count; i++) + { + fd = wfds->fd_array[i]; + h = (HANDLE) _get_osfhandle (fd); + if (IsConsoleHandle (h) + && GetNumberOfConsoleInputEvents (h, &nbuffer)) + continue; + + wbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1)); + anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1)); + } + else + wfds = (fd_set *) alloca (sizeof (fd_set)); + + if (xfds) + for (i = 0; i < xfds->fd_count; i++) + { + fd = xfds->fd_array[i]; + xbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1)); + anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1)); + } + else + xfds = (fd_set *) alloca (sizeof (fd_set)); + + /* Zero all the fd_sets, including the application's. */ + FD_ZERO (rfds); + FD_ZERO (wfds); + FD_ZERO (xfds); + FD_ZERO (&handle_rfds); + FD_ZERO (&handle_wfds); + FD_ZERO (&handle_xfds); + + /* Classify handles. Create fd sets for sockets, poll the others. */ + for (i = 0; i < nfds; i++) + { + if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0) + continue; + + h = (HANDLE) _get_osfhandle (i); + if (!h) + { + errno = EBADF; + return -1; + } + + if (IsSocketHandle (h)) + { + int requested = FD_CLOSE; + + /* See above; socket handles are mapped onto select, but we + need to map descriptors to handles. */ + if (rbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) + { + requested |= FD_READ | FD_ACCEPT; + FD_SET ((SOCKET) h, rfds); + FD_SET ((SOCKET) h, &handle_rfds); + } + if (wbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) + { + requested |= FD_WRITE | FD_CONNECT; + FD_SET ((SOCKET) h, wfds); + FD_SET ((SOCKET) h, &handle_wfds); + } + if (xbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) + { + requested |= FD_OOB; + FD_SET ((SOCKET) h, xfds); + FD_SET ((SOCKET) h, &handle_xfds); + } + + WSAEventSelect ((SOCKET) h, hEvent, requested); + nsock++; + } + else + { + handle_array[nhandles++] = h; + + /* Poll now. If we get an event, do not wait below. */ + if (wait_timeout != 0 + && windows_poll_handle (h, i, &rbits, &wbits, &xbits)) + wait_timeout = 0; + } + } + + /* Place a sentinel at the end of the array. */ + handle_array[nhandles] = NULL; + + /* When will the waiting period expire? */ + if (wait_timeout != INFINITE) + tend = clock () + wait_timeout; + +restart: + if (wait_timeout == 0 || nsock == 0) + rc = 0; + else + { + /* See if we need to wait in the loop below. If any select is ready, + do MsgWaitForMultipleObjects anyway to dispatch messages, but + no need to call select again. */ + rc = select (0, &handle_rfds, &handle_wfds, &handle_xfds, &tv0); + if (rc == 0) + { + /* Restore the fd_sets for the other select we do below. */ + memcpy (&handle_rfds, rfds, sizeof (fd_set)); + memcpy (&handle_wfds, wfds, sizeof (fd_set)); + memcpy (&handle_xfds, xfds, sizeof (fd_set)); + } + else + wait_timeout = 0; + } + + /* How much is left to wait? */ + if (wait_timeout != INFINITE) + { + clock_t tnow = clock (); + if (tend >= tnow) + wait_timeout = tend - tnow; + else + wait_timeout = 0; + } + + for (;;) + { + ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE, + wait_timeout, QS_ALLINPUT); + + if (ret == WAIT_OBJECT_0 + nhandles) + { + /* new input of some other kind */ + BOOL bRet; + while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0) + { + TranslateMessage (&msg); + DispatchMessage (&msg); + } + } + else + break; + } + + /* If we haven't done it yet, check the status of the sockets. */ + if (rc == 0 && nsock > 0) + rc = select (0, &handle_rfds, &handle_wfds, &handle_xfds, &tv0); + + if (nhandles > 1) + { + /* Count results that are not counted in the return value of select. */ + nhandles = 1; + for (i = 0; i < nfds; i++) + { + if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0) + continue; + + h = (HANDLE) _get_osfhandle (i); + if (h == handle_array[nhandles]) + { + /* Not a socket. */ + nhandles++; + windows_poll_handle (h, i, &rbits, &wbits, &xbits); + if (rbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))) + || wbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))) + || xbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) + rc++; + } + } + + if (rc == 0 + && (wait_timeout == INFINITE + /* If NHANDLES > 1, but no bits are set, it means we've + been told incorrectly that some handle was signaled. + This happens with anonymous pipes, which always cause + MsgWaitForMultipleObjects to exit immediately, but no + data is found ready to be read by windows_poll_handle. + To avoid a total failure (whereby we return zero and + don't wait at all), let's poll in a more busy loop. */ + || (wait_timeout != 0 && nhandles > 1))) + { + /* Sleep 1 millisecond to avoid busy wait and retry with the + original fd_sets. */ + memcpy (&handle_rfds, rfds, sizeof (fd_set)); + memcpy (&handle_wfds, wfds, sizeof (fd_set)); + memcpy (&handle_xfds, xfds, sizeof (fd_set)); + SleepEx (1, TRUE); + goto restart; + } + if (timeout && wait_timeout == 0 && rc == 0) + timeout->tv_sec = timeout->tv_usec = 0; + } + + /* Now fill in the results. */ + FD_ZERO (rfds); + FD_ZERO (wfds); + FD_ZERO (xfds); + nhandles = 1; + for (i = 0; i < nfds; i++) + { + if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0) + continue; + + h = (HANDLE) _get_osfhandle (i); + if (h != handle_array[nhandles]) + { + /* Perform handle->descriptor mapping. */ + WSAEventSelect ((SOCKET) h, NULL, 0); + if (FD_ISSET (h, &handle_rfds)) + FD_SET (i, rfds); + if (FD_ISSET (h, &handle_wfds)) + FD_SET (i, wfds); + if (FD_ISSET (h, &handle_xfds)) + FD_SET (i, xfds); + } + else + { + /* Not a socket. */ + nhandles++; + if (rbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) + FD_SET (i, rfds); + if (wbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) + FD_SET (i, wfds); + if (xbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) + FD_SET (i, xfds); + } + } + + return rc; +} + +#else /* ! Native Windows. */ + +#include /* NULL */ +#include +#include + +#undef select + +int +rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, + struct timeval *timeout) +{ + int i; + + /* FreeBSD 8.2 has a bug: it does not always detect invalid fds. */ + if (nfds < 0 || nfds > FD_SETSIZE) + { + errno = EINVAL; + return -1; + } + for (i = 0; i < nfds; i++) + { + if (((rfds && FD_ISSET (i, rfds)) + || (wfds && FD_ISSET (i, wfds)) + || (xfds && FD_ISSET (i, xfds))) + && dup2 (i, i) != i) + return -1; + } + + /* Interix 3.5 has a bug: it does not support nfds == 0. */ + if (nfds == 0) + { + nfds = 1; + rfds = NULL; + wfds = NULL; + xfds = NULL; + } + return select (nfds, rfds, wfds, xfds, timeout); +} + +#endif diff --git a/gnulib/import/sockets.c b/gnulib/import/sockets.c new file mode 100644 index 000000000000..2de48d25b312 --- /dev/null +++ b/gnulib/import/sockets.c @@ -0,0 +1,161 @@ +/* sockets.c --- wrappers for Windows socket functions + + 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 . */ + +/* Written by Simon Josefsson */ + +#include + +/* Specification. */ +#include "sockets.h" + +#if WINDOWS_SOCKETS + +/* This includes winsock2.h on MinGW. */ +# include + +# include "fd-hook.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif + +/* Get set_winsock_errno, FD_TO_SOCKET etc. */ +# include "w32sock.h" + +static int +close_fd_maybe_socket (const struct fd_hook *remaining_list, + gl_close_fn primary, + int fd) +{ + /* Note about multithread-safety: There is a race condition where, between + our calls to closesocket() and the primary close(), some other thread + could make system calls that allocate precisely the same HANDLE value + as sock; then the primary close() would call CloseHandle() on it. */ + SOCKET sock; + WSANETWORKEVENTS ev; + + /* Test whether fd refers to a socket. */ + sock = FD_TO_SOCKET (fd); + ev.lNetworkEvents = 0xDEADBEEF; + WSAEnumNetworkEvents (sock, NULL, &ev); + if (ev.lNetworkEvents != 0xDEADBEEF) + { + /* fd refers to a socket. */ + /* FIXME: other applications, like squid, use an undocumented + _free_osfhnd free function. But this is not enough: The 'osfile' + flags for fd also needs to be cleared, but it is hard to access it. + Instead, here we just close twice the file descriptor. */ + if (closesocket (sock)) + { + set_winsock_errno (); + return -1; + } + else + { + /* This call frees the file descriptor and does a + CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails. */ + _close (fd); + return 0; + } + } + else + /* Some other type of file descriptor. */ + return execute_close_hooks (remaining_list, primary, fd); +} + +static int +ioctl_fd_maybe_socket (const struct fd_hook *remaining_list, + gl_ioctl_fn primary, + int fd, int request, void *arg) +{ + SOCKET sock; + WSANETWORKEVENTS ev; + + /* Test whether fd refers to a socket. */ + sock = FD_TO_SOCKET (fd); + ev.lNetworkEvents = 0xDEADBEEF; + WSAEnumNetworkEvents (sock, NULL, &ev); + if (ev.lNetworkEvents != 0xDEADBEEF) + { + /* fd refers to a socket. */ + if (ioctlsocket (sock, request, arg) < 0) + { + set_winsock_errno (); + return -1; + } + else + return 0; + } + else + /* Some other type of file descriptor. */ + return execute_ioctl_hooks (remaining_list, primary, fd, request, arg); +} + +static struct fd_hook fd_sockets_hook; + +static int initialized_sockets_version /* = 0 */; + +#endif /* WINDOWS_SOCKETS */ + +int +gl_sockets_startup (int version _GL_UNUSED) +{ +#if WINDOWS_SOCKETS + if (version > initialized_sockets_version) + { + WSADATA data; + int err; + + err = WSAStartup (version, &data); + if (err != 0) + return 1; + + if (data.wVersion != version) + { + WSACleanup (); + return 2; + } + + if (initialized_sockets_version == 0) + register_fd_hook (close_fd_maybe_socket, ioctl_fd_maybe_socket, + &fd_sockets_hook); + + initialized_sockets_version = version; + } +#endif + + return 0; +} + +int +gl_sockets_cleanup (void) +{ +#if WINDOWS_SOCKETS + int err; + + initialized_sockets_version = 0; + + unregister_fd_hook (&fd_sockets_hook); + + err = WSACleanup (); + if (err != 0) + return 1; +#endif + + return 0; +} diff --git a/gnulib/import/sockets.h b/gnulib/import/sockets.h new file mode 100644 index 000000000000..e0729c241467 --- /dev/null +++ b/gnulib/import/sockets.h @@ -0,0 +1,66 @@ +/* sockets.h - wrappers for Windows socket functions + + 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 . */ + +/* Written by Simon Josefsson */ + +#ifndef SOCKETS_H +#define SOCKETS_H 1 + +#define SOCKETS_1_0 0x0001 +#define SOCKETS_1_1 0x0101 +#define SOCKETS_2_0 0x0002 +#define SOCKETS_2_1 0x0102 +#define SOCKETS_2_2 0x0202 + +int gl_sockets_startup (int version) +#ifndef WINDOWS_SOCKETS + _GL_ATTRIBUTE_CONST +#endif + ; + +int gl_sockets_cleanup (void) +#ifndef WINDOWS_SOCKETS + _GL_ATTRIBUTE_CONST +#endif + ; + +/* This function is useful it you create a socket using gnulib's + Winsock wrappers but needs to pass on the socket handle to some + other library that only accepts sockets. */ +#ifdef WINDOWS_SOCKETS + +# include + +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif + +static inline SOCKET +gl_fd_to_handle (int fd) +{ + return _get_osfhandle (fd); +} + +#else + +# define gl_fd_to_handle(x) (x) + +#endif /* WINDOWS_SOCKETS */ + +#endif /* SOCKETS_H */ diff --git a/gnulib/import/sys_select.in.h b/gnulib/import/sys_select.in.h new file mode 100644 index 000000000000..1dacb21087db --- /dev/null +++ b/gnulib/import/sys_select.in.h @@ -0,0 +1,326 @@ +/* Substitute for . + Copyright (C) 2007-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 . */ + +# if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +# endif +@PRAGMA_COLUMNS@ + +/* On OSF/1 and Solaris 2.6, and + both include . + On Cygwin, includes . + Simply delegate to the system's header in this case. */ +#if (@HAVE_SYS_SELECT_H@ \ + && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H \ + && ((defined __osf__ && defined _SYS_TYPES_H_ \ + && defined _OSF_SOURCE) \ + || (defined __sun && defined _SYS_TYPES_H \ + && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \ + || defined __EXTENSIONS__)))) + +# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H +# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@ + +#elif (@HAVE_SYS_SELECT_H@ \ + && (defined _CYGWIN_SYS_TIME_H \ + || (!defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H \ + && ((defined __osf__ && defined _SYS_TIME_H_ \ + && defined _OSF_SOURCE) \ + || (defined __sun && defined _SYS_TIME_H \ + && (! (defined _XOPEN_SOURCE \ + || defined _POSIX_C_SOURCE) \ + || defined __EXTENSIONS__)))))) + +# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H +# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@ + +/* On IRIX 6.5, includes , which includes + , which includes . At this point we cannot + include , because that includes , which + gives a syntax error because has not been completely + processed. Simply delegate to the system's header in this case. */ +#elif @HAVE_SYS_SELECT_H@ && defined __sgi && (defined _SYS_BSD_TYPES_H && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H) + +# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H +# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@ + +/* On OpenBSD 5.0, includes , which includes + . At this point we cannot include , because that + includes gnulib's pthread.h override, which gives a syntax error because + /usr/include/pthread.h has not been completely processed. Simply delegate + to the system's header in this case. */ +#elif @HAVE_SYS_SELECT_H@ && defined __OpenBSD__ && (defined _PTHREAD_H_ && !defined PTHREAD_MUTEX_INITIALIZER) + +# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@ + +#else + +#ifndef _@GUARD_PREFIX@_SYS_SELECT_H + +/* On many platforms, assumes prior inclusion of + . Also, mingw defines sigset_t there, instead of + in where it belongs. */ +#include + +#if @HAVE_SYS_SELECT_H@ + +/* On OSF/1 4.0, provides only a forward declaration + of 'struct timeval', and no definition of this type. + Also, Mac OS X, AIX, HP-UX, IRIX, Solaris, Interix declare select() + in . + But avoid namespace pollution on glibc systems and "unknown type + name" problems on Cygwin. */ +# if !(defined __GLIBC__ || defined __CYGWIN__) +# include +# endif + +/* On AIX 7 and Solaris 10, provides an FD_ZERO implementation + that relies on memset(), but without including . + But in any case avoid namespace pollution on glibc systems. */ +# if (defined __OpenBSD__ || defined _AIX || defined __sun || defined __osf__ || defined __BEOS__) \ + && ! defined __GLIBC__ +# include +# endif + +/* The include_next requires a split double-inclusion guard. */ +# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@ + +#endif + +/* Get definition of 'sigset_t'. + But avoid namespace pollution on glibc systems and "unknown type + name" problems on Cygwin. + On OS/2 kLIBC, sigset_t is defined in , too. In addition, + if is included, -> -> + are included. Then -> are included by GNULIB. By the + way, requires PAGE_SIZE defined in . However, + has not been processed, yet. As a result, 'PAGE_SIZE' + undeclared error occurs in . + Do this after the include_next (for the sake of OpenBSD 5.0) but before + the split double-inclusion guard (for the sake of Solaris). */ +#if !((defined __GLIBC__ || defined __CYGWIN__ || defined __KLIBC__) \ + && !defined __UCLIBC__) +# include +#endif + +#ifndef _@GUARD_PREFIX@_SYS_SELECT_H +#define _@GUARD_PREFIX@_SYS_SELECT_H + +#if !@HAVE_SYS_SELECT_H@ +/* A platform that lacks . */ +/* Get the 'struct timeval' and 'fd_set' types and the FD_* macros + on most platforms. */ +# include +/* On HP-UX 11, provides an FD_ZERO implementation + that relies on memset(), but without including . */ +# if defined __hpux +# include +# endif +/* On native Windows platforms: + Get the 'fd_set' type. + Get the close() declaration before we override it. */ +# if @HAVE_WINSOCK2_H@ +# if !defined _GL_INCLUDING_WINSOCK2_H +# define _GL_INCLUDING_WINSOCK2_H +# include +# undef _GL_INCLUDING_WINSOCK2_H +# endif +# include +# endif +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + + +/* Fix some definitions from . */ + +#if @HAVE_WINSOCK2_H@ + +# if !GNULIB_defined_rpl_fd_isset + +/* Re-define FD_ISSET to avoid a WSA call while we are not using + network sockets. */ +static int +rpl_fd_isset (SOCKET fd, fd_set * set) +{ + u_int i; + if (set == NULL) + return 0; + + for (i = 0; i < set->fd_count; i++) + if (set->fd_array[i] == fd) + return 1; + + return 0; +} + +# define GNULIB_defined_rpl_fd_isset 1 +# endif + +# undef FD_ISSET +# define FD_ISSET(fd, set) rpl_fd_isset(fd, set) + +#endif + +/* Hide some function declarations from . */ + +#if @HAVE_WINSOCK2_H@ +# if !defined _@GUARD_PREFIX@_UNISTD_H +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef close +# define close close_used_without_including_unistd_h +# elif !defined __clang__ + _GL_WARN_ON_USE (close, + "close() used without including "); +# endif +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef gethostname +# define gethostname gethostname_used_without_including_unistd_h +# elif !defined __clang__ + _GL_WARN_ON_USE (gethostname, + "gethostname() used without including "); +# endif +# endif +# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef socket +# define socket socket_used_without_including_sys_socket_h +# undef connect +# define connect connect_used_without_including_sys_socket_h +# undef accept +# define accept accept_used_without_including_sys_socket_h +# undef bind +# define bind bind_used_without_including_sys_socket_h +# undef getpeername +# define getpeername getpeername_used_without_including_sys_socket_h +# undef getsockname +# define getsockname getsockname_used_without_including_sys_socket_h +# undef getsockopt +# define getsockopt getsockopt_used_without_including_sys_socket_h +# undef listen +# define listen listen_used_without_including_sys_socket_h +# undef recv +# define recv recv_used_without_including_sys_socket_h +# undef send +# define send send_used_without_including_sys_socket_h +# undef recvfrom +# define recvfrom recvfrom_used_without_including_sys_socket_h +# undef sendto +# define sendto sendto_used_without_including_sys_socket_h +# undef setsockopt +# define setsockopt setsockopt_used_without_including_sys_socket_h +# undef shutdown +# define shutdown shutdown_used_without_including_sys_socket_h +# elif !defined __clang__ + _GL_WARN_ON_USE (socket, + "socket() used without including "); + _GL_WARN_ON_USE (connect, + "connect() used without including "); + _GL_WARN_ON_USE (accept, + "accept() used without including "); + _GL_WARN_ON_USE (bind, + "bind() used without including "); + _GL_WARN_ON_USE (getpeername, + "getpeername() used without including "); + _GL_WARN_ON_USE (getsockname, + "getsockname() used without including "); + _GL_WARN_ON_USE (getsockopt, + "getsockopt() used without including "); + _GL_WARN_ON_USE (listen, + "listen() used without including "); + _GL_WARN_ON_USE (recv, + "recv() used without including "); + _GL_WARN_ON_USE (send, + "send() used without including "); + _GL_WARN_ON_USE (recvfrom, + "recvfrom() used without including "); + _GL_WARN_ON_USE (sendto, + "sendto() used without including "); + _GL_WARN_ON_USE (setsockopt, + "setsockopt() used without including "); + _GL_WARN_ON_USE (shutdown, + "shutdown() used without including "); +# endif +# endif +#endif + + +#if @GNULIB_PSELECT@ +# if @REPLACE_PSELECT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef pselect +# define pselect rpl_pselect +# endif +_GL_FUNCDECL_RPL (pselect, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + struct timespec const *restrict, const sigset_t *restrict)); +_GL_CXXALIAS_RPL (pselect, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + struct timespec const *restrict, const sigset_t *restrict)); +# else +# if !@HAVE_PSELECT@ +_GL_FUNCDECL_SYS (pselect, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + struct timespec const *restrict, const sigset_t *restrict)); +# endif +_GL_CXXALIAS_SYS (pselect, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + struct timespec const *restrict, const sigset_t *restrict)); +# endif +_GL_CXXALIASWARN (pselect); +#elif defined GNULIB_POSIXCHECK +# undef pselect +# if HAVE_RAW_DECL_PSELECT +_GL_WARN_ON_USE (pselect, "pselect is not portable - " + "use gnulib module pselect for portability"); +# endif +#endif + +#if @GNULIB_SELECT@ +# if @REPLACE_SELECT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef select +# define select rpl_select +# endif +_GL_FUNCDECL_RPL (select, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + struct timeval *restrict)); +_GL_CXXALIAS_RPL (select, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + timeval *restrict)); +# else +_GL_CXXALIAS_SYS (select, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + timeval *restrict)); +# endif +_GL_CXXALIASWARN (select); +#elif @HAVE_WINSOCK2_H@ +# undef select +# define select select_used_without_requesting_gnulib_module_select +#elif defined GNULIB_POSIXCHECK +# undef select +# if HAVE_RAW_DECL_SELECT +_GL_WARN_ON_USE (select, "select is not always POSIX compliant - " + "use gnulib module select for portability"); +# endif +#endif + + +#endif /* _@GUARD_PREFIX@_SYS_SELECT_H */ +#endif /* _@GUARD_PREFIX@_SYS_SELECT_H */ +#endif /* OSF/1 */ diff --git a/gnulib/import/w32sock.h b/gnulib/import/w32sock.h new file mode 100644 index 000000000000..f7311887b2c6 --- /dev/null +++ b/gnulib/import/w32sock.h @@ -0,0 +1,140 @@ +/* w32sock.h --- internal auxiliary functions for Windows socket functions + + 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 . */ + +/* Written by Paolo Bonzini */ + +#include + +/* Get O_RDWR and O_BINARY. */ +#include + +/* Get _open_osfhandle(). */ +#include + +/* Get _get_osfhandle(). */ +#if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +#else +# include +#endif + +#define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd))) +#define SOCKET_TO_FD(fh) (_open_osfhandle ((intptr_t) (fh), O_RDWR | O_BINARY)) + +static inline void +set_winsock_errno (void) +{ + int err = WSAGetLastError (); + + /* Map some WSAE* errors to the runtime library's error codes. */ + switch (err) + { + case WSA_INVALID_HANDLE: + errno = EBADF; + break; + case WSA_NOT_ENOUGH_MEMORY: + errno = ENOMEM; + break; + case WSA_INVALID_PARAMETER: + errno = EINVAL; + break; + case WSAENAMETOOLONG: + errno = ENAMETOOLONG; + break; + case WSAENOTEMPTY: + errno = ENOTEMPTY; + break; + case WSAEWOULDBLOCK: + errno = EWOULDBLOCK; + break; + case WSAEINPROGRESS: + errno = EINPROGRESS; + break; + case WSAEALREADY: + errno = EALREADY; + break; + case WSAENOTSOCK: + errno = ENOTSOCK; + break; + case WSAEDESTADDRREQ: + errno = EDESTADDRREQ; + break; + case WSAEMSGSIZE: + errno = EMSGSIZE; + break; + case WSAEPROTOTYPE: + errno = EPROTOTYPE; + break; + case WSAENOPROTOOPT: + errno = ENOPROTOOPT; + break; + case WSAEPROTONOSUPPORT: + errno = EPROTONOSUPPORT; + break; + case WSAEOPNOTSUPP: + errno = EOPNOTSUPP; + break; + case WSAEAFNOSUPPORT: + errno = EAFNOSUPPORT; + break; + case WSAEADDRINUSE: + errno = EADDRINUSE; + break; + case WSAEADDRNOTAVAIL: + errno = EADDRNOTAVAIL; + break; + case WSAENETDOWN: + errno = ENETDOWN; + break; + case WSAENETUNREACH: + errno = ENETUNREACH; + break; + case WSAENETRESET: + errno = ENETRESET; + break; + case WSAECONNABORTED: + errno = ECONNABORTED; + break; + case WSAECONNRESET: + errno = ECONNRESET; + break; + case WSAENOBUFS: + errno = ENOBUFS; + break; + case WSAEISCONN: + errno = EISCONN; + break; + case WSAENOTCONN: + errno = ENOTCONN; + break; + case WSAETIMEDOUT: + errno = ETIMEDOUT; + break; + case WSAECONNREFUSED: + errno = ECONNREFUSED; + break; + case WSAELOOP: + errno = ELOOP; + break; + case WSAEHOSTUNREACH: + errno = EHOSTUNREACH; + break; + default: + errno = (err > 10000 && err < 10025) ? err - 10000 : err; + break; + } +} diff --git a/gnulib/update-gnulib.sh b/gnulib/update-gnulib.sh index 252f163bf2ed..08c43fcfc143 100755 --- a/gnulib/update-gnulib.sh +++ b/gnulib/update-gnulib.sh @@ -60,6 +60,7 @@ IMPORTED_GNULIB_MODULES="\ rawmemchr \ readlink \ rename \ + select \ setenv \ signal-h \ strchrnul \ -- 2.31.1