gnulib: import various network functions

Some sim ports use these to provide networking functionality via the
dv-sockser module or via direct emulation for a few ports.

Gdb seems to build just fine still too.
This commit is contained in:
Mike Frysinger 2021-05-29 15:57:48 -04:00
parent 828a9ed9ca
commit c54d02bce6
13 changed files with 1719 additions and 1051 deletions

View File

@ -143,6 +143,12 @@
whether the gnulib module tempname shall be considered present. */
#undef GNULIB_TEMPNAME
/* Define to 1 when the gnulib module accept should be tested. */
#undef GNULIB_TEST_ACCEPT
/* Define to 1 when the gnulib module bind should be tested. */
#undef GNULIB_TEST_BIND
/* Define to 1 when the gnulib module btowc should be tested. */
#undef GNULIB_TEST_BTOWC
@ -165,6 +171,9 @@
/* Define to 1 when the gnulib module closedir should be tested. */
#undef GNULIB_TEST_CLOSEDIR
/* Define to 1 when the gnulib module connect should be tested. */
#undef GNULIB_TEST_CONNECT
/* Define to 1 when the gnulib module dirfd should be tested. */
#undef GNULIB_TEST_DIRFD
@ -228,6 +237,9 @@
/* Define to 1 when the gnulib module glob should be tested. */
#undef GNULIB_TEST_GLOB
/* Define to 1 when the gnulib module listen should be tested. */
#undef GNULIB_TEST_LISTEN
/* Define to 1 when the gnulib module lstat should be tested. */
#undef GNULIB_TEST_LSTAT
@ -312,6 +324,12 @@
/* Define to 1 when the gnulib module setlocale_null should be tested. */
#undef GNULIB_TEST_SETLOCALE_NULL
/* Define to 1 when the gnulib module setsockopt should be tested. */
#undef GNULIB_TEST_SETSOCKOPT
/* Define to 1 when the gnulib module socket should be tested. */
#undef GNULIB_TEST_SOCKET
/* Define to 1 when the gnulib module stat should be tested. */
#undef GNULIB_TEST_STAT

2213
gnulib/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -33,9 +33,12 @@
# --no-libtool \
# --macro-prefix=gl \
# --no-vc-files \
# accept \
# alloca \
# bind \
# canonicalize-lgpl \
# chown \
# connect \
# count-one-bits \
# dirent \
# dirfd \
@ -52,6 +55,7 @@
# inet_ntop \
# inttypes \
# limits-h \
# listen \
# lstat \
# memchr \
# memmem \
@ -65,7 +69,9 @@
# rename \
# select \
# setenv \
# setsockopt \
# signal-h \
# socket \
# strchrnul \
# strerror_r-posix \
# strstr \
@ -115,6 +121,15 @@ HAVE_INCLUDE_NEXT = (__GNUC__ || __clang__ || 60000000 <= __DECC_VER)
## end gnulib module absolute-header
## begin gnulib module accept
EXTRA_DIST += accept.c w32sock.h
EXTRA_libgnu_a_SOURCES += accept.c
## end gnulib module accept
## begin gnulib module alloca
@ -214,6 +229,15 @@ EXTRA_DIST += basename-lgpl.h
## end gnulib module basename-lgpl
## begin gnulib module bind
EXTRA_DIST += bind.c w32sock.h
EXTRA_libgnu_a_SOURCES += bind.c
## end gnulib module bind
## begin gnulib module btowc
@ -276,6 +300,15 @@ EXTRA_libgnu_a_SOURCES += closedir.c
## end gnulib module closedir
## begin gnulib module connect
EXTRA_DIST += connect.c w32sock.h
EXTRA_libgnu_a_SOURCES += connect.c
## end gnulib module connect
## begin gnulib module count-one-bits
libgnu_a_SOURCES += count-one-bits.c
@ -976,6 +1009,15 @@ EXTRA_DIST += limits.in.h
## end gnulib module limits-h
## begin gnulib module listen
EXTRA_DIST += listen.c w32sock.h
EXTRA_libgnu_a_SOURCES += listen.c
## end gnulib module listen
## begin gnulib module localcharset
libgnu_a_SOURCES += localcharset.c
@ -1731,6 +1773,15 @@ EXTRA_libgnu_a_SOURCES += setlocale-lock.c
## end gnulib module setlocale-null
## begin gnulib module setsockopt
EXTRA_DIST += setsockopt.c w32sock.h
EXTRA_libgnu_a_SOURCES += setsockopt.c
## end gnulib module setsockopt
## begin gnulib module signal-h
BUILT_SOURCES += signal.h
@ -1821,6 +1872,15 @@ EXTRA_DIST += warn-on-use.h
## end gnulib module snippet/warn-on-use
## begin gnulib module socket
EXTRA_DIST += socket.c w32sock.h
EXTRA_libgnu_a_SOURCES += socket.c
## end gnulib module socket
## begin gnulib module sockets
libgnu_a_SOURCES += sockets.h sockets.c

