mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
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
This commit is contained in:
77
build/php.m4
77
build/php.m4
@@ -1319,24 +1319,20 @@ int main(void)
|
||||
dnl
|
||||
dnl PHP_FOPENCOOKIE
|
||||
dnl
|
||||
AC_DEFUN([PHP_FOPENCOOKIE], [
|
||||
AC_CHECK_FUNC(fopencookie, [have_glibc_fopencookie=yes])
|
||||
|
||||
if test "$have_glibc_fopencookie" = "yes"; then
|
||||
dnl glibcs (since 2.1.2?) have a type called cookie_io_functions_t.
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
]], [[cookie_io_functions_t cookie;]])],[have_cookie_io_functions_t=yes],[])
|
||||
|
||||
if test "$have_cookie_io_functions_t" = "yes"; then
|
||||
dnl Newer glibcs have a different seeker definition.
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE([[
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
dnl Check for cookie_io_functions_t type and fopencookie(). When using glibc,
|
||||
dnl checks here require _GNU_SOURCE defined via AC_USE_SYSTEM_EXTENSIONS. Some
|
||||
dnl glibc versions started using the off64_t in fopencookie seeker definition,
|
||||
dnl which is in transition to use the POSIX standard off_t on 32-bit (with large
|
||||
dnl file support enabled) and 64-bit.
|
||||
dnl
|
||||
AC_DEFUN([PHP_FOPENCOOKIE],
|
||||
[AC_CHECK_TYPE([cookie_io_functions_t], [AC_CHECK_FUNCS([fopencookie])],,
|
||||
[#include <stdio.h>])
|
||||
dnl Check if glibc might use off64_t seeker definition.
|
||||
AS_VAR_IF([ac_cv_func_fopencookie], [yes],
|
||||
[AC_CACHE_CHECK([whether fopencookie seeker uses off64_t],
|
||||
[php_cv_type_cookie_off64_t],
|
||||
[AC_RUN_IFELSE([AC_LANG_SOURCE([
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -1345,48 +1341,35 @@ struct cookiedata {
|
||||
};
|
||||
|
||||
ssize_t reader(void *cookie, char *buffer, size_t size)
|
||||
{ return size; }
|
||||
{ (void)cookie; (void)buffer; return size; }
|
||||
ssize_t writer(void *cookie, const char *buffer, size_t size)
|
||||
{ return size; }
|
||||
{ (void)cookie; (void)buffer; return size; }
|
||||
int closer(void *cookie)
|
||||
{ return 0; }
|
||||
{ (void)cookie; return 0; }
|
||||
int seeker(void *cookie, off64_t *position, int whence)
|
||||
{ ((struct cookiedata*)cookie)->pos = *position; return 0; }
|
||||
{ ((struct cookiedata*)cookie)->pos = *position; (void)whence; return 0; }
|
||||
|
||||
cookie_io_functions_t funcs = {reader, writer, seeker, closer};
|
||||
|
||||
int main(void) {
|
||||
struct cookiedata g = { 0 };
|
||||
FILE *fp = fopencookie(&g, "r", funcs);
|
||||
|
||||
if (fp && fseek(fp, 8192, SEEK_SET) == 0 && g.pos == 8192)
|
||||
if (fp && fseek(fp, 8192, SEEK_SET) == 0 && g.pos == 8192) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
]])], [
|
||||
cookie_io_functions_use_off64_t=yes
|
||||
], [
|
||||
cookie_io_functions_use_off64_t=no
|
||||
], [
|
||||
dnl Cross compilation.
|
||||
case $host_alias in
|
||||
*linux*)
|
||||
cookie_io_functions_use_off64_t=yes
|
||||
;;
|
||||
*)
|
||||
cookie_io_functions_use_off64_t=no
|
||||
;;
|
||||
esac
|
||||
])],
|
||||
[php_cv_type_cookie_off64_t=yes],
|
||||
[php_cv_type_cookie_off64_t=no],
|
||||
[AS_CASE([$host_alias],
|
||||
[*linux*], [php_cv_type_cookie_off64_t=yes],
|
||||
[php_cv_type_cookie_off64_t=no])]
|
||||
)])
|
||||
AS_VAR_IF([php_cv_type_cookie_off64_t], [yes],
|
||||
[AC_DEFINE([COOKIE_SEEKER_USES_OFF64_T], [1],
|
||||
[Whether fopencookie seeker uses off64_t.])])
|
||||
])
|
||||
|
||||
AC_DEFINE(HAVE_FOPENCOOKIE, 1, [ ])
|
||||
|
||||
if test "$cookie_io_functions_use_off64_t" = "yes" ; then
|
||||
AC_DEFINE(COOKIE_SEEKER_USES_OFF64_T, 1, [ ])
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
])
|
||||
|
||||
dnl ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user