mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
all the _GNU_SOURCE dependant stuff is now in zlib_fopen_wrapper.c
so all the #define/#include workarounds in zlib.c are no longer needed
This commit is contained in:
parent
ee23c53108
commit
cedb39ee56
4 changed files with 109 additions and 86 deletions
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
LTLIBRARY_NAME = libzlib.la
|
LTLIBRARY_NAME = libzlib.la
|
||||||
LTLIBRARY_SOURCES = zlib.c
|
LTLIBRARY_SOURCES = zlib.c zlib_fopen_wrapper.c
|
||||||
LTLIBRARY_SHARED_NAME = zlib.la
|
LTLIBRARY_SHARED_NAME = zlib.la
|
||||||
LTLIBRARY_SHARED_LIBADD = $(ZLIB_SHARED_LIBADD)
|
LTLIBRARY_SHARED_LIBADD = $(ZLIB_SHARED_LIBADD)
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,9 @@ PHP_FUNCTION(gzinflate);
|
||||||
PHP_FUNCTION(gzencode);
|
PHP_FUNCTION(gzencode);
|
||||||
PHP_FUNCTION(ob_gzhandler);
|
PHP_FUNCTION(ob_gzhandler);
|
||||||
|
|
||||||
|
FILE *zlib_fopen_wrapper(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path);
|
||||||
|
|
||||||
|
|
||||||
#ifdef ZTS
|
#ifdef ZTS
|
||||||
#define ZLIBLS_D php_zlib_globals *zlib_globals
|
#define ZLIBLS_D php_zlib_globals *zlib_globals
|
||||||
#define ZLIBLS_DC , ZLIBLS_D
|
#define ZLIBLS_DC , ZLIBLS_D
|
||||||
|
|
|
@ -19,15 +19,6 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
#define IS_EXT_MODULE
|
#define IS_EXT_MODULE
|
||||||
|
|
||||||
#ifndef PHP_WIN32
|
|
||||||
#include "php_config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAVE_FOPENCOOKIE
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stdio.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "php.h"
|
#include "php.h"
|
||||||
#include "SAPI.h"
|
#include "SAPI.h"
|
||||||
|
|
||||||
|
@ -81,10 +72,6 @@ int zlib_globals_id;
|
||||||
static php_zlib_globals zlib_globals;
|
static php_zlib_globals zlib_globals;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_FOPENCOOKIE
|
|
||||||
static FILE *zlib_fopen_wrapper(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define OS_CODE 0x03 /* FIXME */
|
#define OS_CODE 0x03 /* FIXME */
|
||||||
#define CODING_GZIP 1
|
#define CODING_GZIP 1
|
||||||
#define CODING_DEFLATE 2
|
#define CODING_DEFLATE 2
|
||||||
|
@ -941,78 +928,6 @@ PHP_FUNCTION(gzinflate)
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#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, const char *buffer, size_t size) {
|
|
||||||
return gzwrite(((struct gz_cookie *)cookie)->gz_file,(char *)buffer,size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int gz_seeker(void *cookie,off_t position, int whence) {
|
|
||||||
return gzseek(((struct gz_cookie *)cookie)->gz_file,(z_off_t)position,whence);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int gz_closer(void *cookie) {
|
|
||||||
int ret=gzclose(((struct gz_cookie *)cookie)->gz_file);
|
|
||||||
efree(cookie);
|
|
||||||
cookie=NULL;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static COOKIE_IO_FUNCTIONS_T gz_cookie_functions =
|
|
||||||
{ gz_reader
|
|
||||||
, gz_writer
|
|
||||||
, gz_seeker
|
|
||||||
, gz_closer
|
|
||||||
};
|
|
||||||
|
|
||||||
static FILE *zlib_fopen_wrapper(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path)
|
|
||||||
{
|
|
||||||
struct gz_cookie *gc = NULL;
|
|
||||||
FILE *fp;
|
|
||||||
int fissock=0, fsocketd=0;
|
|
||||||
|
|
||||||
gc = (struct gz_cookie *)emalloc(sizeof(struct gz_cookie));
|
|
||||||
|
|
||||||
if(gc) {
|
|
||||||
*issock = 0;
|
|
||||||
|
|
||||||
while(*path!=':')
|
|
||||||
path++;
|
|
||||||
|
|
||||||
path++;
|
|
||||||
|
|
||||||
fp = php_fopen_wrapper(path, mode, options|IGNORE_URL, &fissock, &fsocketd, NULL);
|
|
||||||
|
|
||||||
if (!fp) {
|
|
||||||
efree(gc);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
gc->gz_file = gzdopen(fileno(fp), mode);
|
|
||||||
|
|
||||||
if(gc->gz_file) {
|
|
||||||
return fopencookie(gc,mode,gz_cookie_functions);
|
|
||||||
} else {
|
|
||||||
efree(gc);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
errno = ENOENT;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static int php_do_deflate(uint str_length, Bytef **p_buffer, uint *p_buf_used ZLIBLS_DC)
|
static int php_do_deflate(uint str_length, Bytef **p_buffer, uint *p_buf_used ZLIBLS_DC)
|
||||||
|
|
105
ext/zlib/zlib_fopen_wrapper.c
Normal file
105
ext/zlib/zlib_fopen_wrapper.c
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
| PHP version 4.0 |
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
| This source file is subject to version 2.02 of the PHP license, |
|
||||||
|
| that is bundled with this package in the file LICENSE, and is |
|
||||||
|
| available at through the world-wide-web at |
|
||||||
|
| http://www.php.net/license/2_02.txt. |
|
||||||
|
| If you did not receive a copy of the PHP license and are unable to |
|
||||||
|
| obtain it through the world-wide-web, please send a note to |
|
||||||
|
| license@php.net so we can mail you a copy immediately. |
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
|
||||||
|
| Stefan Röhrich <sr@linux.de> |
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
*/
|
||||||
|
/* $Id$ */
|
||||||
|
#define IS_EXT_MODULE
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
|
#include "php.h"
|
||||||
|
#include "php_zlib.h"
|
||||||
|
#include "fopen-wrappers.h"
|
||||||
|
|
||||||
|
#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, const char *buffer, size_t size) {
|
||||||
|
return gzwrite(((struct gz_cookie *)cookie)->gz_file,(char *)buffer,size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int gz_seeker(void *cookie,off_t position, int whence) {
|
||||||
|
return gzseek(((struct gz_cookie *)cookie)->gz_file,(z_off_t)position,whence);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int gz_closer(void *cookie) {
|
||||||
|
int ret=gzclose(((struct gz_cookie *)cookie)->gz_file);
|
||||||
|
free(cookie);
|
||||||
|
cookie=NULL;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static COOKIE_IO_FUNCTIONS_T gz_cookie_functions =
|
||||||
|
{ gz_reader
|
||||||
|
, gz_writer
|
||||||
|
, gz_seeker
|
||||||
|
, gz_closer
|
||||||
|
};
|
||||||
|
|
||||||
|
FILE *zlib_fopen_wrapper(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path)
|
||||||
|
{
|
||||||
|
struct gz_cookie *gc = NULL;
|
||||||
|
FILE *fp;
|
||||||
|
int fissock=0, fsocketd=0;
|
||||||
|
|
||||||
|
gc = (struct gz_cookie *)malloc(sizeof(struct gz_cookie));
|
||||||
|
|
||||||
|
if(gc) {
|
||||||
|
*issock = 0;
|
||||||
|
|
||||||
|
while(*path!=':')
|
||||||
|
path++;
|
||||||
|
|
||||||
|
path++;
|
||||||
|
|
||||||
|
fp = php_fopen_wrapper(path, mode, options|IGNORE_URL, &fissock, &fsocketd, NULL);
|
||||||
|
|
||||||
|
if (!fp) {
|
||||||
|
free(gc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
gc->gz_file = gzdopen(fileno(fp), mode);
|
||||||
|
|
||||||
|
if(gc->gz_file) {
|
||||||
|
return fopencookie(gc,mode,gz_cookie_functions);
|
||||||
|
} else {
|
||||||
|
free(gc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errno = ENOENT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* tab-width: 4
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* End:
|
||||||
|
*/
|
Loading…
Add table
Add a link
Reference in a new issue