View File

@ -47,9 +47,12 @@
# --no-libtool \
# --macro-prefix=gl \
# --no-vc-files \
# accept \
# alloca \
# bind \
# canonicalize-lgpl \
# chown \
# connect \
# count-one-bits \
# dirent \
# dirfd \
@ -66,6 +69,7 @@
# inet_ntop \
# inttypes \
# limits-h \
# listen \
# lstat \
# memchr \
# memmem \
@ -79,7 +83,9 @@
# rename \
# select \
# setenv \
# setsockopt \
# signal-h \
# socket \
# strchrnul \
# strerror_r-posix \
# strstr \
@ -1820,10 +1826,11 @@ noinst_HEADERS =
noinst_LIBRARIES = libgnu.a
noinst_LTLIBRARIES =
# No GNU Make output.
EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h arpa_inet.in.h \
assure.h attribute.h basename-lgpl.h btowc.c \
canonicalize-lgpl.c chdir-long.c chdir-long.h chown.c \
fchown-stub.c cloexec.h close.c closedir.c dirent-private.h \
EXTRA_DIST = m4/gnulib-cache.m4 accept.c w32sock.h alloca.c \
alloca.in.h arpa_inet.in.h assure.h attribute.h \
basename-lgpl.h bind.c w32sock.h btowc.c canonicalize-lgpl.c \
chdir-long.c chdir-long.h chown.c fchown-stub.c cloexec.h \
close.c closedir.c dirent-private.h connect.c w32sock.h \
count-one-bits.h ctype.in.h dirent.in.h dirfd.c dirname.h \
dup.c dup2.c eloop-threshold.h errno.in.h error.c error.h \
exitfail.h fchdir.c fcntl.c fcntl.in.h fd-hook.h fdopendir.c \
@ -1838,8 +1845,8 @@ EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h arpa_inet.in.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 localcharset.h locale.in.h lstat.c malloc.c \
malloca.h math.in.h lc-charset-dispatch.c \
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 \
@ -1852,17 +1859,17 @@ EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h arpa_inet.in.h \
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 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 sys_wait.in.h tempname.h time.in.h time_r.c \
unistd.in.h unistd--.h unistd-safer.h unsetenv.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 \
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 \
$(top_srcdir)/import/extra/update-copyright verify.h \
wchar.in.h wctype.in.h windows-initguard.h windows-mutex.c \
windows-mutex.h windows-once.c windows-once.h \
@ -1912,25 +1919,26 @@ libgnu_a_SOURCES = openat-priv.h openat-proc.c basename-lgpl.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 \
chdir-long.c chown.c fchown-stub.c close.c closedir.c dirfd.c \
dup.c dup2.c error.c fchdir.c fcntl.c fdopendir.c ffs.c \
float.c itold.c fnmatch.c fnmatch_loop.c fnmatch.c free.c \
frexp.c frexp.c frexpl.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 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 \
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
EXTRA_libgnu_a_SOURCES = accept.c alloca.c bind.c btowc.c \
canonicalize-lgpl.c chdir-long.c chown.c fchown-stub.c close.c \
closedir.c connect.c dirfd.c dup.c dup2.c error.c fchdir.c \
fcntl.c fdopendir.c ffs.c float.c itold.c fnmatch.c \
fnmatch_loop.c fnmatch.c free.c frexp.c frexp.c frexpl.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 \
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
# Use this preprocessor expression to decide whether #include_next works.
# Do not rely on a 'configure'-time test for this, since the expression
@ -2042,9 +2050,11 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/accept.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alloca.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/at-func.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basename-lgpl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bind.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/btowc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/canonicalize-lgpl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chdir-long.Po@am__quote@
@ -2052,6 +2062,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cloexec.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/close.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/closedir.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connect.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/count-one-bits.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dirfd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dirname-lgpl.Po@am__quote@
@ -2098,6 +2109,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isnanl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/itold.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lc-charset-dispatch.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/listen.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/localcharset.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/malloc.Po@am__quote@
@ -2137,6 +2149,8 @@ distclean-compile:
@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)/setsockopt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socket.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@

