cvs: php4 /ext/zlib config.m4 zlib.c

From: Date: Wed, 11 Oct 2000 22:40:22 +0000
Subject: cvs: php4 /ext/zlib config.m4 zlib.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2017@lists.php.net to get a copy of this message
hholzgra Wed Oct 11 15:40:22 2000 EDT Modified files: /php4/ext/zlib config.m4 zlib.c Log: @ -read and write .gz-files transparently on glibc based systems @ using the 'zlib:' fopen wrapper (Hartmut) Index: php4/ext/zlib/config.m4 diff -u php4/ext/zlib/config.m4:1.7 php4/ext/zlib/config.m4:1.8 --- php4/ext/zlib/config.m4:1.7 Mon Jun 26 01:53:36 2000 +++ php4/ext/zlib/config.m4 Wed Oct 11 15:40:22 2000 @@ -1,4 +1,4 @@ -dnl $Id: config.m4,v 1.7 2000/06/26 08:53:36 sr Exp $ +dnl $Id: config.m4,v 1.8 2000/10/11 22:40:22 hholzgra Exp $ @@ -41,4 +41,6 @@ AC_ADD_LIBRARY_WITH_PATH(z, $ZLIB_LIBDIR, ZLIB_SHARED_LIBADD) AC_ADD_INCLUDE($ZLIB_INCDIR) + + AC_CHECK_FUNC(fopencookie, [AC_DEFINE(HAVE_FOPENCOOKIE,1,[ ])]) fi Index: php4/ext/zlib/zlib.c diff -u php4/ext/zlib/zlib.c:1.53 php4/ext/zlib/zlib.c:1.54 --- php4/ext/zlib/zlib.c:1.53 Thu Jul 13 11:27:10 2000 +++ php4/ext/zlib/zlib.c Wed Oct 11 15:40:22 2000 @@ -16,11 +16,20 @@ | Stefan Röhrich <sr@linux.de> | +----------------------------------------------------------------------+ */ -/* $Id: zlib.c,v 1.53 2000/07/13 18:27:10 eschmid Exp $ */ +/* $Id: zlib.c,v 1.54 2000/10/11 22:40:22 hholzgra Exp $ */ #define IS_EXT_MODULE +#include "php_config.h" + +#if HAVE_FOPENCOOKIE +#define _GNU_SOURCE +#include "libio.h" +#endif + #include "php.h" + + #include <stdio.h> #include <stdlib.h> #include <errno.h> @@ -74,6 +83,9 @@ static php_zlib_globals zlib_globals; #endif +#if HAVE_FOPENCOOKIE +static FILE *zlib_fopen_wrapper(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path); +#endif /* True globals, no need for thread safety */ static int le_zp; @@ -133,11 +145,20 @@ ZLIBG(gzgetss_state)=0; #endif le_zp = register_list_destructors(phpi_destructor_gzclose,NULL); + +#if HAVE_FOPENCOOKIE + php_register_url_wrapper("zlib",zlib_fopen_wrapper); +#endif + return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(zlib) { +#if HAVE_FOPENCOOKIE + php_unregister_url_wrapper("zlib"); +#endif + return SUCCESS; } @@ -145,6 +166,9 @@ { php_info_print_table_start(); php_info_print_table_row(2, "ZLib Support", "enabled"); +#if HAVE_FOPENCOOKIE + php_info_print_table_row(2, "'zlib:' fopen wrapper", "enabled"); +#endif php_info_print_table_row(2, "Compiled Version", ZLIB_VERSION ); php_info_print_table_row(2, "Linked Version", (char *)zlibVersion() ); php_info_print_table_end(); @@ -734,6 +758,68 @@ } } /* }}} */ + +#if HAVE_FOPENCOOKIE +struct gz_cookie { + gzFile gz_file; +}; + +static ssize_t gz_reader(void *cookie, char *buffer, size_t size) +{ + return gzread(((struct gz_cookie *)cookie)->gz_file,buffer,size); +} + +static ssize_t gz_writer(void *cookie, char *buffer, size_t size) { + return gzwrite(((struct gz_cookie *)cookie)->gz_file,buffer,size); +} + +static int gz_seeker(void *cookie,fpos_t *position, int whence) { + return (*position=gzseek(((struct gz_cookie *)cookie)->gz_file,*position,whence)); +} + +static int gz_cleaner(void *cookie) { + gzclose(((struct gz_cookie *)cookie)->gz_file); + efree(cookie); + cookie=NULL; +} + + +static cookie_io_functions_t gz_cookie_functions = +{ gz_reader +, gz_writer +, gz_seeker +, gz_cleaner +}; + +static FILE *zlib_fopen_wrapper(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) +{ + struct gz_cookie *gc = NULL; + + gc = (struct gz_cookie *)emalloc(sizeof(struct gz_cookie)); + + if(gc) { + *issock = 0; + + while(*path!=':') + path++; + + path++; + + gc->gz_file = gzopen(path,mode); + + if(gc->gz_file) { + return fopencookie(gc,mode,gz_cookie_functions); + } else { + efree(gc); + return NULL; + } + } + errno = ENOENT; + return NULL; +} + + +#endif

« previous php.cvs (#2017) next »