11#[=============================================================================[
2- # CheckStrerrorR
3-
4- Check whether `strerror_r()` is the POSIX-compatible version or the GNU-specific
2+ Check whether strerror_r() is the POSIX-compatible version or the GNU-specific
53version.
64
7- ## Cache variables
8-
9- * `HAVE_STRERROR_R`
10-
11- Whether `strerror_r()` is available.
12-
13- * `STRERROR_R_CHAR_P`
14-
15- Whether `strerror_r()` returns a `char *` message, otherwise it returns an
16- `int` error number.
5+ Result variables:
176
18- ## Usage
19-
20- ```cmake
21- # CMakeLists.txt
22- include(cmake/CheckStrerrorR.cmake)
23- ```
7+ * HAVE_STRERROR_R - Whether strerror_r() is available.
8+ * STRERROR_R_CHAR_P - Whether strerror_r() returns a 'char *' message, otherwise
9+ it returns an 'int' error number.
2410#]=============================================================================]
2511
2612include_guard (GLOBAL )
@@ -29,14 +15,35 @@ include(CheckSourceCompiles)
2915include (CheckSymbolExists)
3016include (CMakePushCheckState)
3117
32- check_symbol_exists(strerror_r string .h HAVE_STRERROR_R)
18+ set (HAVE_STRERROR_R FALSE )
19+ set (STRERROR_R_CHAR_P FALSE )
3320
34- if (NOT HAVE_STRERROR_R )
21+ if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
3522 return ()
3623endif ()
3724
25+ check_symbol_exists(strerror_r string .h PHP_ZEND_HAS_STRERROR_R)
26+
27+ if (NOT PHP_ZEND_HAS_STRERROR_R)
28+ return ()
29+ endif ()
30+
31+ set (HAVE_STRERROR_R TRUE )
32+
33+ # Skip in consecutive configuration phases.
34+ if (DEFINED PHP_ZEND_HAS_STRERROR_R_CHAR_P)
35+ if (PHP_ZEND_HAS_STRERROR_R_CHAR_P)
36+ set (STRERROR_R_CHAR_P TRUE )
37+ return ()
38+ endif ()
39+ endif ()
40+
41+ message (CHECK_START "Checking strerror_r() return type" )
42+
3843cmake_push_check_state(RESET)
3944 set (CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
45+ set (CMAKE_REQUIRED_QUIET TRUE )
46+
4047 check_source_compiles(C [[
4148 #include <string.h>
4249
@@ -47,5 +54,12 @@ cmake_push_check_state(RESET)
4754 char *p = strerror_r (0, buf, sizeof buf);
4855 return !p || x;
4956 }
50- ]] STRERROR_R_CHAR_P )
57+ ]] PHP_ZEND_HAS_STRERROR_R_CHAR_P )
5158cmake_pop_check_state()
59+
60+ if (PHP_ZEND_HAS_STRERROR_R_CHAR_P)
61+ set (STRERROR_R_CHAR_P TRUE )
62+ message (CHECK_PASS "char *" )
63+ else ()
64+ message (CHECK_PASS "int" )
65+ endif ()
0 commit comments