52
gnulib/import/accept.c Normal file
View File

@ -0,0 +1,52 @@
/* accept.c --- wrappers for Windows accept 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>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
#undef accept
int
rpl_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
{
SOCKET sock = FD_TO_SOCKET (fd);
if (sock == INVALID_SOCKET)
{
errno = EBADF;
return -1;
}
else
{
SOCKET fh = accept (sock, addr, addrlen);
if (fh == INVALID_SOCKET)
{
set_winsock_errno ();
return -1;
}
else
return SOCKET_TO_FD (fh);
}
}

49
gnulib/import/bind.c Normal file
View File

@ -0,0 +1,49 @@
/* bind.c --- wrappers for Windows bind 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>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
#undef bind
int
rpl_bind (int fd, const struct sockaddr *sockaddr, socklen_t len)
{
SOCKET sock = FD_TO_SOCKET (fd);
if (sock == INVALID_SOCKET)
{
errno = EBADF;
return -1;
}
else
{
int r = bind (sock, sockaddr, len);
if (r < 0)
set_winsock_errno ();
return r;
}
}

56
gnulib/import/connect.c Normal file
View File

@ -0,0 +1,56 @@
/* connect.c --- wrappers for Windows connect 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>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
#undef connect
int
rpl_connect (int fd, const struct sockaddr *sockaddr, socklen_t len)
{
SOCKET sock = FD_TO_SOCKET (fd);
if (sock == INVALID_SOCKET)
{
errno = EBADF;
return -1;
}
else
{
int r = connect (sock, sockaddr, len);
if (r < 0)
{
/* EINPROGRESS is not returned by WinSock 2.0; for backwards
compatibility, connect(2) uses EWOULDBLOCK. */
if (WSAGetLastError () == WSAEWOULDBLOCK)
WSASetLastError (WSAEINPROGRESS);
set_winsock_errno ();
}
return r;
}
}

49
gnulib/import/listen.c Normal file
View File

