@@ -45,51 +45,59 @@ function(_php_check_pread)
4545 return ()
4646 endif ()
4747
48- if (NOT CMAKE_CROSSCOMPILING )
49- set (
50- temporaryFile
51- ${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles/php_check_pread.tmp
52- )
53-
54- file (WRITE "${temporaryFile} " "test\n " )
55-
56- cmake_push_check_state(RESET)
57- set (CMAKE_REQUIRED_QUIET TRUE )
58- check_source_runs(C "
59- #include <sys/types.h>
60- #include <sys/stat.h>
61- #include <fcntl.h>
62- #include <unistd.h>
63- #include <errno.h>
64- #include <stdlib.h>
65-
66- int main(void) {
67- char buf[3];
68- int fd = open(\" ${temporaryFile} \" , O_RDONLY);
48+ set (
49+ temporaryFile
50+ ${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles/php_check_pread.tmp
51+ )
6952
70- if (fd < 0) return 1;
71- if (pread(fd, buf, 2, 0) != 2) return 1;
72- /* Linux glibc breakage until 2.2.5 */
73- if (pread(fd, buf, 2, -1) != -1 || errno != EINVAL) return 1;
53+ file (WRITE "${temporaryFile} " "test\n " )
7454
75- return 0;
76- }
77- " HAVE_PREAD)
78- cmake_pop_check_state()
79- endif ()
55+ cmake_push_check_state(RESET)
56+ set (CMAKE_REQUIRED_QUIET TRUE )
57+ set (CMAKE_REQUIRED_DEFINITIONS -DTMP_FILE=${temporaryFile} )
58+
59+ check_source_runs(C [[
60+ #define xstr(s) str(s)
61+ #define str(s) #s
62+
63+ #include <sys/types.h>
64+ #include <sys/stat.h>
65+ #include <fcntl.h>
66+ #include <unistd.h>
67+ #include <errno.h>
68+ #include <stdlib.h>
69+
70+ int main(void)
71+ {
72+ char buf[3];
73+ int fd = open(xstr(TMP_FILE), O_RDONLY);
74+
75+ if (fd < 0) return 1;
76+ if (pread(fd, buf, 2, 0) != 2) return 1;
77+ /* Linux glibc breakage until 2.2.5 */
78+ if (pread(fd, buf, 2, -1) != -1 || errno != EINVAL) return 1;
79+
80+ return 0;
81+ }
82+ ]] HAVE_PREAD)
83+ cmake_pop_check_state()
8084
8185 # This check is obsolete. Some systems once had pread() available with 3rd
8286 # argument of type 'off64_t', but didn't provide declaration in the headers.
83- if (NOT HAVE_PREAD AND NOT CMAKE_CROSSCOMPILING )
87+ if (NOT HAVE_PREAD)
8488 cmake_push_check_state(RESET)
8589 set (CMAKE_REQUIRED_QUIET TRUE )
90+ set (CMAKE_REQUIRED_DEFINITIONS -DTMP_FILE=${temporaryFile} )
8691
8792 # Needs '_GNU_SOURCE' to enable '_LARGEFILE64_SOURCE' for using 'off64_t'.
8893 # Default way would be the '_FILE_OFFSET_BITS=64' but this is skipped to
8994 # match the current php-src code.
9095 set (CMAKE_REQUIRED_LIBRARIES PHP::SystemExtensions)
9196
92- check_source_runs(C "
97+ check_source_runs(C [[
98+ #define xstr(s) str(s)
99+ #define str(s) #s
100+
93101 #include <sys/types.h>
94102 #include <sys/stat.h>
95103 #include <fcntl.h>
@@ -100,9 +108,10 @@ function(_php_check_pread)
100108 /* Provide a missing declaration. */
101109 ssize_t pread(int, void *, size_t, off64_t);
102110
103- int main(void) {
111+ int main(void)
112+ {
104113 char buf[3];
105- int fd = open(\" ${temporaryFile} \" , O_RDONLY);
114+ int fd = open(xstr(TMP_FILE) , O_RDONLY);
106115
107116 if (fd < 0) return 1;
108117 if (pread(fd, buf, 2, 0) != 2) return 1;
@@ -111,7 +120,7 @@ function(_php_check_pread)
111120
112121 return 0;
113122 }
114- " PHP_PREAD_64)
123+ ]] PHP_PREAD_64)
115124 cmake_pop_check_state()
116125
117126 if (PHP_PREAD_64)
@@ -144,56 +153,59 @@ function(_php_check_pwrite)
144153 return ()
145154 endif ()
146155
147- if (NOT CMAKE_CROSSCOMPILING )
156+ cmake_push_check_state(RESET)
157+ set (CMAKE_REQUIRED_QUIET TRUE )
148158 set (
149- temporaryFile
150- ${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles/php_check_pwrite.tmp
159+ CMAKE_REQUIRED_DEFINITIONS
160+ -DTMP_FILE= ${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles/php_check_pwrite.tmp
151161 )
152162
153- cmake_push_check_state(RESET)
154- set (CMAKE_REQUIRED_QUIET TRUE )
155-
156- check_source_runs(C "
157- #include <sys/types.h>
158- #include <sys/stat.h>
159- #include <fcntl.h>
160- #include <unistd.h>
161- #include <errno.h>
162- #include <stdlib.h>
163-
164- int main(void) {
165- int fd = open( \" ${temporaryFile} \" , O_WRONLY|O_CREAT, 0600);
166-
167- if (fd < 0) return 1;
168- if (pwrite(fd, \" text \" , 4, 0) != 4 ) return 1;
169- /* Linux glibc breakage until 2.2.5 */
170- if (pwrite(fd, \" text \" , 4, -1) != -1 || errno != EINVAL) return 1;
171-
172- return 0;
173- }
174- " HAVE_PWRITE)
175- cmake_pop_check_state( )
176- endif ()
163+ check_source_runs(C [[
164+ #define xstr(s) str(s )
165+ #define str(s) #s
166+
167+ #include <sys/types.h>
168+ #include <sys/stat.h>
169+ #include <fcntl.h>
170+ #include <unistd.h>
171+ #include <errno.h>
172+ #include <stdlib.h>
173+
174+ int main(void)
175+ {
176+ int fd = open(xstr(TMP_FILE), O_WRONLY|O_CREAT, 0600);
177+
178+ if (fd < 0 ) return 1;
179+ if (pwrite(fd, "text", 4, 0) != 4) return 1;
180+ /* Linux glibc breakage until 2.2.5 */
181+ if (pwrite(fd, "text", 4, -1) != -1 || errno != EINVAL) return 1;
182+
183+ return 0;
184+ }
185+ ]] HAVE_PWRITE )
186+ cmake_pop_check_state ()
177187
178188 # This check is obsolete. Some systems once had pwrite() available with 3rd
179189 # argument of type 'off64_t', but didn't provide declaration in the headers.
180190 # On later systems the 2nd argument of pwrite() should also have the 'const'
181191 # keyword.
182- if (NOT HAVE_PWRITE AND NOT CMAKE_CROSSCOMPILING )
183- set (
184- temporaryFile
185- ${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles/php_check_pwrite64.tmp
186- )
187-
192+ if (NOT HAVE_PWRITE)
188193 cmake_push_check_state(RESET)
189194 set (CMAKE_REQUIRED_QUIET TRUE )
195+ set (
196+ CMAKE_REQUIRED_DEFINITIONS
197+ -DTMP_FILE=${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles/php_check_pwrite64.tmp
198+ )
190199
191200 # Needs '_GNU_SOURCE' to enable '_LARGEFILE64_SOURCE' for using 'off64_t'.
192201 # Default way would be the '_FILE_OFFSET_BITS=64' but this is skipped to
193202 # match the current php-src code.
194203 set (CMAKE_REQUIRED_LIBRARIES PHP::SystemExtensions)
195204
196- check_source_runs(C "
205+ check_source_runs(C [[
206+ #define xstr(s) str(s)
207+ #define str(s) #s
208+
197209 #include <sys/types.h>
198210 #include <sys/stat.h>
199211 #include <fcntl.h>
@@ -204,17 +216,18 @@ function(_php_check_pwrite)
204216 /* Provide a missing declaration. */
205217 ssize_t pwrite(int, void *, size_t, off64_t);
206218
207- int main(void) {
208- int fd = open(\" ${temporaryFile} \" , O_WRONLY|O_CREAT, 0600);
219+ int main(void)
220+ {
221+ int fd = open(xstr(TMP_FILE), O_WRONLY|O_CREAT, 0600);
209222
210223 if (fd < 0) return 1;
211- if (pwrite(fd, \ " text\ " , 4, 0) != 4) return 1;
224+ if (pwrite(fd, "text", 4, 0) != 4) return 1;
212225 /* Linux glibc breakage until 2.2.5 */
213- if (pwrite(fd, \ " text\ " , 4, -1) != -1 || errno != EINVAL) return 1;
226+ if (pwrite(fd, "text", 4, -1) != -1 || errno != EINVAL) return 1;
214227
215228 return 0;
216229 }
217- " PHP_PWRITE_64)
230+ ]] PHP_PWRITE_64)
218231 cmake_pop_check_state()
219232
220233 if (PHP_PWRITE_64)
0 commit comments