build: drop HAVE_SYS_SOCKET_H and HAVE_SYS_TIME_H macros

Both are available with well-known conditions, under non-Windows, and
`curl/curl.h` already uses them. `sys/time.h` is also necessary for
mingw-w64 for `gettimeofday()`.

Follow-up to 56d5982312 #17522

Closes #17581
This commit is contained in:
Viktor Szakats 2025-06-11 07:32:16 +02:00
parent 639d5e0f5e
commit 3186a20483
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
18 changed files with 56 additions and 112 deletions

View file

@ -203,7 +203,7 @@ int main(void)
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
@ -230,7 +230,7 @@ int main(void)
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
@ -257,7 +257,7 @@ int main(void)
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
# include <sys/socket.h>
#endif
int main(void)

View file

@ -42,7 +42,7 @@ if(NOT DEFINED HAVE_STRUCT_SOCKADDR_STORAGE)
if(WIN32)
set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h")
list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
elseif(HAVE_SYS_SOCKET_H)
else()
set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
endif()
check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
@ -53,8 +53,8 @@ endif()
if(NOT WIN32)
set(_source_epilogue "#undef inline")
curl_add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
curl_add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
check_c_source_compiles("${_source_epilogue}
#include <sys/socket.h>
int main(void)
{
int flag = MSG_NOSIGNAL;
@ -64,11 +64,13 @@ if(NOT WIN32)
endif()
set(_source_epilogue "#undef inline")
curl_add_header_include(HAVE_SYS_TIME_H "sys/time.h")
check_c_source_compiles("${_source_epilogue}
#ifdef _MSC_VER
#include <winsock2.h>
#endif
#ifndef _WIN32
#include <sys/time.h>
#endif
#include <time.h>
int main(void)
{
@ -101,9 +103,11 @@ elseif(BSD OR CMAKE_SYSTEM_NAME MATCHES "BSD")
endif()
if(NOT DEFINED HAVE_GETADDRINFO_THREADSAFE)
set(_source_epilogue "#undef inline")
curl_add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
curl_add_header_include(HAVE_SYS_TIME_H "sys/time.h")
set(_source_epilogue "#undef inline
#ifndef _WIN32
#include <sys/socket.h>
#include <sys/time.h>
#endif")
curl_add_header_include(HAVE_NETDB_H "netdb.h")
check_c_source_compiles("${_source_epilogue}
int main(void)
@ -144,8 +148,8 @@ endif()
if(NOT WIN32 AND NOT DEFINED HAVE_CLOCK_GETTIME_MONOTONIC_RAW)
set(_source_epilogue "#undef inline")
curl_add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
curl_add_header_include(HAVE_SYS_TIME_H "sys/time.h")
check_c_source_compiles("${_source_epilogue}
#include <sys/time.h>
#include <time.h>
int main(void)
{

View file

@ -287,7 +287,6 @@ else()
set(HAVE_SYS_SOCKIO_H 1)
endif()
set(HAVE_SYS_STAT_H 1)
set(HAVE_SYS_TIME_H 1)
set(HAVE_SYS_TYPES_H 1)
set(HAVE_SYS_UN_H 1)
if(CYGWIN)

View file

@ -1618,17 +1618,12 @@ if(WIN32)
set(HAVE_IF_NAMETOINDEX 0)
endif()
unset(HAVE_IF_NAMETOINDEX CACHE)
set(HAVE_SYS_TIME_H ${MINGW})
else()
set(HAVE_SYS_SOCKET_H 1)
set(HAVE_SYS_TIME_H 1)
endif()
if(HAVE_SYS_SOCKET_H)
if(NOT WIN32)
list(APPEND CURL_INCLUDES "sys/socket.h")
endif()
if(HAVE_SYS_TIME_H)
if(NOT WIN32 OR MINGW)
list(APPEND CURL_INCLUDES "sys/time.h")
endif()
@ -1687,7 +1682,6 @@ foreach(_variable IN ITEMS
HAVE_STDBOOL_H
HAVE_STROPTS_H
HAVE_SYS_IOCTL_H
HAVE_SYS_SOCKET_H
HAVE_SYS_TYPES_H
HAVE_UNISTD_H
)
@ -1832,7 +1826,7 @@ if(WIN32)
list(APPEND CMAKE_EXTRA_INCLUDE_FILES "winsock2.h")
check_type_size("ADDRESS_FAMILY" SIZEOF_ADDRESS_FAMILY)
set(HAVE_ADDRESS_FAMILY ${HAVE_SIZEOF_ADDRESS_FAMILY})
elseif(HAVE_SYS_SOCKET_H)
else()
list(APPEND CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
check_type_size("sa_family_t" SIZEOF_SA_FAMILY_T)
set(HAVE_SA_FAMILY_T ${HAVE_SIZEOF_SA_FAMILY_T})

View file

@ -600,9 +600,7 @@ AC_DEFUN([TYPE_SOCKADDR_STORAGE],
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@ -620,7 +618,7 @@ dnl Test if the socket recv() function is available,
AC_DEFUN([CURL_CHECK_FUNC_RECV], [
AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl
AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
AC_CHECK_HEADERS(sys/types.h sys/socket.h)
AC_CHECK_HEADERS(sys/types.h)
#
AC_MSG_CHECKING([for recv])
AC_LINK_IFELSE([
@ -636,10 +634,8 @@ AC_DEFUN([CURL_CHECK_FUNC_RECV], [
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#endif
]],[[
recv(0, 0, 0, 0);
]])
@ -668,7 +664,7 @@ dnl Test if the socket send() function is available,
AC_DEFUN([CURL_CHECK_FUNC_SEND], [
AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl
AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
AC_CHECK_HEADERS(sys/types.h sys/socket.h)
AC_CHECK_HEADERS(sys/types.h)
#
AC_MSG_CHECKING([for send])
AC_LINK_IFELSE([
@ -684,10 +680,8 @@ AC_DEFUN([CURL_CHECK_FUNC_SEND], [
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#endif
]],[[
char s[] = "";
send(0, (void *)s, 0, 0);
@ -714,7 +708,7 @@ dnl -------------------------------------------------
dnl Check for MSG_NOSIGNAL
AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
AC_CHECK_HEADERS(sys/types.h sys/socket.h)
AC_CHECK_HEADERS(sys/types.h)
AC_CACHE_CHECK([for MSG_NOSIGNAL], [curl_cv_msg_nosignal], [
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
@ -728,10 +722,8 @@ AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#endif
]],[[
int flag = MSG_NOSIGNAL;
(void)flag;
@ -757,7 +749,7 @@ dnl Check for timeval struct
AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [
AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl
AC_CHECK_HEADERS(sys/types.h sys/time.h sys/socket.h)
AC_CHECK_HEADERS(sys/types.h)
AC_CACHE_CHECK([for struct timeval], [curl_cv_struct_timeval], [
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
@ -767,17 +759,14 @@ AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [
#define WIN32_LEAN_AND_MEAN
#endif
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <time.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
]],[[
struct timeval ts;
ts.tv_sec = 0;
@ -804,7 +793,7 @@ dnl -------------------------------------------------
dnl Check if monotonic clock_gettime is available.
AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
AC_CHECK_HEADERS(sys/types.h sys/time.h)
AC_CHECK_HEADERS(sys/types.h)
AC_MSG_CHECKING([for monotonic clock_gettime])
#
@ -813,7 +802,7 @@ AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#ifndef _WIN32
#include <sys/time.h>
#endif
#include <time.h>
@ -839,7 +828,7 @@ dnl -------------------------------------------------
dnl Check if monotonic clock_gettime is available.
AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC_RAW], [
AC_CHECK_HEADERS(sys/types.h sys/time.h)
AC_CHECK_HEADERS(sys/types.h)
AC_MSG_CHECKING([for raw monotonic clock_gettime])
#
AC_COMPILE_IFELSE([
@ -847,7 +836,7 @@ AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC_RAW], [
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#ifndef _WIN32
#include <sys/time.h>
#endif
#include <time.h>
@ -893,7 +882,7 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#ifndef _WIN32
#include <sys/time.h>
#endif
#include <time.h>
@ -946,7 +935,7 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#ifndef _WIN32
#include <sys/time.h>
#endif
#include <time.h>
@ -1034,7 +1023,7 @@ dnl Test if the socket select() function is available.
AC_DEFUN([CURL_CHECK_FUNC_SELECT], [
AC_REQUIRE([CURL_CHECK_STRUCT_TIMEVAL])dnl
AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
AC_CHECK_HEADERS(sys/select.h sys/socket.h)
AC_CHECK_HEADERS(sys/select.h)
#
AC_MSG_CHECKING([for select])
AC_LINK_IFELSE([
@ -1045,13 +1034,13 @@ AC_DEFUN([CURL_CHECK_FUNC_SELECT], [
#define WIN32_LEAN_AND_MEAN
#endif
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <time.h>
#ifndef _WIN32
#ifdef HAVE_SYS_SELECT_H
@ -1059,9 +1048,6 @@ AC_DEFUN([CURL_CHECK_FUNC_SELECT], [
#elif defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
$curl_includes_bsdsocket
#endif
]],[[

View file

@ -3914,13 +3914,6 @@ case "$OPT_FISH_FPATH" in
esac
AM_CONDITIONAL(USE_FISH_COMPLETION, test x"$FISH_FUNCTIONS_DIR" != x)
if test "$curl_cv_native_windows" != 'yes'; then
AC_DEFINE(HAVE_SYS_SOCKET_H, 1, [if you have <sys/socket.h>])
AC_DEFINE(HAVE_SYS_TIME_H, 1, [if you have <sys/time.h>])
HAVE_SYS_SOCKET_H=1
HAVE_SYS_TIME_H=1
fi
dnl Now check for the very most basic headers. Then we can use these
dnl ones as default-headers when checking for the rest!
AC_CHECK_HEADERS(
@ -3966,7 +3959,7 @@ dnl default includes
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#if !defined(_WIN32) || defined(__MINGW32__)
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_SELECT_H
@ -3974,7 +3967,7 @@ dnl default includes
#elif defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
@ -4054,14 +4047,13 @@ AC_CHECK_TYPE(sa_family_t,
#define WIN32_LEAN_AND_MEAN
#endif
#include <winsock2.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#else
#include <sys/socket.h>
#endif
])
],
[
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
#include <sys/socket.h>
#endif
])
@ -4074,7 +4066,7 @@ AC_CHECK_TYPE([suseconds_t],[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#ifndef _WIN32
#include <sys/time.h>
#endif
])

View file

@ -43,7 +43,6 @@
#define USE_MANUAL 1
#define HAVE_NETINET_IN_H 1
#define HAVE_SYS_SOCKET_H 1
#define HAVE_NETDB_H 1
#define HAVE_ARPA_INET_H 1
#define HAVE_UNISTD_H 1
@ -53,7 +52,6 @@
#define HAVE_FCNTL_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_UTIME_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_UTIME_H 1
#define HAVE_SYS_IOCTL_H 1
#define HAVE_ALARM 1

View file

@ -158,18 +158,12 @@
/* Define if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H
/* Define if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H
/* Define if you have the <sys/sockio.h> header file. */
#undef HAVE_SYS_SOCKIO_H
/* Define if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H
/* Define if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H
/* Define if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H

View file

@ -113,9 +113,7 @@
#define HAVE_SYS_IOCTL_H 1
#define HAVE_SYS_PARAM_H 1
#define HAVE_SYS_RESOURCE_H 1
#define HAVE_SYS_SOCKET_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_UN_H 1
#define HAVE_TERMIOS_H 1

View file

@ -144,18 +144,12 @@
/* Define if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H
/* Define if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H
/* Define if you have the <sys/sockio.h> header file. */
#undef HAVE_SYS_SOCKIO_H
/* Define if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H
/* Define if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H

View file

@ -74,20 +74,12 @@
/* Define if you have the <sys/select.h> header file. */
/* #define HAVE_SYS_SELECT_H 1 */
/* Define if you have the <sys/socket.h> header file. */
/* #define HAVE_SYS_SOCKET_H 1 */
/* Define if you have the <sys/sockio.h> header file. */
/* #define HAVE_SYS_SOCKIO_H 1 */
/* Define if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define if you have the <sys/time.h> header file. */
#ifdef __MINGW32__
#define HAVE_SYS_TIME_H 1
#endif
/* Define if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1

View file

@ -586,18 +586,12 @@
/* Define to 1 if you have the <sys/select.h> header file. */
#cmakedefine HAVE_SYS_SELECT_H 1
/* Define to 1 if you have the <sys/socket.h> header file. */
#cmakedefine HAVE_SYS_SOCKET_H 1
/* Define to 1 if you have the <sys/sockio.h> header file. */
#cmakedefine HAVE_SYS_SOCKIO_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#cmakedefine HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#cmakedefine HAVE_SYS_TYPES_H 1

View file

@ -45,7 +45,7 @@
#include <sys/stat.h>
#endif
#ifdef HAVE_SYS_TIME_H
#if !defined(_WIN32) || defined(__MINGW32__)
#include <sys/time.h>
#endif
@ -96,7 +96,7 @@
# endif
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
#include <sys/socket.h>
#endif

View file

@ -32,7 +32,7 @@ char *curlx_inet_ntop(int af, const void *addr, char *buf, size_t size);
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
#include <sys/socket.h>
#endif
#ifdef HAVE_ARPA_INET_H

View file

@ -32,7 +32,7 @@ int curlx_inet_pton(int, const char *, void *);
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
#include <sys/socket.h>
#endif
#ifdef HAVE_ARPA_INET_H

View file

@ -30,10 +30,10 @@
/* ---------------------------------------------------------------- */
#ifdef USE_WATT32
# include <tcp.h>
# include <sys/socket.h>
# undef byte
# undef word
# define HAVE_SYS_IOCTL_H
# define HAVE_SYS_SOCKET_H
# define HAVE_NETINET_IN_H
# define HAVE_NETDB_H
# define HAVE_ARPA_INET_H

View file

@ -37,9 +37,6 @@ curl_includes_arpa_inet="\
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
@ -49,10 +46,12 @@ curl_includes_arpa_inet="\
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <sys/socket.h>
#endif
/* includes end */"
AC_CHECK_HEADERS(
sys/types.h sys/socket.h netinet/in.h arpa/inet.h,
sys/types.h netinet/in.h arpa/inet.h,
[], [], [$curl_includes_arpa_inet])
])
@ -92,7 +91,7 @@ curl_includes_ifaddrs="\
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
# include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
@ -103,7 +102,7 @@ curl_includes_ifaddrs="\
#endif
/* includes end */"
AC_CHECK_HEADERS(
sys/types.h sys/socket.h netinet/in.h ifaddrs.h,
sys/types.h netinet/in.h ifaddrs.h,
[], [], [$curl_includes_ifaddrs])
])
@ -243,7 +242,7 @@ curl_includes_stropts="\
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
@ -254,7 +253,7 @@ curl_includes_stropts="\
#endif
/* includes end */"
AC_CHECK_HEADERS(
sys/types.h unistd.h sys/socket.h sys/ioctl.h stropts.h,
sys/types.h unistd.h sys/ioctl.h stropts.h,
[], [], [$curl_includes_stropts])
])
@ -270,12 +269,12 @@ curl_includes_sys_socket="\
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
# include <sys/socket.h>
#endif
/* includes end */"
AC_CHECK_HEADERS(
sys/types.h sys/socket.h,
sys/types.h,
[], [], [$curl_includes_sys_socket])
])
@ -329,13 +328,13 @@ curl_includes_time="\
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#if !defined(_WIN32) || defined(__MINGW32__)
# include <sys/time.h>
#endif
#include <time.h>
/* includes end */"
AC_CHECK_HEADERS(
sys/types.h sys/time.h,
sys/types.h,
[], [], [$curl_includes_time])
])

View file

@ -28,7 +28,7 @@
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#ifndef _WIN32
#include <sys/socket.h>
#endif
#ifdef HAVE_ARPA_INET_H