@ -0,0 +1,49 @@
/* listen.c --- wrappers for Windows listen 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>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
#undef listen
int
rpl_listen (int fd, int backlog)
{
SOCKET sock = FD_TO_SOCKET (fd);
if (sock == INVALID_SOCKET)
{
errno = EBADF;
return -1;
}
else
{
int r = listen (sock, backlog);
if (r < 0)
set_winsock_errno ();
return r;
}
}

View File

@ -38,9 +38,12 @@
# --no-libtool \
# --macro-prefix=gl \
# --no-vc-files \
# accept \
# alloca \
# bind \
# canonicalize-lgpl \
# chown \
# connect \
# count-one-bits \
# dirent \
# dirfd \
@ -57,6 +60,7 @@
# inet_ntop \
# inttypes \
# limits-h \
# listen \
# lstat \
# memchr \
# memmem \
@ -70,7 +74,9 @@
# rename \
# select \
# setenv \
# setsockopt \
# signal-h \
# socket \
# strchrnul \
# strerror_r-posix \
# strstr \
@ -87,9 +93,12 @@
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([])
gl_MODULES([
accept
alloca
bind
canonicalize-lgpl
chown
connect
count-one-bits
dirent
dirfd
@ -106,6 +115,7 @@ gl_MODULES([
inet_ntop
inttypes
limits-h
listen
lstat
memchr
memmem
@ -119,7 +129,9 @@ gl_MODULES([
rename
select
setenv
setsockopt
signal-h
socket
strchrnul
strerror_r-posix
strstr

View File

@ -44,6 +44,7 @@ AC_DEFUN([gl_EARLY],
AC_REQUIRE([AM_PROG_CC_C_O])
# Code from module absolute-header:
# Code from module accept:
# Code from module alloca:
# Code from module alloca-opt:
# Code from module arpa_inet:
@ -51,6 +52,7 @@ AC_DEFUN([gl_EARLY],
# Code from module at-internal:
# Code from module attribute:
# Code from module basename-lgpl:
# Code from module bind:
# Code from module btowc:
# Code from module builtin-expect:
# Code from module c99:
@ -62,6 +64,7 @@ AC_DEFUN([gl_EARLY],
# Code from module cloexec:
# Code from module close:
# Code from module closedir:
# Code from module connect:
# Code from module count-one-bits:
# Code from module ctype:
# Code from module d-ino:
@ -129,6 +132,7 @@ AC_DEFUN([gl_EARLY],
AC_REQUIRE([AC_SYS_LARGEFILE])
# Code from module libc-config:
# Code from module limits-h:
# Code from module listen:
# Code from module localcharset:
# Code from module locale:
# Code from module lock:
@ -175,11 +179,13 @@ AC_DEFUN([gl_EARLY],
# Code from module select:
# Code from module setenv:
# Code from module setlocale-null:
# Code from module setsockopt:
# Code from module signal-h:
# Code from module snippet/_Noreturn:
# Code from module snippet/arg-nonnull:
# Code from module snippet/c++defs:
# Code from module snippet/warn-on-use:
# Code from module socket:
# Code from module socketlib:
# Code from module sockets:
# Code from module socklen:
@ -251,10 +257,20 @@ AC_DEFUN([gl_INIT],
m4_pushdef([gl_LIBSOURCES_DIR], [])
gl_COMMON
gl_source_base='import'
AC_REQUIRE([gl_HEADER_SYS_SOCKET])
if test "$ac_cv_header_winsock2_h" = yes; then
AC_LIBOBJ([accept])
fi
gl_SYS_SOCKET_MODULE_INDICATOR([accept])
gl_FUNC_ALLOCA
gl_HEADER_ARPA_INET
AC_PROG_MKDIR_P
AC_REQUIRE([AC_CANONICAL_HOST])
AC_REQUIRE([gl_HEADER_SYS_SOCKET])
if test "$ac_cv_header_winsock2_h" = yes; then
AC_LIBOBJ([bind])
fi
gl_SYS_SOCKET_MODULE_INDICATOR([bind])
gl_FUNC_BTOWC
if test $HAVE_BTOWC = 0 || test $REPLACE_BTOWC = 1; then
AC_LIBOBJ([btowc])
@ -295,6 +311,11 @@ AC_DEFUN([gl_INIT],
AC_LIBOBJ([closedir])
fi
gl_DIRENT_MODULE_INDICATOR([closedir])
AC_REQUIRE([gl_HEADER_SYS_SOCKET])
if test "$ac_cv_header_winsock2_h" = yes; then
AC_LIBOBJ([connect])
fi
gl_SYS_SOCKET_MODULE_INDICATOR([connect])
gl_CTYPE_H
gl_CHECK_TYPE_STRUCT_DIRENT_D_INO
gl_CHECK_TYPE_STRUCT_DIRENT_D_TYPE
@ -498,6 +519,11 @@ AC_DEFUN([gl_INIT],
AC_REQUIRE([gl_LARGEFILE])
gl___INLINE
gl_LIMITS_H
AC_REQUIRE([gl_HEADER_SYS_SOCKET])
if test "$ac_cv_header_winsock2_h" = yes; then
AC_LIBOBJ([listen])
fi
gl_SYS_SOCKET_MODULE_INDICATOR([listen])
gl_LOCALCHARSET
dnl For backward compatibility. Some packages still use this.
LOCALCHARSET_TESTS_ENVIRONMENT=
@ -685,7 +711,26 @@ AC_DEFUN([gl_INIT],
gl_PREREQ_SETLOCALE_LOCK
fi
gl_LOCALE_MODULE_INDICATOR([setlocale_null])
AC_REQUIRE([gl_HEADER_SYS_SOCKET])
if test "$ac_cv_header_winsock2_h" = yes; then
AC_LIBOBJ([setsockopt])
fi
gl_SYS_SOCKET_MODULE_INDICATOR([setsockopt])
gl_SIGNAL_H
AC_REQUIRE([gl_HEADER_SYS_SOCKET])
if test "$ac_cv_header_winsock2_h" = yes; then
AC_LIBOBJ([socket])
fi
# When this module is used, sockets may actually occur as file descriptors,
# hence it is worth warning if the modules 'close' and 'ioctl' are not used.
m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
AC_REQUIRE([gl_PREREQ_SYS_H_WINSOCK2])
if test "$ac_cv_header_winsock2_h" = yes; then
UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=1
SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=1
fi
gl_SYS_SOCKET_MODULE_INDICATOR([socket])
AC_REQUIRE([gl_SOCKETLIB])
AC_REQUIRE([gl_SOCKETS])
gl_TYPE_SOCKLEN_T
@ -980,6 +1025,7 @@ AC_DEFUN([gl_FILE_LIST], [
doc/gendocs_template
doc/gendocs_template_min
lib/_Noreturn.h
lib/accept.c
lib/alloca.c
lib/alloca.in.h
lib/arg-nonnull.h
@ -989,6 +1035,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/attribute.h
lib/basename-lgpl.c
lib/basename-lgpl.h
lib/bind.c
lib/btowc.c
lib/c++defs.h
lib/canonicalize-lgpl.c
@ -1000,6 +1047,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/cloexec.h
lib/close.c
lib/closedir.c
lib/connect.c
lib/count-one-bits.c
lib/count-one-bits.h
lib/ctype.in.h
@ -1081,6 +1129,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/lc-charset-dispatch.h
lib/libc-config.h
lib/limits.in.h
lib/listen.c
lib/localcharset.c
lib/localcharset.h
lib/locale.in.h
@ -1148,7 +1197,9 @@ AC_DEFUN([gl_FILE_LIST], [
lib/setlocale-lock.c
lib/setlocale_null.c
lib/setlocale_null.h
lib/setsockopt.c
lib/signal.in.h
lib/socket.c
lib/sockets.c
lib/sockets.h
lib/stat-time.c

View File

@ -0,0 +1,65 @@
/* setsockopt.c --- wrappers for Windows setsockopt 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>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get struct timeval. */
#include <sys/time.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
#undef setsockopt
int
rpl_setsockopt (int fd, int level, int optname, const void *optval, socklen_t optlen)
{
SOCKET sock = FD_TO_SOCKET (fd);
int r;
if (sock == INVALID_SOCKET)
{
errno = EBADF;
return -1;
}
else
{
if (level == SOL_SOCKET
&& (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO))
{
const struct timeval *tv = optval;
int milliseconds = tv->tv_sec * 1000 + tv->tv_usec / 1000;
optval = &milliseconds;
r = setsockopt (sock, level, optname, optval, sizeof (int));
}
else
{
r = setsockopt (sock, level, optname, optval, optlen);
}
if (r < 0)
set_winsock_errno ();
return r;
}
}

