Skip to content

Commit 471aa11

Browse files
authored
Refactor fopencookie check (#14346)
- This checks for a type cookie_io_functions_t and defines the HAVE_FOPENCOOKIE based on type check result and the fopencookie() function presence. - Fixed -Wunused... warnings in config.log on stricter compiler configurations - The run check for off64_t is wrapped into AC_CACHE_CHECK for having the php_cv_type_cookie_off64_t cache variable available to customize possible cross-compilation edge cases - Comment about glibcs 2.1.2 removed because also some other earlier versions provided this type already
1 parent cd44826 commit 471aa11

File tree

1 file changed

+30
-47
lines changed

1 file changed

+30
-47
lines changed

build/php.m4

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,24 +1319,20 @@ int main(void)
13191319
dnl
13201320
dnl PHP_FOPENCOOKIE
13211321
dnl
1322-
AC_DEFUN([PHP_FOPENCOOKIE], [
1323-
AC_CHECK_FUNC(fopencookie, [have_glibc_fopencookie=yes])
1324-
1325-
if test "$have_glibc_fopencookie" = "yes"; then
1326-
dnl glibcs (since 2.1.2?) have a type called cookie_io_functions_t.
1327-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1328-
#ifndef _GNU_SOURCE
1329-
#define _GNU_SOURCE
1330-
#endif
1331-
#include <stdio.h>
1332-
]], [[cookie_io_functions_t cookie;]])],[have_cookie_io_functions_t=yes],[])
1333-
1334-
if test "$have_cookie_io_functions_t" = "yes"; then
1335-
dnl Newer glibcs have a different seeker definition.
1336-
AC_RUN_IFELSE([AC_LANG_SOURCE([[
1337-
#ifndef _GNU_SOURCE
1338-
#define _GNU_SOURCE
1339-
#endif
1322+
dnl Check for cookie_io_functions_t type and fopencookie(). When using glibc,
1323+
dnl checks here require _GNU_SOURCE defined via AC_USE_SYSTEM_EXTENSIONS. Some
1324+
dnl glibc versions started using the off64_t in fopencookie seeker definition,
1325+
dnl which is in transition to use the POSIX standard off_t on 32-bit (with large
1326+
dnl file support enabled) and 64-bit.
1327+
dnl
1328+
AC_DEFUN([PHP_FOPENCOOKIE],
1329+
[AC_CHECK_TYPE([cookie_io_functions_t], [AC_CHECK_FUNCS([fopencookie])],,
1330+
[#include <stdio.h>])
1331+
dnl Check if glibc might use off64_t seeker definition.
1332+
AS_VAR_IF([ac_cv_func_fopencookie], [yes],
1333+
[AC_CACHE_CHECK([whether fopencookie seeker uses off64_t],
1334+
[php_cv_type_cookie_off64_t],
1335+
[AC_RUN_IFELSE([AC_LANG_SOURCE([
13401336
#include <stdio.h>
13411337
#include <stdlib.h>
13421338
@@ -1345,48 +1341,35 @@ struct cookiedata {
13451341
};
13461342
13471343
ssize_t reader(void *cookie, char *buffer, size_t size)
1348-
{ return size; }
1344+
{ (void)cookie; (void)buffer; return size; }
13491345
ssize_t writer(void *cookie, const char *buffer, size_t size)
1350-
{ return size; }
1346+
{ (void)cookie; (void)buffer; return size; }
13511347
int closer(void *cookie)
1352-
{ return 0; }
1348+
{ (void)cookie; return 0; }
13531349
int seeker(void *cookie, off64_t *position, int whence)
1354-
{ ((struct cookiedata*)cookie)->pos = *position; return 0; }
1350+
{ ((struct cookiedata*)cookie)->pos = *position; (void)whence; return 0; }
13551351
13561352
cookie_io_functions_t funcs = {reader, writer, seeker, closer};
13571353
13581354
int main(void) {
13591355
struct cookiedata g = { 0 };
13601356
FILE *fp = fopencookie(&g, "r", funcs);
1361-
1362-
if (fp && fseek(fp, 8192, SEEK_SET) == 0 && g.pos == 8192)
1357+
if (fp && fseek(fp, 8192, SEEK_SET) == 0 && g.pos == 8192) {
13631358
return 0;
1359+
}
13641360
return 1;
13651361
}
1366-
1367-
]])], [
1368-
cookie_io_functions_use_off64_t=yes
1369-
], [
1370-
cookie_io_functions_use_off64_t=no
1371-
], [
1372-
dnl Cross compilation.
1373-
case $host_alias in
1374-
*linux*)
1375-
cookie_io_functions_use_off64_t=yes
1376-
;;
1377-
*)
1378-
cookie_io_functions_use_off64_t=no
1379-
;;
1380-
esac
1362+
])],
1363+
[php_cv_type_cookie_off64_t=yes],
1364+
[php_cv_type_cookie_off64_t=no],
1365+
[AS_CASE([$host_alias],
1366+
[*linux*], [php_cv_type_cookie_off64_t=yes],
1367+
[php_cv_type_cookie_off64_t=no])]
1368+
)])
1369+
AS_VAR_IF([php_cv_type_cookie_off64_t], [yes],
1370+
[AC_DEFINE([COOKIE_SEEKER_USES_OFF64_T], [1],
1371+
[Whether fopencookie seeker uses off64_t.])])
13811372
])
1382-
1383-
AC_DEFINE(HAVE_FOPENCOOKIE, 1, [ ])
1384-
1385-
if test "$cookie_io_functions_use_off64_t" = "yes" ; then
1386-
AC_DEFINE(COOKIE_SEEKER_USES_OFF64_T, 1, [ ])
1387-
fi
1388-
fi
1389-
fi
13901373
])
13911374

13921375
dnl ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)