Skip to content

Commit 167575a

Browse files
committed
Check fopencookie with CheckSourceCompiles module and refactor check
To determine whether some signature uses off64_t, running the test code most likely isn't needed as compilers error out properly at the compilation step.
1 parent 17129d6 commit 167575a

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

cmake/cmake/checks/CheckFopencookie.cmake

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
#[=============================================================================[
2-
Check if 'fopencookie()' works as expected.
2+
Check if fopencookie() works as expected.
33
4-
Module first checks if 'fopencookie()' and type 'cookie_io_functions_t' are
5-
available. Then it checks whether the 'fopencookie' seeker uses type 'off64_t'.
6-
Since 'off64_t' is non-standard and obsolescent, the standard 'off_t' type can
7-
be used on both 64-bit and 32-bit systems, where the '_FILE_OFFSET_BITS=64' can
8-
make it behave like 'off64_t' on 32-bit. Since code is in the transition process
9-
to use 'off_t' only, check is left here when using glibc.
4+
First, the fopencookie() and type cookie_io_functions_t are checked if they are
5+
available. Then check is done whether the 'fopencookie' seeker uses type
6+
off64_t. Since off64_t is non-standard and obsolescent, the standard off_t type
7+
can be used on both 64-bit and 32-bit systems, where the _FILE_OFFSET_BITS=64
8+
can make it behave like off64_t on 32-bit platforms. Since code is in the
9+
transition process to use off_t only, check is left here when using glibc.
1010
1111
Result variables:
1212
13-
* HAVE_FOPENCOOKIE - Whether 'fopencookie()' and 'cookie_io_functions_t' are
14-
available.
15-
* COOKIE_SEEKER_USES_OFF64_T - Whether 'fopencookie' seeker uses the 'off64_t'
16-
type.
13+
* HAVE_FOPENCOOKIE
14+
* COOKIE_SEEKER_USES_OFF64_T
1715
#]=============================================================================]
1816

19-
include(CheckSourceRuns)
17+
include(CheckSourceCompiles)
2018
include(CheckSymbolExists)
2119
include(CheckTypeSize)
2220
include(CMakePushCheckState)
@@ -51,29 +49,17 @@ set(HAVE_FOPENCOOKIE TRUE)
5149

5250
# Skip in consecutive configuration phases.
5351
if(DEFINED PHP_HAS_COOKIE_SEEKER_OFF64_T)
54-
if(PHP_HAS_COOKIE_SEEKER_OFF64_T)
55-
set(COOKIE_SEEKER_USES_OFF64_T TRUE)
56-
endif()
52+
set(COOKIE_SEEKER_USES_OFF64_T ${PHP_HAS_COOKIE_SEEKER_OFF64_T})
5753
return()
5854
endif()
5955

6056
# GNU C library can have a different seeker definition using off64_t.
6157
message(CHECK_START "Checking whether fopencookie seeker uses off64_t")
6258

63-
if(
64-
NOT DEFINED PHP_HAS_COOKIE_SEEKER_OFF64_T_EXITCODE
65-
AND CMAKE_CROSSCOMPILING
66-
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
67-
AND CMAKE_SYSTEM_NAME STREQUAL "Linux"
68-
AND PHP_C_STANDARD_LIBRARY STREQUAL "glibc"
69-
)
70-
set(PHP_HAS_COOKIE_SEEKER_OFF64_T_EXITCODE 0)
71-
endif()
72-
7359
cmake_push_check_state(RESET)
7460
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
7561

76-
check_source_runs(C [[
62+
check_source_compiles(C [[
7763
#include <stdio.h>
7864
#include <stdlib.h>
7965
@@ -125,8 +111,9 @@ cmake_push_check_state(RESET)
125111
cmake_pop_check_state()
126112

127113
if(PHP_HAS_COOKIE_SEEKER_OFF64_T)
128-
set(COOKIE_SEEKER_USES_OFF64_T TRUE)
129114
message(CHECK_PASS "yes")
130115
else()
131116
message(CHECK_FAIL "no")
132117
endif()
118+
119+
set(COOKIE_SEEKER_USES_OFF64_T ${PHP_HAS_COOKIE_SEEKER_OFF64_T})

cmake/cmake/toolchains/template.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ set(CMAKE_FIND_ROOT_PATH "")
1616
# PHP
1717
################################################################################
1818

19-
# Set the exit code for the fopencookie seeker using off64_t check.
20-
set(PHP_HAS_COOKIE_SEEKER_OFF64_T_EXITCODE 0)
21-
2219
# Set the exit code if flush should be called explicitly after a buffered io.
2320
set(PHP_HAS_FLUSHIO_EXITCODE 1)
2421

cmake/main/cmake/php_config.h.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@
134134
/* Define to 1 if the system has a working POSIX 'fnmatch' function. */
135135
#cmakedefine HAVE_FNMATCH 1
136136

137-
/* Define to 1 if you have the 'fopencookie' function. */
137+
/* Define to 1 if the system has the 'fopencookie' function and the
138+
'cookie_io_functions_t' type. */
138139
#cmakedefine HAVE_FOPENCOOKIE 1
139140

140141
/* Define to 1 if you have the 'ftok' function. */

0 commit comments

Comments
 (0)