53
gnulib/import/socket.c Normal file
View File

@ -0,0 +1,53 @@
/* socket.c --- wrappers for Windows socket 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>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
#include "sockets.h"
/* Don't assume that UNICODE is defined. */
#undef WSASocket
#define WSASocket WSASocketW
int
rpl_socket (int domain, int type, int protocol)
{
SOCKET fh;
gl_sockets_startup (SOCKETS_1_1);
/* We have to use WSASocket() to create non-overlapped IO sockets.
Overlapped IO sockets cannot be used with read/write. */
fh = WSASocket (domain, type, protocol, NULL, 0, 0);
if (fh == INVALID_SOCKET)
{
set_winsock_errno ();
return -1;
}
else
return SOCKET_TO_FD (fh);
}

View File

@ -30,9 +30,12 @@
# The list of gnulib modules we are importing in GDB.
IMPORTED_GNULIB_MODULES="\
accept \
alloca \
bind \
canonicalize-lgpl \
chown \
connect \
count-one-bits \
dirent \
dirfd \
@ -50,6 +53,7 @@ IMPORTED_GNULIB_MODULES="\
inttypes \
lstat \
limits-h \
listen \
memchr \
memmem \
mkdir \
@ -62,7 +66,9 @@ IMPORTED_GNULIB_MODULES="\
rename \
select \
setenv \
setsockopt \
signal-h \
socket \
strchrnul \
strerror_r-posix \
strstr \