build: fix unsigned time_t detection for cmake, MS-DOS, AmigaOS

- cmake: add auto-detection. Sync this with autotools.
- enable for MS-DOS and AmigaOS builds.
  (auto-detection doesn't work for cross-builds.)
- tidy up detection snippet.
- fix comment.

Closes #15868
This commit is contained in:
Viktor Szakats 2024-12-30 20:57:41 +01:00
parent f60f872bcd
commit 10fe952da0
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
4 changed files with 41 additions and 18 deletions

View File

@ -170,6 +170,7 @@ set(HAVE_POSIX_STRERROR_R 0)
set(HAVE_MSG_NOSIGNAL 0)
set(HAVE_STRUCT_TIMEVAL 1)
set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
set(HAVE_TIME_T_UNSIGNED 0)
set(HAVE_GETHOSTBYNAME_R_3 0)
set(HAVE_GETHOSTBYNAME_R_3_REENTRANT 0)

View File

@ -536,6 +536,9 @@ elseif(APPLE)
elseif(AMIGA)
set(HAVE_GETADDRINFO 0) # Breaks the build when detected and used.
endif()
if(DOS OR AMIGA)
set(HAVE_TIME_T_UNSIGNED 1)
endif()
if(ENABLE_THREADED_RESOLVER)
if(WIN32)
@ -1787,6 +1790,16 @@ if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
}" HAVE_WRITABLE_ARGV)
endif()
if(NOT CMAKE_CROSSCOMPILING)
include(CheckCSourceRuns)
check_c_source_runs("
#include <time.h>
int main(void) {
time_t t = -1;
return t < 0;
}" HAVE_TIME_T_UNSIGNED)
endif()
curl_internal_test(HAVE_GLIBC_STRERROR_R)
curl_internal_test(HAVE_POSIX_STRERROR_R)

View File

@ -3965,24 +3965,30 @@ AC_CHECK_TYPE([suseconds_t],[
#endif
])
AC_MSG_CHECKING([if time_t is unsigned])
CURL_RUN_IFELSE(
[
#include <time.h>
#include <limits.h>
int main(void) {
time_t t = -1;
return (t < 0);
}
],[
AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_TIME_T_UNSIGNED, 1, [Define this if time_t is unsigned])
],[
AC_MSG_RESULT([no])
],[
dnl cross-compiling, most systems are unsigned
AC_MSG_RESULT([no])
])
case $host_os in
amigaos*|msdos*)
AC_DEFINE(HAVE_TIME_T_UNSIGNED, 1, [Define this if time_t is unsigned])
;;
*)
AC_MSG_CHECKING([if time_t is unsigned])
CURL_RUN_IFELSE(
[
#include <time.h>
int main(void) {
time_t t = -1;
return t < 0;
}
],[
AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_TIME_T_UNSIGNED, 1, [Define this if time_t is unsigned])
],[
AC_MSG_RESULT([no])
],[
dnl cross-compiling, most systems are signed
AC_MSG_RESULT([no])
])
;;
esac
TYPE_IN_ADDR_T

View File

@ -622,6 +622,9 @@
/* Define this symbol if your OS supports changing the contents of argv */
#cmakedefine HAVE_WRITABLE_ARGV 1
/* Define this if time_t is unsigned */
#cmakedefine HAVE_TIME_T_UNSIGNED 1
/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */
#cmakedefine NEED_REENTRANT 1