cvs: php4 / acinclude.m4 /main streams.c

From: Date: Thu, 22 Aug 2002 22:28:20 +0000
Subject: cvs: php4 / acinclude.m4 /main streams.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-13585@lists.php.net to get a copy of this message
wez Thu Aug 22 18:28:20 2002 EDT Modified files: /php4 acinclude.m4 /php4/main streams.c Log: Add a configure check to see if the seeker function in an fopencookie uses off_t or the newer, more portable "fpos_t *". The check could perhaps be more refined, as the test program will segfault on older systems (like mine) that use off_t. Index: php4/acinclude.m4 diff -u php4/acinclude.m4:1.202 php4/acinclude.m4:1.203 --- php4/acinclude.m4:1.202 Tue Aug 6 18:05:38 2002 +++ php4/acinclude.m4 Thu Aug 22 18:28:19 2002 @@ -1,4 +1,4 @@ -dnl $Id: acinclude.m4,v 1.202 2002/08/06 22:05:38 markonen Exp $ +dnl $Id: acinclude.m4,v 1.203 2002/08/22 22:28:19 wez Exp $ dnl dnl This file contains local autoconf functions. @@ -1408,9 +1408,44 @@ [ have_cookie_io_functions_t=yes ], [] ) - if test "$have_cookie_io_functions_t" = "yes" ; then + if test "$have_cookie_io_functions_t" = "yes" ; then cookie_io_functions_t=cookie_io_functions_t - have_fopen_cookie=yes + have_fopen_cookie=yes + + dnl even newer glibcs have a different seeker definition... + + AC_TRY_RUN([ +#define _GNU_SOURCE +#include <stdio.h> + +struct cookiedata { + fpos_t pos; +}; + +size_t reader(void *cookie, char *buffer, size_t size) +{ return size; } +size_t writer(void *cookie, const char *buffer, size_t size) +{ return size; } +int closer(void *cookie) +{ return 0; } +int seeker(void *cookie, fpos_t *position, int whence) +{ ((struct cookiedata*)cookie)->pos = *position; return 0; } + +cookie_io_functions_t funcs = {reader, writer, seeker, closer}; + +main() { + struct cookiedata g = { 0 }; + FILE *fp = fopencookie(&g, "r", funcs); + + if (fp && fseek(fp, 69, SEEK_SET) == 0 && g.pos == 69) + exit(0); + exit(1); +} + + ], + [ cookie_io_functions_use_fpos_t=yes ], + [ ] ) + else dnl older glibc versions (up to 2.1.2 ?) dnl call it _IO_cookie_io_functions_t @@ -1421,14 +1456,17 @@ [ have_IO_cookie_io_functions_t=yes ], [] ) if test "$have_cookie_io_functions_t" = "yes" ; then - cookie_io_functions_t=_IO_cookie_io_functions_t - have_fopen_cookie=yes + cookie_io_functions_t=_IO_cookie_io_functions_t + have_fopen_cookie=yes fi - fi + fi - if test "$have_fopen_cookie" = "yes" ; then - AC_DEFINE(HAVE_FOPENCOOKIE, 1, [ ]) - AC_DEFINE_UNQUOTED(COOKIE_IO_FUNCTIONS_T, $cookie_io_functions_t, [ ]) + if test "$have_fopen_cookie" = "yes" ; then + AC_DEFINE(HAVE_FOPENCOOKIE, 1, [ ]) + AC_DEFINE_UNQUOTED(COOKIE_IO_FUNCTIONS_T, $cookie_io_functions_t, [ ]) + if test "$cookie_io_functions_use_fpos_t" = "yes" ; then + AC_DEFINE(COOKIE_SEEKER_USES_FPOS_T, 1, [ ]) + fi fi fi Index: php4/main/streams.c diff -u php4/main/streams.c:1.67 php4/main/streams.c:1.68 --- php4/main/streams.c:1.67 Thu Aug 22 13:42:18 2002 +++ php4/main/streams.c Thu Aug 22 18:28:19 2002 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.67 2002/08/22 17:42:18 wez Exp $ */ +/* $Id: streams.c,v 1.68 2002/08/22 22:28:19 wez Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -1138,12 +1138,25 @@ return php_stream_write(((php_stream *)cookie), (char *)buffer, size); } +#ifdef COOKIE_SEEKER_USES_FPOS_T +static int stream_cookie_seeker(void *cookie, fpos_t *position, int whence) +{ + TSRMLS_FETCH(); + + *position = php_stream_seek((php_stream *)cookie, *position, whence); + + if (*position == -1) + return -1; + return 0; +} +#else static int stream_cookie_seeker(void *cookie, off_t position, int whence) { TSRMLS_FETCH(); return php_stream_seek((php_stream *)cookie, position, whence); } +#endif static int stream_cookie_closer(void *cookie) {

« previous php.cvs (#13585) next »