mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-07-08 01:30:39 +08:00
Fix test_strerror_r not works
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
build/
|
||||||
@@ -47,18 +47,20 @@ endif()
|
|||||||
check_symbol_exists(strcasecmp "string.h" HAVE_STRCASECMP)
|
check_symbol_exists(strcasecmp "string.h" HAVE_STRCASECMP)
|
||||||
check_symbol_exists(strncasecmp "string.h" HAVE_STRNCASECMP)
|
check_symbol_exists(strncasecmp "string.h" HAVE_STRNCASECMP)
|
||||||
check_symbol_exists(strerror_r "string.h" HAVE_STRERROR_R)
|
check_symbol_exists(strerror_r "string.h" HAVE_STRERROR_R)
|
||||||
if (HAVE_STRERROR_R)
|
set(HAVE_GNU_SOURCE OFF)
|
||||||
test_strerror_r(HAVE_GNU_STRERROR_R)
|
|
||||||
endif()
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
set(TMP "${CMAKE_REQUIRED_DEFINITIONS}")
|
set(TMP "${CMAKE_REQUIRED_DEFINITIONS}")
|
||||||
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
|
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
|
||||||
check_symbol_exists(fcloseall "stdio.h" HAVE_FCLOSEALL)
|
check_symbol_exists(fcloseall "stdio.h" HAVE_FCLOSEALL)
|
||||||
if (HAVE_FCLOSEALL)
|
if (HAVE_FCLOSEALL)
|
||||||
add_compile_definitions(_GNU_SOURCE)
|
add_compile_definitions(_GNU_SOURCE)
|
||||||
|
set(HAVE_GNU_SOURCE ON)
|
||||||
endif()
|
endif()
|
||||||
set(CMAKE_REQUIRED_DEFINITIONS "${TMP}")
|
set(CMAKE_REQUIRED_DEFINITIONS "${TMP}")
|
||||||
endif()
|
endif()
|
||||||
|
if (HAVE_STRERROR_R)
|
||||||
|
test_strerror_r(HAVE_GNU_STRERROR_R ${HAVE_GNU_SOURCE})
|
||||||
|
endif()
|
||||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/utils_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/utils_config.h")
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/utils_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/utils_config.h")
|
||||||
|
|
||||||
if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
|
if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
function(test_strerror_r OUTPUT_VAR)
|
function(test_strerror_r OUTPUT_VAR HAVE_GNU_SOURCE)
|
||||||
if (DEFINED STRERROR_R_TEST_RESULT_CACHE)
|
if (DEFINED STRERROR_R_TEST_RESULT_CACHE)
|
||||||
set(${OUTPUT_VAR} ${STRERROR_R_TEST_RESULT_CACHE} PARENT_SCOPE)
|
set(${OUTPUT_VAR} ${STRERROR_R_TEST_RESULT_CACHE} PARENT_SCOPE)
|
||||||
message(STATUS "Check strerror_r is GNU complatable - ${STRERROR_R_TEST_RESULT_CACHE} (Cached)")
|
message(STATUS "Check strerror_r is GNU complatable - ${STRERROR_R_TEST_RESULT_CACHE} (Cached)")
|
||||||
else()
|
else()
|
||||||
message(STATUS "Check strerror_r is GNU complatable")
|
message(STATUS "Check strerror_r is GNU complatable")
|
||||||
try_compile(STRERROR_R_TEST_RESULT "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/test_strerror_r.c")
|
if (HAVE_GNU_SOURCE)
|
||||||
|
set(TMP_DEF -D_GNU_SOURCE)
|
||||||
|
endif()
|
||||||
|
try_compile(STRERROR_R_TEST_RESULT "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/test_strerror_r.c" COMPILE_DEFINITIONS -Werror=int-conversion ${TMP_DEF})
|
||||||
set(STRERROR_R_TEST_RESULT_CACHE ${STRERROR_R_TEST_RESULT} CACHE BOOL "Is strerror_r is GNU complatable.")
|
set(STRERROR_R_TEST_RESULT_CACHE ${STRERROR_R_TEST_RESULT} CACHE BOOL "Is strerror_r is GNU complatable.")
|
||||||
set(${OUTPUT_VAR} ${STRERROR_R_TEST_RESULT} PARENT_SCOPE)
|
if (STRERROR_R_TEST_RESULT)
|
||||||
|
set(${OUTPUT_VAR} 1 PARENT_SCOPE)
|
||||||
|
else()
|
||||||
|
unset(${OUTPUT_VAR} PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
message(STATUS "Check strerror_r is GNU complatable - ${STRERROR_R_TEST_RESULT}")
|
message(STATUS "Check strerror_r is GNU complatable - ${STRERROR_R_TEST_RESULT}")
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char buf[280];
|
char buf[280];
|
||||||
|
|||||||
Reference in New Issue
Block a user