summaryrefslogtreecommitdiff
path: root/ext/zlib
diff options
context:
space:
mode:
Diffstat (limited to 'ext/zlib')
-rw-r--r--ext/zlib/CREDITS2
-rw-r--r--ext/zlib/config.w3222
-rw-r--r--ext/zlib/config0.m465
-rw-r--r--ext/zlib/package.xml70
-rw-r--r--ext/zlib/php_zlib.def60
-rw-r--r--ext/zlib/php_zlib.h84
-rw-r--r--ext/zlib/tests/001.phpt32
-rw-r--r--ext/zlib/tests/002.phpt24
-rw-r--r--ext/zlib/tests/003.phpt14
-rw-r--r--ext/zlib/tests/004.phpt66
-rw-r--r--ext/zlib/tests/004.txt.gzbin0 -> 150 bytes
-rw-r--r--ext/zlib/tests/005.phpt72
-rw-r--r--ext/zlib/tests/006.phpt75
-rw-r--r--ext/zlib/tests/007.phpt51
-rw-r--r--ext/zlib/tests/008.phpt11
-rw-r--r--ext/zlib/tests/bug51269.phpt21
-rw-r--r--ext/zlib/tests/bug55544-win.phptbin0 -> 427 bytes
-rw-r--r--ext/zlib/tests/bug55544.phptbin0 -> 430 bytes
-rw-r--r--ext/zlib/tests/bug60761.phpt54
-rw-r--r--ext/zlib/tests/bug61139.phpt14
-rw-r--r--ext/zlib/tests/bug61287.phpt24
-rw-r--r--ext/zlib/tests/bug61443.phpt15
-rw-r--r--ext/zlib/tests/bug61820.phpt23
-rw-r--r--ext/zlib/tests/bug_34821.phpt41
-rw-r--r--ext/zlib/tests/bug_40189.phpt27
-rw-r--r--ext/zlib/tests/bug_52944-darwin.phpt24
-rw-r--r--ext/zlib/tests/bug_52944-win.phpt24
-rw-r--r--ext/zlib/tests/bug_52944.phpt27
-rw-r--r--ext/zlib/tests/bug_52944_corrupted_data.inc142
-rw-r--r--ext/zlib/tests/compress_zlib_wrapper.phpt22
-rw-r--r--ext/zlib/tests/data.inc88
-rw-r--r--ext/zlib/tests/func.inc17
-rw-r--r--ext/zlib/tests/gzclose_basic.phpt39
-rw-r--r--ext/zlib/tests/gzclose_error.phpt33
-rw-r--r--ext/zlib/tests/gzcompress_basic1.phpt125
-rw-r--r--ext/zlib/tests/gzcompress_error1.phpt84
-rw-r--r--ext/zlib/tests/gzcompress_variation1.phpt34
-rw-r--r--ext/zlib/tests/gzdeflate_basic1.phpt125
-rw-r--r--ext/zlib/tests/gzdeflate_error1.phpt86
-rw-r--r--ext/zlib/tests/gzdeflate_variation1.phpt36
-rw-r--r--ext/zlib/tests/gzencode_basic1.phpt115
-rw-r--r--ext/zlib/tests/gzencode_error1.phpt98
-rw-r--r--ext/zlib/tests/gzencode_variation1-win32.phpt46
-rw-r--r--ext/zlib/tests/gzencode_variation1.phpt37
-rw-r--r--ext/zlib/tests/gzencode_variation2-win32.phpt40
-rw-r--r--ext/zlib/tests/gzencode_variation2.phpt40
-rw-r--r--ext/zlib/tests/gzeof_basic.phpt58
-rw-r--r--ext/zlib/tests/gzeof_error.phpt28
-rw-r--r--ext/zlib/tests/gzeof_variation1.phpt31
-rw-r--r--ext/zlib/tests/gzfile_basic.phpt39
-rw-r--r--ext/zlib/tests/gzfile_basic2.phpt39
-rw-r--r--ext/zlib/tests/gzfile_error.phpt29
-rw-r--r--ext/zlib/tests/gzfile_variation1.phpt43
-rw-r--r--ext/zlib/tests/gzfile_variation10.phpt119
-rw-r--r--ext/zlib/tests/gzfile_variation11.phpt129
-rw-r--r--ext/zlib/tests/gzfile_variation12.phpt108
-rw-r--r--ext/zlib/tests/gzfile_variation13.phpt51
-rw-r--r--ext/zlib/tests/gzfile_variation14.phpt44
-rw-r--r--ext/zlib/tests/gzfile_variation15.phpt109
-rw-r--r--ext/zlib/tests/gzfile_variation2.phpt40
-rw-r--r--ext/zlib/tests/gzfile_variation3.phpt50
-rw-r--r--ext/zlib/tests/gzfile_variation4.phpt43
-rw-r--r--ext/zlib/tests/gzfile_variation5.phpt39
-rw-r--r--ext/zlib/tests/gzfile_variation6.phpt49
-rw-r--r--ext/zlib/tests/gzfile_variation7.phpt44
-rw-r--r--ext/zlib/tests/gzfile_variation8.phpt43
-rw-r--r--ext/zlib/tests/gzfile_variation9.phpt107
-rw-r--r--ext/zlib/tests/gzfilegzreadfile.phpt82
-rw-r--r--ext/zlib/tests/gzgetc_basic.phpt42
-rw-r--r--ext/zlib/tests/gzgetc_basic_1.phpt43
-rw-r--r--ext/zlib/tests/gzgetc_error.phpt29
-rw-r--r--ext/zlib/tests/gzgets_basic.phpt46
-rw-r--r--ext/zlib/tests/gzgets_error.phpt30
-rw-r--r--ext/zlib/tests/gzinflate-bug42663.phpt26
-rw-r--r--ext/zlib/tests/gzinflate_error1.phpt75
-rw-r--r--ext/zlib/tests/gzinflate_length.phpt26
-rw-r--r--ext/zlib/tests/gzopen_basic.phpt51
-rw-r--r--ext/zlib/tests/gzopen_basic2.phpt52
-rw-r--r--ext/zlib/tests/gzopen_error.phpt47
-rw-r--r--ext/zlib/tests/gzopen_include_path.inc92
-rw-r--r--ext/zlib/tests/gzopen_variation1.phpt228
-rw-r--r--ext/zlib/tests/gzopen_variation2.phpt227
-rw-r--r--ext/zlib/tests/gzopen_variation3.phpt218
-rw-r--r--ext/zlib/tests/gzopen_variation4.phpt161
-rw-r--r--ext/zlib/tests/gzopen_variation5.phpt71
-rw-r--r--ext/zlib/tests/gzopen_variation6.phpt47
-rw-r--r--ext/zlib/tests/gzopen_variation7.phpt31
-rw-r--r--ext/zlib/tests/gzopen_variation8.phpt42
-rw-r--r--ext/zlib/tests/gzopen_variation9.phpt55
-rw-r--r--ext/zlib/tests/gzpassthru_basic.phpt32
-rw-r--r--ext/zlib/tests/gzpassthru_error.phpt29
-rw-r--r--ext/zlib/tests/gzputs_basic.phpt31
-rw-r--r--ext/zlib/tests/gzread_basic.phpt37
-rw-r--r--ext/zlib/tests/gzread_error.phpt32
-rw-r--r--ext/zlib/tests/gzread_error2.phpt32
-rw-r--r--ext/zlib/tests/gzread_variation1.phpt34
-rw-r--r--ext/zlib/tests/gzreadgzwrite.phpt36
-rw-r--r--ext/zlib/tests/gzreadgzwriteplain.phpt54
-rw-r--r--ext/zlib/tests/gzrewind_basic.phpt36
-rw-r--r--ext/zlib/tests/gzrewind_basic2.phpt34
-rw-r--r--ext/zlib/tests/gzrewind_error.phpt27
-rw-r--r--ext/zlib/tests/gzrewind_variation1.phpt28
-rw-r--r--ext/zlib/tests/gzseek_basic.phpt49
-rw-r--r--ext/zlib/tests/gzseek_basic2.phpt42
-rw-r--r--ext/zlib/tests/gzseek_error.phpt33
-rw-r--r--ext/zlib/tests/gzseek_variation1.phpt33
-rw-r--r--ext/zlib/tests/gzseek_variation2.phpt49
-rw-r--r--ext/zlib/tests/gzseek_variation3.phpt50
-rw-r--r--ext/zlib/tests/gzseek_variation4.phpt42
-rw-r--r--ext/zlib/tests/gzseek_variation5.phpt42
-rw-r--r--ext/zlib/tests/gzseek_variation6.phpt39
-rw-r--r--ext/zlib/tests/gzseek_variation7.phpt47
-rw-r--r--ext/zlib/tests/gztell_basic.phpt34
-rw-r--r--ext/zlib/tests/gztell_basic2.phpt42
-rw-r--r--ext/zlib/tests/gztell_error.phpt26
-rw-r--r--ext/zlib/tests/gzuncompress_basic1.phpt43
-rw-r--r--ext/zlib/tests/gzuncompress_error1.phpt80
-rw-r--r--ext/zlib/tests/gzwrite_basic.phpt31
-rw-r--r--ext/zlib/tests/gzwrite_error.phpt35
-rw-r--r--ext/zlib/tests/gzwrite_error2.phpt30
-rw-r--r--ext/zlib/tests/gzwrite_variation1.phpt27
-rw-r--r--ext/zlib/tests/ob_001.phpt20
-rw-r--r--ext/zlib/tests/ob_002.phpt18
-rw-r--r--ext/zlib/tests/ob_003.phpt23
-rw-r--r--ext/zlib/tests/ob_004.phpt24
-rw-r--r--ext/zlib/tests/ob_005.phpt22
-rw-r--r--ext/zlib/tests/ob_gzhandler_legacy_002.phpt24
-rw-r--r--ext/zlib/tests/readgzfile_basic.phpt34
-rw-r--r--ext/zlib/tests/readgzfile_basic2.phpt34
-rw-r--r--ext/zlib/tests/readgzfile_error.phpt29
-rw-r--r--ext/zlib/tests/readgzfile_variation1.phpt43
-rw-r--r--ext/zlib/tests/readgzfile_variation10.phpt67
-rw-r--r--ext/zlib/tests/readgzfile_variation11.phpt64
-rw-r--r--ext/zlib/tests/readgzfile_variation12.phpt56
-rw-r--r--ext/zlib/tests/readgzfile_variation13.phpt51
-rw-r--r--ext/zlib/tests/readgzfile_variation14.phpt44
-rw-r--r--ext/zlib/tests/readgzfile_variation15.phpt94
-rw-r--r--ext/zlib/tests/readgzfile_variation2.phpt40
-rw-r--r--ext/zlib/tests/readgzfile_variation3.phpt50
-rw-r--r--ext/zlib/tests/readgzfile_variation4.phpt43
-rw-r--r--ext/zlib/tests/readgzfile_variation5.phpt39
-rw-r--r--ext/zlib/tests/readgzfile_variation6.phpt49
-rw-r--r--ext/zlib/tests/readgzfile_variation7.phpt43
-rw-r--r--ext/zlib/tests/readgzfile_variation8.phpt43
-rw-r--r--ext/zlib/tests/readgzfile_variation9.phpt55
-rw-r--r--ext/zlib/tests/reading_include_path.inc27
-rw-r--r--ext/zlib/tests/zlib_filter_deflate.phpt17
-rw-r--r--ext/zlib/tests/zlib_filter_deflate2.phpt16
-rw-r--r--ext/zlib/tests/zlib_filter_inflate.phpt17
-rw-r--r--ext/zlib/tests/zlib_filter_inflate2.phpt41
-rw-r--r--ext/zlib/tests/zlib_scheme_copy_basic.phpt37
-rw-r--r--ext/zlib/tests/zlib_scheme_copy_variation1.phpt38
-rw-r--r--ext/zlib/tests/zlib_scheme_copy_variation2.phpt53
-rw-r--r--ext/zlib/tests/zlib_scheme_dir_basic.phpt26
-rw-r--r--ext/zlib/tests/zlib_scheme_file_basic.phpt38
-rw-r--r--ext/zlib/tests/zlib_scheme_file_get_contents_basic.phpt24
-rw-r--r--ext/zlib/tests/zlib_scheme_file_put_contents_basic.phpt31
-rw-r--r--ext/zlib/tests/zlib_scheme_file_read_file_basic.phpt23
-rw-r--r--ext/zlib/tests/zlib_scheme_fopen_basic.phpt25
-rw-r--r--ext/zlib/tests/zlib_scheme_fopen_variation1.phpt30
-rw-r--r--ext/zlib/tests/zlib_scheme_rename_basic.phpt21
-rw-r--r--ext/zlib/tests/zlib_scheme_stat_basic.phpt22
-rw-r--r--ext/zlib/tests/zlib_scheme_stat_basic2.phpt46
-rw-r--r--ext/zlib/tests/zlib_scheme_unlink_basic.phpt21
-rw-r--r--ext/zlib/tests/zlib_wrapper_fflush_basic.phpt33
-rw-r--r--ext/zlib/tests/zlib_wrapper_flock_basic.phpt19
-rw-r--r--ext/zlib/tests/zlib_wrapper_fstat_basic.phpt19
-rw-r--r--ext/zlib/tests/zlib_wrapper_ftruncate_basic.phpt32
-rw-r--r--ext/zlib/tests/zlib_wrapper_meta_data_basic.phpt65
-rw-r--r--ext/zlib/zlib.c1037
-rw-r--r--ext/zlib/zlib.dsp121
-rw-r--r--ext/zlib/zlib_filter.c454
-rw-r--r--ext/zlib/zlib_fopen_wrapper.c187
-rw-r--r--ext/zlib/zlib_win32_howto.txt16
174 files changed, 9873 insertions, 0 deletions
diff --git a/ext/zlib/CREDITS b/ext/zlib/CREDITS
new file mode 100644
index 0000000..a1773c4
--- /dev/null
+++ b/ext/zlib/CREDITS
@@ -0,0 +1,2 @@
+Zlib
+Rasmus Lerdorf, Stefan Roehrich, Zeev Suraski, Jade Nicoletti, Michael Wallner
diff --git a/ext/zlib/config.w32 b/ext/zlib/config.w32
new file mode 100644
index 0000000..000b1cc
--- /dev/null
+++ b/ext/zlib/config.w32
@@ -0,0 +1,22 @@
+// $Id$
+// vim:ft=javascript
+
+ARG_ENABLE("zlib", "ZLIB support", "yes");
+
+if (PHP_ZLIB == "yes") {
+ if (CHECK_LIB("zlib_a.lib;zlib.lib", "zlib", PHP_ZLIB) &&
+ CHECK_HEADER_ADD_INCLUDE("zlib.h", "CFLAGS", "..\\zlib;" + php_usual_include_suspects)) {
+
+ EXTENSION("zlib", "zlib.c zlib_fopen_wrapper.c zlib_filter.c", null, "/D ZLIB_EXPORTS");
+ AC_DEFINE("HAVE_ZLIB", 1, "ZLIB support");
+
+ if (!PHP_ZLIB_SHARED) {
+ ADD_DEF_FILE("ext\\zlib\\php_zlib.def");
+ }
+ } else {
+ WARNING("zlib support can't be enabled, zlib is missing")
+ PHP_ZLIB = "no"
+ }
+}
+
+
diff --git a/ext/zlib/config0.m4 b/ext/zlib/config0.m4
new file mode 100644
index 0000000..25c7f4f
--- /dev/null
+++ b/ext/zlib/config0.m4
@@ -0,0 +1,65 @@
+dnl
+dnl $Id$
+dnl
+
+PHP_ARG_WITH(zlib,for ZLIB support,
+[ --with-zlib[=DIR] Include ZLIB support (requires zlib >= 1.0.9)])
+
+PHP_ARG_WITH(zlib-dir,if the location of ZLIB install directory is defined,
+[ --with-zlib-dir=<DIR> Define the location of zlib install directory], no, no)
+
+if test "$PHP_ZLIB" != "no" || test "$PHP_ZLIB_DIR" != "no"; then
+ PHP_NEW_EXTENSION(zlib, zlib.c zlib_fopen_wrapper.c zlib_filter.c, $ext_shared)
+ PHP_SUBST(ZLIB_SHARED_LIBADD)
+
+ if test "$PHP_ZLIB" != "yes" -a "$PHP_ZLIB" != "no"; then
+ if test -f $PHP_ZLIB/include/zlib/zlib.h; then
+ ZLIB_DIR=$PHP_ZLIB
+ ZLIB_INCDIR=$ZLIB_DIR/include/zlib
+ elif test -f $PHP_ZLIB/include/zlib.h; then
+ ZLIB_DIR=$PHP_ZLIB
+ ZLIB_INCDIR=$ZLIB_DIR/include
+ fi
+ else
+ for i in /usr/local /usr $PHP_ZLIB_DIR; do
+ if test -f $i/include/zlib/zlib.h; then
+ ZLIB_DIR=$i
+ ZLIB_INCDIR=$i/include/zlib
+ elif test -f $i/include/zlib.h; then
+ ZLIB_DIR=$i
+ ZLIB_INCDIR=$i/include
+ fi
+ done
+ fi
+
+ if test -z "$ZLIB_DIR"; then
+ AC_MSG_ERROR(Cannot find libz)
+ fi
+
+ case $ZLIB_DIR in
+ /usr) ac_extra= ;;
+ *) ac_extra=-L$ZLIB_DIR/$PHP_LIBDIR ;;
+ esac
+
+ AC_MSG_CHECKING([for zlib version >= 1.2.0.4])
+ ZLIB_VERSION=`$EGREP "define ZLIB_VERSION" $ZLIB_DIR/include/zlib.h | $SED -e 's/[[^0-9\.]]//g'`
+ AC_MSG_RESULT([$ZLIB_VERSION])
+ if test `echo $ZLIB_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*1000000 + $2*10000 + $3*100 + $4}'` -lt 1020004; then
+ AC_MSG_ERROR([libz version greater or equal to 1.2.0.4 required])
+ fi
+
+ PHP_CHECK_LIBRARY(z, gzgets, [
+ AC_DEFINE(HAVE_ZLIB,1,[ ])
+ ],[
+ AC_MSG_ERROR(ZLIB extension requires gzgets in zlib)
+ ],[
+ $ac_extra
+ ])
+
+ PHP_ADD_LIBPATH($ZLIB_DIR/$PHP_LIBDIR, ZLIB_SHARED_LIBADD)
+
+ PHP_ZLIB_DIR=$ZLIB_DIR
+ PHP_ADD_LIBRARY(z,, ZLIB_SHARED_LIBADD)
+ PHP_ADD_INCLUDE($ZLIB_INCDIR)
+
+fi
diff --git a/ext/zlib/package.xml b/ext/zlib/package.xml
new file mode 100644
index 0000000..4be42e0
--- /dev/null
+++ b/ext/zlib/package.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE package SYSTEM "../pear/package.dtd">
+<package>
+ <name>zlib</name>
+ <summary>zlib compression management</summary>
+ <maintainers>
+ <maintainer>
+ <user>sr</user>
+ <name>Stefan Roehrich</name>
+ <email>sr@linux.de</email>
+ <role>lead</role>
+ </maintainer>
+ <maintainer>
+ <user>rasmus</user>
+ <name>Rasmus Lerdorf</name>
+ <email>rasmus@php.net</email>
+ <role>developer</role>
+ </maintainer>
+ <maintainer>
+ <user>zeev</user>
+ <name>Zeev Suraski</name>
+ <email>zeev@php.net</email>
+ <role>developer</role>
+ </maintainer>
+ <maintainer>
+ <user>???</user>
+ <name>Jade Nicoletti</name>
+ <email>???@php.net</email>
+ <role>developer</role>
+ </maintainer>
+ </maintainers>
+ <description>
+This module enables you to transparently read and write
+gzip (.gz) compressed files, through versions of most of
+the filesystem functions which work with gzip-compressed
+files (and uncompressed files, too, but not with sockets).
+ </description>
+ <license>PHP</license>
+ <release>
+ <state>beta</state>
+ <version>5.0.0rc1</version>
+ <date>2004-03-19</date>
+ <notes>
+package.xml added to support installation using pear installer
+ </notes>
+ <filelist>
+ <file role="doc" name="CREDITS"/>
+ <file role="doc" name="zlib_win32_howto.txt"/>
+ <file role="src" name="config0.m4"/>
+ <file role="src" name="config.w32"/>
+ <file role="src" name="php_zlib.h"/>
+ <file role="src" name="zlib.c"/>
+ <file role="src" name="zlib.dsp"/>
+ <file role="src" name="zlib_fopen_wrapper.c"/>
+ <file role="src" name="php_zlib.def"/>
+ <file role="test" name="tests/001.phpt"/>
+ <file role="test" name="tests/002.phpt"/>
+ <file role="test" name="tests/003.phpt"/>
+ <file role="test" name="tests/gzreadgzwrite.phpt"/>
+ <file role="test" name="tests/gzreadgzwriteplain.phpt"/>
+ <file role="test" name="tests/gzfilegzreadfile.phpt"/>
+ </filelist>
+ <deps>
+ <dep type="php" rel="ge" version="5" />
+ </deps>
+ </release>
+</package>
+<!--
+vim:et:ts=1:sw=1
+-->
diff --git a/ext/zlib/php_zlib.def b/ext/zlib/php_zlib.def
new file mode 100644
index 0000000..a47cbc1
--- /dev/null
+++ b/ext/zlib/php_zlib.def
@@ -0,0 +1,60 @@
+LIBRARY
+; zlib data compression library
+
+EXPORTS
+; basic functions
+ zlibVersion
+ deflate
+ deflateEnd
+ inflate
+ inflateEnd
+; advanced functions
+ deflateSetDictionary
+ deflateCopy
+ deflateReset
+ deflateParams
+ deflateBound
+ deflatePrime
+ inflateSetDictionary
+ inflateSync
+ inflateCopy
+ inflateReset
+ inflateBack
+ inflateBackEnd
+ zlibCompileFlags
+; utility functions
+ compress
+ compress2
+ compressBound
+ uncompress
+ gzopen
+ gzdopen
+ gzsetparams
+ gzread
+ gzwrite
+ gzprintf
+ gzputs
+ gzgets
+ gzputc
+ gzgetc
+ gzungetc
+ gzflush
+ gzseek
+ gzrewind
+ gztell
+ gzeof
+ gzclose
+ gzerror
+ gzclearerr
+; checksum functions
+ adler32
+ crc32
+; various hacks, don't look :)
+ deflateInit_
+ deflateInit2_
+ inflateInit_
+ inflateInit2_
+ inflateBackInit_
+ inflateSyncPoint
+ get_crc_table
+ zError
diff --git a/ext/zlib/php_zlib.h b/ext/zlib/php_zlib.h
new file mode 100644
index 0000000..6b1d0cd
--- /dev/null
+++ b/ext/zlib/php_zlib.h
@@ -0,0 +1,84 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.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> |
+ | Michael Wallner <mike@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef PHP_ZLIB_H
+#define PHP_ZLIB_H
+
+#include <zlib.h>
+
+#define PHP_ZLIB_ENCODING_RAW -0xf
+#define PHP_ZLIB_ENCODING_GZIP 0x1f
+#define PHP_ZLIB_ENCODING_DEFLATE 0x0f
+
+#define PHP_ZLIB_ENCODING_ANY 0x2f
+
+#define PHP_ZLIB_OUTPUT_HANDLER_NAME "zlib output compression"
+#define PHP_ZLIB_BUFFER_SIZE_GUESS(in_len) (((size_t) ((double) in_len * (double) 1.015)) + 10 + 8 + 4 + 1)
+
+typedef struct _php_zlib_buffer {
+ char *data;
+ char *aptr;
+ size_t used;
+ size_t free;
+ size_t size;
+} php_zlib_buffer;
+
+typedef struct _php_zlib_context {
+ z_stream Z;
+ php_zlib_buffer buffer;
+} php_zlib_context;
+
+ZEND_BEGIN_MODULE_GLOBALS(zlib)
+ /* variables for transparent gzip encoding */
+ int compression_coding;
+ long output_compression;
+ long output_compression_level;
+ char *output_handler;
+ php_zlib_context *ob_gzhandler;
+ long output_compression_default;
+ zend_bool handler_registered;
+ZEND_END_MODULE_GLOBALS(zlib);
+
+php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
+extern php_stream_ops php_stream_gzio_ops;
+extern php_stream_wrapper php_stream_gzip_wrapper;
+extern php_stream_filter_factory php_zlib_filter_factory;
+extern zend_module_entry php_zlib_module_entry;
+#define zlib_module_ptr &php_zlib_module_entry
+#define phpext_zlib_ptr zlib_module_ptr
+
+#ifdef ZTS
+# include "TSRM.h"
+# define ZLIBG(v) TSRMG(zlib_globals_id, zend_zlib_globals *, v)
+#else
+# define ZLIBG(v) (zlib_globals.v)
+#endif
+
+#endif /* PHP_ZLIB_H */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ */
diff --git a/ext/zlib/tests/001.phpt b/ext/zlib/tests/001.phpt
new file mode 100644
index 0000000..0c2ca28
--- /dev/null
+++ b/ext/zlib/tests/001.phpt
@@ -0,0 +1,32 @@
+--TEST--
+gzdeflate()/gzinflate()
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php /* $Id$ */
+$original = str_repeat("hallo php",4096);
+$packed=gzdeflate($original);
+echo strlen($packed)." ".strlen($original)."\n";
+$unpacked=gzinflate($packed);
+if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
+
+/* with explicit compression level, length */
+$original = str_repeat("hallo php",4096);
+$packed=gzdeflate($original, 9);
+echo strlen($packed)." ".strlen($original)."\n";
+$unpacked=gzinflate($packed, 40000);
+if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
+
+$original = 'aaaaaaaaaaaaaaa';
+$packed=gzdeflate($original);
+echo strlen($packed)." ".strlen($original)."\n";
+$unpacked=gzinflate($packed);
+if (strcmp($original,$unpacked)==0) echo "Strings are equal";
+?>
+--EXPECT--
+100 36864
+Strings are equal
+100 36864
+Strings are equal
+5 15
+Strings are equal
diff --git a/ext/zlib/tests/002.phpt b/ext/zlib/tests/002.phpt
new file mode 100644
index 0000000..9844a1b
--- /dev/null
+++ b/ext/zlib/tests/002.phpt
@@ -0,0 +1,24 @@
+--TEST--
+gzcompress()/gzuncompress()
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php /* $Id$ */
+$original = str_repeat("hallo php",4096);
+$packed=gzcompress($original);
+echo strlen($packed)." ".strlen($original)."\n";
+$unpacked=gzuncompress($packed);
+if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
+
+/* with explicit compression level, length */
+$original = str_repeat("hallo php",4096);
+$packed=gzcompress($original, 9);
+echo strlen($packed)." ".strlen($original)."\n";
+$unpacked=gzuncompress($packed, 40000);
+if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
+?>
+--EXPECT--
+106 36864
+Strings are equal
+106 36864
+Strings are equal
diff --git a/ext/zlib/tests/003.phpt b/ext/zlib/tests/003.phpt
new file mode 100644
index 0000000..d9275d9
--- /dev/null
+++ b/ext/zlib/tests/003.phpt
@@ -0,0 +1,14 @@
+--TEST--
+gzencode()
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+$original = str_repeat("hallo php",4096);
+$packed = gzencode($original);
+echo strlen($packed)." ".strlen($original). "\n";
+if (strcmp($original, gzdecode($packed)) == 0) echo "Strings are equal";
+?>
+--EXPECT--
+118 36864
+Strings are equal
diff --git a/ext/zlib/tests/004.phpt b/ext/zlib/tests/004.phpt
new file mode 100644
index 0000000..ebc7d82
--- /dev/null
+++ b/ext/zlib/tests/004.phpt
@@ -0,0 +1,66 @@
+--TEST--
+gzfile() with various invalid params
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(gzfile());
+var_dump(gzfile("nonexistent_file_gzfile",1));
+var_dump(gzfile(1,1,1));
+
+var_dump(gzfile(dirname(__FILE__)."/004.txt.gz"));
+var_dump(gzfile(dirname(__FILE__)."/004.txt.gz", 1));
+
+echo "Done\n";
+?>
+--EXPECTF--
+Warning: gzfile() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: gzfile(nonexistent_file_gzfile): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+Done
diff --git a/ext/zlib/tests/004.txt.gz b/ext/zlib/tests/004.txt.gz
new file mode 100644
index 0000000..07805db
--- /dev/null
+++ b/ext/zlib/tests/004.txt.gz
Binary files differ
diff --git a/ext/zlib/tests/005.phpt b/ext/zlib/tests/005.phpt
new file mode 100644
index 0000000..84fc3b5
--- /dev/null
+++ b/ext/zlib/tests/005.phpt
@@ -0,0 +1,72 @@
+--TEST--
+gzcompress()/gzuncompress() and invalid params
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(gzcompress());
+var_dump(gzcompress("", 1000));
+var_dump(gzcompress("", -1));
+
+var_dump(gzcompress(""));
+var_dump(gzcompress("", 9));
+
+$string = "Answer me, it can't be so hard
+Cry to relieve what's in your heart
+Desolation, grief and agony";
+
+var_dump($data1 = gzcompress($string));
+var_dump($data2 = gzcompress($string, 9));
+
+var_dump(gzuncompress());
+var_dump(gzuncompress("", 1000));
+var_dump(gzuncompress("", -1));
+
+var_dump(gzuncompress(""));
+var_dump(gzuncompress("", 9));
+
+var_dump(gzuncompress($data1));
+var_dump(gzuncompress($data2));
+$data2{4} = 0;
+var_dump(gzuncompress($data2));
+
+echo "Done\n";
+?>
+--EXPECTF--
+
+Warning: gzcompress() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: gzcompress(): compression level (1000) must be within -1..9 in %s on line %d
+bool(false)
+string(%d) "%a"
+string(%d) "%a"
+string(%d) "%a"
+string(%d) "%a"
+string(%d) "%a"
+
+Warning: gzuncompress() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: gzuncompress(): %s error in %s on line %d
+bool(false)
+
+Warning: gzuncompress(): length (-1) must be greater or equal zero in %s on line %d
+bool(false)
+
+Warning: gzuncompress(): %s error in %s on line %d
+bool(false)
+
+Warning: gzuncompress(): %s error in %s on line %d
+bool(false)
+string(94) "Answer me, it can't be so hard
+Cry to relieve what's in your heart
+Desolation, grief and agony"
+string(94) "Answer me, it can't be so hard
+Cry to relieve what's in your heart
+Desolation, grief and agony"
+
+Warning: gzuncompress(): %s error in %s on line %d
+bool(false)
+Done
diff --git a/ext/zlib/tests/006.phpt b/ext/zlib/tests/006.phpt
new file mode 100644
index 0000000..8c03ea0
--- /dev/null
+++ b/ext/zlib/tests/006.phpt
@@ -0,0 +1,75 @@
+--TEST--
+gzdeflate()/gzinflate() and invalid params
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(gzdeflate());
+var_dump(gzdeflate("", 1000));
+var_dump(gzdeflate("", -1));
+
+var_dump(gzdeflate(""));
+var_dump(gzdeflate("", 9));
+
+$string = "Answer me, it can't be so hard
+Cry to relieve what's in your heart
+Desolation, grief and agony";
+
+var_dump($data1 = gzdeflate($string));
+var_dump($data2 = gzdeflate($string, 9));
+
+var_dump(gzinflate());
+var_dump(gzinflate(""));
+var_dump(gzinflate("asfwe", 1000));
+var_dump(gzinflate("asdf", -1));
+
+var_dump(gzinflate("asdf"));
+var_dump(gzinflate("asdf", 9));
+
+var_dump(gzinflate($data1));
+var_dump(gzinflate($data2));
+$data2{4} = 0;
+var_dump(gzinflate($data2));
+
+echo "Done\n";
+?>
+--EXPECTF--
+Warning: gzdeflate() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: gzdeflate(): compression level (1000) must be within -1..9 in %s on line %d
+bool(false)
+string(%d) "%a"
+string(%d) "%a"
+string(%d) "%a"
+string(%d) "%a"
+string(%d) "%a"
+
+Warning: gzinflate() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: gzinflate(): data error in %s on line %d
+bool(false)
+
+Warning: gzinflate(): data error in %s on line %d
+bool(false)
+
+Warning: gzinflate(): length (-1) must be greater or equal zero in %s on line %d
+bool(false)
+
+Warning: gzinflate(): data error in %s on line %d
+bool(false)
+
+Warning: gzinflate(): data error in %s on line %d
+bool(false)
+string(94) "Answer me, it can't be so hard
+Cry to relieve what's in your heart
+Desolation, grief and agony"
+string(94) "Answer me, it can't be so hard
+Cry to relieve what's in your heart
+Desolation, grief and agony"
+
+Warning: gzinflate(): data error in %s on line %d
+bool(false)
+Done
diff --git a/ext/zlib/tests/007.phpt b/ext/zlib/tests/007.phpt
new file mode 100644
index 0000000..09207a5
--- /dev/null
+++ b/ext/zlib/tests/007.phpt
@@ -0,0 +1,51 @@
+--TEST--
+gzencode() and invalid params
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(gzencode());
+var_dump(gzencode(1,1,1,1));
+var_dump(gzencode("", -10));
+var_dump(gzencode("", 100));
+var_dump(gzencode("", 1, 100));
+
+var_dump(gzencode("", -1, ZLIB_ENCODING_GZIP));
+var_dump(gzencode("", 9, ZLIB_ENCODING_DEFLATE));
+
+$string = "Light of my sun
+Light in this temple
+Light in my truth
+Lies in the darkness";
+
+var_dump(gzencode($string, 9, 3));
+
+var_dump(gzencode($string, -1, ZLIB_ENCODING_GZIP));
+var_dump(gzencode($string, 9, ZLIB_ENCODING_DEFLATE));
+
+echo "Done\n";
+?>
+--EXPECTF--
+Warning: gzencode() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: gzencode() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+
+Warning: gzencode(): compression level (-10) must be within -1..9 in %s on line %d
+bool(false)
+
+Warning: gzencode(): compression level (100) must be within -1..9 in %s on line %d
+bool(false)
+
+Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
+bool(false)
+string(%d) "%s"
+string(%d) "%s"
+
+Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
+bool(false)
+string(%d) "%s"
+string(%d) "%s"
+Done
diff --git a/ext/zlib/tests/008.phpt b/ext/zlib/tests/008.phpt
new file mode 100644
index 0000000..4102e0c
--- /dev/null
+++ b/ext/zlib/tests/008.phpt
@@ -0,0 +1,11 @@
+--TEST--
+zlib.output_compression=1 with client not accepting compression
+--SKIPIF--
+<?php if (!extension_loaded('zlib')) die('skip'); ?>
+--INI--
+zlib.output_compression=1
+display_startup_errors=1
+--FILE--
+===DONE===
+--EXPECT--
+===DONE===
diff --git a/ext/zlib/tests/bug51269.phpt b/ext/zlib/tests/bug51269.phpt
new file mode 100644
index 0000000..6b97bac
--- /dev/null
+++ b/ext/zlib/tests/bug51269.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #51269 (zlib.output_compression Overwrites Vary Header)
+--INI--
+zlib.output_compression=1
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip zlib required");
+?>
+--FILE--
+<?php
+header('Vary: Cookie');
+echo 'foo';
+?>
+--EXPECTF--
+%s
+--EXPECTHEADERS--
+Vary: Cookie
+Content-Encoding: gzip
+Vary: Accept-Encoding
diff --git a/ext/zlib/tests/bug55544-win.phpt b/ext/zlib/tests/bug55544-win.phpt
new file mode 100644
index 0000000..03fd6b1
--- /dev/null
+++ b/ext/zlib/tests/bug55544-win.phpt
Binary files differ
diff --git a/ext/zlib/tests/bug55544.phpt b/ext/zlib/tests/bug55544.phpt
new file mode 100644
index 0000000..a0d22f4
--- /dev/null
+++ b/ext/zlib/tests/bug55544.phpt
Binary files differ
diff --git a/ext/zlib/tests/bug60761.phpt b/ext/zlib/tests/bug60761.phpt
new file mode 100644
index 0000000..1e9fe69
--- /dev/null
+++ b/ext/zlib/tests/bug60761.phpt
@@ -0,0 +1,54 @@
+--TEST--
+checks zlib compression output size is always the same
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--CGI--
+1
+--FILE--
+<?php
+
+// the INI directives from bug #60761 report
+ini_set('zlib.output_compression', '4096');
+ini_set('zlib.output_compression_level', '9');
+
+// try to duplicate the original bug by running this as a CGI
+// test using ob_start and zlib.output_compression(or ob_gzhandler)
+// so it follows more of the original code-path than just calling
+// gzcompress on CLI or CGI
+
+$lens = array();
+
+for ( $i=0 ; $i < 100 ; $i++ ) {
+
+ // can't use ob_gzhandler with zlib.output_compression
+ ob_start();//"ob_gzhandler");
+ phpinfo();
+ $html = ob_get_clean();
+
+ $len = strlen($html);
+
+ $lens[$len] = $len;
+}
+
+$lens = array_values($lens);
+
+echo "Compressed Lengths\n";
+
+// pass == only ONE length for all iterations
+// (length didn't change during run)
+//
+// hard to anticipate what 'correct' length should be since
+// return value of phpinfo() will vary between installations...
+// just check that there is only one length
+//
+var_dump($lens); // show lengths to help triage in case of failure
+
+// expected headers since its CGI
+
+?>
+--EXPECTF--
+%s
+array(1) {
+ [0]=>
+ int(%d)
+}
diff --git a/ext/zlib/tests/bug61139.phpt b/ext/zlib/tests/bug61139.phpt
new file mode 100644
index 0000000..eaca003
--- /dev/null
+++ b/ext/zlib/tests/bug61139.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Bug #61139 (gzopen leaks when specifying invalid mode)
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) {
+ die('skip - zlib extension not loaded');
+}
+?>
+--FILE--
+<?php
+
+gzopen('someFile', 'c');
+--EXPECTF--
+Warning: gzopen(): gzopen failed in %s on line %d
diff --git a/ext/zlib/tests/bug61287.phpt b/ext/zlib/tests/bug61287.phpt
new file mode 100644
index 0000000..769446a
--- /dev/null
+++ b/ext/zlib/tests/bug61287.phpt
@@ -0,0 +1,24 @@
+--TEST--
+bug #61287 - inflate needs the terminating null byte
+--SKIPIF--
+<?php extension_loaded("zlib") or die("SKIP need zlib");
+--FILE--
+<?php
+$array = array(
+ 'region_id' => 1,
+ 'discipline' => 23,
+ 'degrees' => array(),
+ 'country_id' => 27
+);
+
+$serialized = serialize($array);
+
+$deflated = gzdeflate($serialized, 9);
+$inflated = gzinflate($deflated);
+
+echo strlen($inflated),"\n";
+?>
+Done
+--EXPECT--
+92
+Done
diff --git a/ext/zlib/tests/bug61443.phpt b/ext/zlib/tests/bug61443.phpt
new file mode 100644
index 0000000..ea2fa68
--- /dev/null
+++ b/ext/zlib/tests/bug61443.phpt
@@ -0,0 +1,15 @@
+--TEST--
+bug #61443
+--SKIPIF--
+<?php
+extension_loaded("zlib") or die("skip");
+?>
+--FILE--
+<?php
+ob_start(); echo "foo\n"; ob_get_clean();
+if(!headers_sent()) ini_set('zlib.output_compression', true); echo "end\n";
+?>
+DONE
+--EXPECTF--
+end
+DONE
diff --git a/ext/zlib/tests/bug61820.phpt b/ext/zlib/tests/bug61820.phpt
new file mode 100644
index 0000000..6f33b54
--- /dev/null
+++ b/ext/zlib/tests/bug61820.phpt
@@ -0,0 +1,23 @@
+--TEST--
+bug #61820 using ob_gzhandler will complain about headers already sent when no compression
+--SKIPIF--
+<?php
+extension_loaded("zlib") or die("skip");
+?>
+--FILE--
+<?php
+ob_start('ob_gzhandler');
+
+echo "Hi there.\n";
+ob_flush();
+flush();
+
+echo "This is confusing...\n";
+ob_flush();
+flush();
+?>
+DONE
+--EXPECT--
+Hi there.
+This is confusing...
+DONE
diff --git a/ext/zlib/tests/bug_34821.phpt b/ext/zlib/tests/bug_34821.phpt
new file mode 100644
index 0000000..b378ec4
--- /dev/null
+++ b/ext/zlib/tests/bug_34821.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Bug #34821 (zlib encoders fail on widely varying binary data)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+
+// test 50 bytes to 50k
+$b = array(
+ 50,
+ 500,
+ 5000,
+ 50000,
+// 1000000, // works, but test would take too long
+);
+
+$s = '';
+$i = 0;
+
+foreach ($b as $size) {
+ do {
+ $s .= chr(rand(0,255));
+ } while (++$i < $size);
+ var_dump($s === gzinflate(gzdeflate($s)));
+ var_dump($s === gzuncompress(gzcompress($s)));
+ var_dump($s === gzinflate(substr(gzencode($s), 10, -8)));
+}
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/zlib/tests/bug_40189.phpt b/ext/zlib/tests/bug_40189.phpt
new file mode 100644
index 0000000..aedf061
--- /dev/null
+++ b/ext/zlib/tests/bug_40189.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #40189 (endless loop in zlib.inflate stream filter)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--INI--
+allow_url_fopen=1
+--FILE--
+<?php
+// this string is an excerpt of a phar archive that caused an infinite loop
+$a = "\x3\x0\x85\x46\x2f\x7c\xc2\xaa\x69\x2b\x6d\xe5\xdb\xfe\xe4\x21\x8f\x0\x97\x21\x1d\x2\x0\x0\x0\x47\x42\x4d\x42";
+var_dump(base64_encode($a));
+$gp = fopen(dirname(__FILE__) . '/test.other', 'wb');
+$fp = fopen('data://text/plain;base64,AwCFRi98wqppK23l2/7kIY8AlyEdAgAAAEdCTUI=', 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
+var_dump(stream_copy_to_stream($fp, $gp, 5));
+fclose($fp);
+fclose($gp);
+var_dump(file_get_contents(dirname(__FILE__) . '/test.other'));
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/test.other');
+?>
+--EXPECT--
+string(40) "AwCFRi98wqppK23l2/7kIY8AlyEdAgAAAEdCTUI="
+int(0)
+string(0) ""
diff --git a/ext/zlib/tests/bug_52944-darwin.phpt b/ext/zlib/tests/bug_52944-darwin.phpt
new file mode 100644
index 0000000..c25baba
--- /dev/null
+++ b/ext/zlib/tests/bug_52944-darwin.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Bug #52944 (segfault with zlib filter and corrupted data)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+<?php
+if (PHP_OS != 'Darwin') {
+ die("skip Darwin only");
+}
+--INI--
+allow_url_fopen=1
+--FILE--
+<?php
+require dirname(__FILE__) . "/bug_52944_corrupted_data.inc";
+
+$fp = fopen('data://text/plain;base64,' . $data, 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
+var_dump(fread($fp,1));
+var_dump(fread($fp,1));
+fclose($fp);
+echo "Done.\n";
+--EXPECT--
+string(1) "%"
+string(1) "C"
+Done.
diff --git a/ext/zlib/tests/bug_52944-win.phpt b/ext/zlib/tests/bug_52944-win.phpt
new file mode 100644
index 0000000..fa369f8
--- /dev/null
+++ b/ext/zlib/tests/bug_52944-win.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Bug #52944 (segfault with zlib filter and corrupted data)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die("skip windows only");
+}
+--INI--
+allow_url_fopen=1
+--FILE--
+<?php
+require dirname(__FILE__) . "/bug_52944_corrupted_data.inc";
+
+$fp = fopen('data://text/plain;base64,' . $data, 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
+var_dump(fread($fp,1));
+var_dump(fread($fp,1));
+fclose($fp);
+echo "Done.\n";
+--EXPECT--
+string(1) "%"
+string(1) "C"
+Done.
diff --git a/ext/zlib/tests/bug_52944.phpt b/ext/zlib/tests/bug_52944.phpt
new file mode 100644
index 0000000..ed4af3e
--- /dev/null
+++ b/ext/zlib/tests/bug_52944.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #52944 (segfault with zlib filter and corrupted data)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die("skip not for windows");
+}
+if (PHP_OS == 'Darwin') {
+ die("skip not for Darwin");
+}
+--INI--
+allow_url_fopen=1
+--FILE--
+<?php
+require dirname(__FILE__) . "/bug_52944_corrupted_data.inc";
+
+$fp = fopen('data://text/plain;base64,' . $data, 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
+var_dump(fread($fp,1));
+var_dump(fread($fp,1));
+fclose($fp);
+echo "Done.\n";
+--EXPECT--
+string(0) ""
+string(0) ""
+Done.
diff --git a/ext/zlib/tests/bug_52944_corrupted_data.inc b/ext/zlib/tests/bug_52944_corrupted_data.inc
new file mode 100644
index 0000000..ed46a36
--- /dev/null
+++ b/ext/zlib/tests/bug_52944_corrupted_data.inc
@@ -0,0 +1,142 @@
+<?php
+
+// corrupted data
+$data =
+'U3XuBFLaJfQAWt4cqi8u8ugXxyDcPTZy8VicbJr50gGTEh0dmo+d8O4uBCTuAf3dHbbDYTieluscWXkKlavfKdMkZZRP3GpTApbb'.
+'mQONJCgdbpPHat6iGOoq34vIGCLKFuD8qiA4ti5AL7bArvDtd7i+5tvn49j1L3bwroIsk1iPS5leATIwp1iwk+VdPLzu7tsexYBf'.
+'giLx7WtQI779GtQIKD1QI4AT1Ihvf0I1Iu1u1Ca+7Vs3TtfqiCXvrm99EuJy/ix5z1VD8atW9sUyvmu/pQn8KU5lZvHUqC5xzgow'.
+'0e8m/e5n5fLH2EPhBn4CA3n0p02/E/hVlAgxNIczOk7H7shAHSyUQ7PIwicPE/xNw7Nq4F+aHj2CowlZQKvhr2+fGIhA1QsSG6SD'.
+'y3MBWfRsWxpYq08oqfievkq2Du7uwO99DGhG4GQrIODp67QfRFEFnrUQWD1qV2R44JVHoEjwt5c6ASus4MdOAtA+2OZAHLLOA9O6'.
+'4kgGY4wOggODnQMWrk6fnTn4s4E/GG/QqEPiOiY+PWvij9MDz+0qM8WlyB6rGiGdVcVbChvQJhcjos7ShfrFxU017nBgsMHx2OON'.
+'NV7mx3AovW/veYYnlUfNlF1TNysBvNPrs5V6ClWzREIaxqSGPIK+EoQEeqBvCarbQHOQnolOl/jMrmXPMBWbIDRkzJPVo3kCD3Us'.
+'NRXjK+Ad8/fMLPiqY7+CulD4Vc/pga9nIEdhGDsx1qvT4Aw9rpW6rGtv5tqvcnMLWCNgtbu7BZ25GYiGMwiStZFNs0jY+uxVFrcG'.
+'rOVt+PaYWLhRRxt3rOCm2E/BUUA75CBa7wmWkSkXFyV7bsA/9NU5TPSC8jU9p/fSqS0u9l44323oNb1h6KfYl1mvAYIzNUX0Csfp'.
+'pozkYa12FecgDSsD86KHnATUwz8uzu3jbL5Bkb9UyUtMjL30feyC0oVBYY/DcR8DYdAnbI1FcItMFuAcIkNLx7498TGqFlN49v/K'.
+'5TdaEbZPfKhWMwvZw5SKGjMvAGm6xBrEIRtYsmfRcY0NfA5ogzyuzS2nO9sCMcVkMlxTpc03vuJcSkv9T4aZkYktzv5j3FUIf9Eu'.
+'EVuPX9ZM2dBAEEEAmEzVXRcbdmMfGoEF0hn+ufCvjZoGXMbSLKGXRkIhYEcJFHzrGphvw7M/YAd1MT/q4b1weBHE7+N+ge1EyDGK'.
+'vT/q0GzHs65w1UpMcFyhKRUsLtZfOj1gG3MMrfijvnyV7gJ6DOJTfsQwogzOuESkGzr2vt7AB5ltDDDgs1YBLCP2Hs4ep/INGvDn'.
+'0gS4x7TeREJvQoEvnXoNF2AxzeJZadBG9nsfE1DhTWy/BU0CvZ/t/8VxK1No7y8OsiarJz7+Z4eP7zN0XqDFE2fBdgcLzaFdGau4'.
+'eCY+NT0bWZiQ9RJ8xXipdAO0oplw23O6CXo1DvAcC7C0VnHjT9+dnveSDURCDL+J058ivgw1MKpyUank1fTE7eD+MYNOtKepW3EM'.
+'5BaeogscRezzQwX74AjxOVQW7QYa4BPofdJVOrFAYE2dq42rbINe19qxXjuXQquNl2liaVckfFge4ywTvwxcfNuyttEveIsC5Efh'.
+'t/0A5I1okwDIHgrUs3fN2x3Q79uewcOW4/dgcJII2THNt84OUqH5dlnqMzEPzLrjLQi4S+MtVgp6vWcf+ZBE33o8admzR8jNW06P'.
+'QldnMQigV9BkjL7s2W0fRg+kbGLKAf78yTVnjHqLJv5Qjv0IeEDy4yPGq0JBW+BDvsVZShTCaCWReUxyexvGUy8LRxw72zipLkfM'.
+'a5oI2gU7/g1j8VDFlbFspQbEOJs7RdSJJDjP95E1IHKcjuHLG4xcDeh/dWXyLkXf/JFL2QJcW2nE5NXi4hT+b7e6jjOGiqHNMbWT'.
+'sLVBvw1MQLgf8dt69bepfRWCHfyDIx4Z+RYGUv6AqwxbGGD5A8YzzGY9+71nbKlzi0glZwx/ABx/NvCnUYMEyJXuvXns4PsG/jQ6'.
+'9kcfPq8j/DqmrZ9xXXoYSLidm1i1f/LA7BI807Pf4oZPYI19F9WRQRAtZJMeRRzCn8DnwMM9PzepeCNEb883OvT9HP0ovLO8UkY9'.
+'/oSSaM+n4dt20Kigx0lBgiPHgQFn4nAVc8ufSMdg4i0Z5mg0oDjD7s0saDFcEhehwEJntB2onT2hGTAXAx8MKgAVNU21E8wQNYXQ'.
+'NFf40yNVQga+Z0+xrAmk7oMUQWOfM/2ZTX758olZiaMm33pQ/X1BtvOrMAnHeJiBSheFXMKD94DNU2mkmsvE3AGrJtVcB2n/4inK'.
+'jwAZCUviQzNQgOMJojl7IF8e6YyJidrAa1HrParr/hwJifakm3TB5m8GqSGxuFhz2Nv4I4tpcyMhr4FeaN2ikWvSsZuGlgZCVWHF'.
+'Np2AKxTgEbXkY+6FyRivfDWrEnEbI0h5C9WhRdKUIws1Ah6PXb/LjqrO8bUMac6wX7iXoKV/qlgtU/vKMP8GXcQaGMxdF4PtMdNP'.
+'ZfKg8U56sg92RdJk2/hHYYCN5zp4Y3bwxvRIDt4rezRJujhIQWXMspk1tCIWF4Fj37holt/deS/w2ZSTfD2cxMJZPbDZ0OYnSf04'.
+'AG019g+HdEw8gKmvDnh0/LSRPjWAIn4zfc2aeSUXcBYeU1jd2I1B897dKS8OKHsMHdJLqeNoVE7kY6f05tQBMfvYtSMfCsHh2TKu'.
+'LJozmKY8Pt2g/m3wGcJKGzaKCYCjQaYqLY9ja5xckLecwnjndoKrMLh2ChaskC6FQQLdYmK3k6T6hmzudB5gliE9wbMKq0ZO2+Kd'.
+'frgGaU2bFYOwh4YbGc/Zhj9Itfsuumm46+8WuYgSemdNDMUOrLF9bIiF1SvIcfVibPsEfwXwEgRSrs4IkLhpCoDTFzjumlOAIgv7'.
+'dHqWGtnCI+BW4UFq1KaFKnGAPM8tcjzFDns13W1tFBMMjlEFXCANwEPGsKQoHiwupo+2BNgoJzXw8Jci0Ug780lYtzhDwyI4bF6x'.
+'tqUz//T3J/sNHcfVGwcG5Bv26+FhQ7/TQV2+UfYjXUmH+PYKvF9nYOAfXIFs05MF0GZuD+I1bxzCPYYAjX94gfYEikCDHljmHIQW'.
+'UdBAG97qgZKGn3X8eYo/z/DnOf58iz/fnZmpI6Hv5tHsjoPB/VhMZvm0zJxnI7sKbVamF/wDJ7XXkHRLpV/PHnqUZUHNI1FjPSox'.
+'M2fsNKtw7xDv3pBTh3Jpx8SUjDoe7Ssr/t9s7tgDz8hKkEz5kxsXB26mjTbLQ5gd0ryBQfK6DbLuACweipYkhxgdULB45bjEIYlj'.
+'hFzVsQOI9LI/eo5Cvzx90cFAgZLOlXo0DtD6ybmilDPD+Gr6DgT5PLw4dFw+wKZQgkwvoxcfLGV8/5ybY+ZeR4R9OdUvJqZS+MKc'.
+'s5i2khnoq5qlU1GEomn7cvac2y5zlAvJ5ekoBXEmmg4vFCRqJWfSDU8FLZagAgvcApwcX4zNnW+3KWE2YAQKUg1bPxdm05UZpCod'.
+'QOJfTouMHbo2uDhDcozKx1ymCZKK+RG2g1QRLvx2xHWCOiqI77EHF3INCaEsyzUz/VZsDo99btQVL3dOHTSHKdSbBiP8BunIxD/Q'.
+'kVOlT56ZzWmO6pBwBb6UZL5nVh1s0o0rPqys8GkNel/5BI5a7+5OBVgHLswDjCWAKA3QjzMQmuDJdZ4xFcc9XYlZf0GhqxmZKhXj'.
+'oLpb2QyUXsI4reNzqEBAwoCl1JXT28ixWewzk2fHsDUVeVTikTHNoQn+mMMZ1hXzRpybchWrwo89E5V7YBNqMbVKXjKa6zlzsufk'.
+'3oVshy4QS3Y9MPPSWuvCHpWGY1C0GsnGl0s+DtMkVYZBwZokYHiw02MjvySnMDkpMz/PzY/0ifyikqkgDvhBfOcL9CYY5bY/jvvi'.
+'0e1jIum7gPac24Oohaeixwlae4FNHGYihuxDmm5vHR6cHB3une9vHv+I6Kpgjt/uvj65F2Jzj7/nJomR+3jKD6fL8tO4vMaEMSSt'.
+'qrMG7I40BA458LMgpdHs7Nht3v3l2z5ZEqYieUvZsMg270hz7W51oW03NT86wygOKgqXRQeupQr6efBYaiBLDapLDYqlHoHOLpfY'.
+'qSwxB0tklaW15xDWlV1D20regqPt5Dtm5Dke7kiQcFviiCUS7AXYS7cA2w+BHXaH7agAmLjOQgbZqYZUqpmk1dxKpxmK9WQGSt0H'.
+'tjq2g344KEC+ySAZGy7LRpNxAezay+C2g3Hgj2kvUAFqoja5MwdSacnEzeM8wUWYAs5xJc4CpIJznOLcA4HSfxO2K+iz7YrmdOaB'.
+'KRi38xiPg/gqiPcL00gA5qRdfRQMonEwH7CeQ1iCXiiAr9E5dNU8uy2bgflDPygWVwCEMo/p9PojsEkKROm6WR8f8ynS1cxwojAD'.
+'jRQ2cAtQu3n2J8DNod+NioAjtzyoUCoWbckOnmzmqVBbfJpZGTAoAO62yjDtAsw+nXxWhusU4A4OyzDdAswxnY5WhgsLcCdBXFFi'.
+'zwOBkGtnVf0vvIyHN30/mgzHlVNpbyXQT7yZsAJIHB+AgBetQjGvMKaPji3BZ4IZFGF+FFXpFz+8UVjqSMR0HIrT5ApW8FTg2PQr'.
+'WzH1ZIgLNqVkSKexLqj0RCSMcioojOCFcTzVeEOD2wkEAs3RijgN/f3mSv15vfb06fOVNfCAFfDC1BXYlzONN8hBk/Dy861WFgiz'.
+'FTu4UpY7BrK5NYLExKnrzT8sbLXEUduODm2ntdo0ydwaoRviC0h6wcXqqjsHP0XD4LDdBhLTgfxi/+BjB6wzgabNaPCkCblpNb/L'.
+'TsD1Ujg2IA2xB/Gxo97KwLDXeJxC7rDERTxU6g8L+fMa9UVcRTdKhzZulFIaImUU3gR9SjGZSNdxCO3VX4SDjoYrmEvixGc8xnIM'.
+'OmQV/myETn396fPaYsepLd44a/oy1HIrhuroi7hsL1bTAZsMLaI1/ewLhyylRig7BACCp2sA/vMR4VrSvChuAeMt1Za061Bf1lt4'.
+'xn19SesG8IItxrfVlzrWHSh57Cyl9ZYnVcd2iLVONibfrj99Wlsc1RaHSwU+gazbGSuF2ymnhHhiG/FKmmiGx8vO0qJfxxPt+bm1'.
+'9FtJ/ocFaPR1oWuXFrtLy7l+xZJOHKiCJKfYO/AteCBvnSpiZgB/WDCMcNcJT9IjZZdWl0xgMgwBMRDtSe5w9nDXNBsiBwcvCDYP'.
+'Tx474dsSLJOgvSS7tqqWZkqqOIN7y3QXDAefl3TZ33pN14gWjl7XNaYBPa6+pPPxxTWEssfwnjy3NTVS+fQNEPbR7aPVJ397sLm/'.
+'g+79uzgYgL6xewnen4LX8y39ccRp50nXBfqdAxmXTDx3lm/aePRodRVd2+NBkr6TPIvpvhdHWyIl8GyJvmU4z9n6A1TsJSriFYEe'.
+'JV1QzJTyIRzKq0i5gEczU+JhJLJq8hrcaoz0NUMploYeyf80BMphPoc+HITjuQj/wBcYprUYdUHmnUOX4iWyg9F4KgjyCLjiG0Mn'.
+'lAwjIlZNnI42sFtGfRc4YPX072or35+tdiy8GEEex//Y0epreM/K43uRCCbkqs2rVu56xQ4OHfUi5KUYJWnzXgx4g5+x9Pk///rv'.
+'Pv+3z//l8z/8+u9+/ftf/8Pnf9A+/wsk/QWS/vHzP//695//n8//7dd//+t/+PXvNUj6LwD7f37+i4apn/9vzPT5L3iJKfSxpNGj'.
+'XIAtd3OJwHGAK3Z0h6mat9RfeB+KobfChDSJbvHtsxlwG1p+jqd6S9glunATWm8pkAyOCu2H48MDQ1/FbJgLhsdIt7ja8N9t+vRo'.
+'KRkkshqNuqUpX9ROW2rIKudSRVdaSq5eAmOkgCketpYaWk40p19nVnbdQnZHKh63mnGGXqKnnhvQFQRlvtnMk1VC434eKMBGc0PS'.
+'4q/nv3sZMC0vz0PiKhNZoeiCbsh4JJuN19AMEj4nNt/gL6ov1U6prag/ixClmCIeXVRaf+G91JdFzZb1F6veS9ytlGsBISD2RE5C'.
+'ZquEqJACxfboSg+WPksKkUGR0uhRlYrEC0QkqMw+E+RWeG0mcK+uziGlvHj3OBoEJ9AF+THMglcIXxvUwygGnXjuTabn3ni+lhi5'.
+'U1x4ovt++cphHs5hykdYxjt3ihJfliQ0Efym/5dKiW8TSs7duSWibvv5o1JglBm5go8kknDYRjTAKrdLYPbCmP35I85OLq/VQMD3'.
+'g/aYk/BpNje/2vklGSmyfZNdt+NFrem8upMeqqrfEoxpUEHTJbpiZskDBrhYMudUSOUkZctDnrj4T8MfSIHfNCQ5r9Yjr0dVo2nw'.
+'aOTAe0pPpJS2oq3Xak0BgXQCwkMbmE9NNgQNc3XNXFl7/gzhkHuQBMIkSOnPxhHK3cwa4jSQt9oSIYLeKKEmvixbGmwEqV0Lv1mn'.
+'Uk2ZFuUKZR06D28GMVNIV7BfwuRdOCTqzUPDHVVZh6wP77dfcoBzjQ++SwrZiyuFOKX4wtubgeJgHNpBu43n2OijST8BZ1HHy3HH'.
+'4ComjXVtZmnPcMsFtvkR3oZId/6xAau939V2KG+i1e1v7bX5NyF/r22+P3l7eHRsj28gUfg2fMPuJOSQUjzQ/OFrkQ34Wdnb3do5'.
+'ON5BZJxDXpZswE/ua3p9cnaJoigc+C2xszt+V9/vrorGrOavKWTyJHd3hjqB0JLpzq04d6mhExF0K3GvguzyhY7V5SgRHCptvETn'.
+'RVfefNWmEyzaRve0ffbYceiGQZy5wuUoPfBtvHfB7QQ2eJUAYXUwQjYZT/vBKb5TBIEFuhOg/roCccBwCfPKNqksEAA4ZZiV1bY6'.
+'vMbtOPo46uBh+3iActsOE0NvAJO2giEGSOPI0Rs6cm168HVnZoEJ98pNgn44LNaftmRa7WZyHdK5TxhYcesDrI7rSQ3cJchXXlHa'.
+'AAqCojHZfqZ+8KLxOBrgh7pIlpemhg7iXO2mNzXIguqyIBQWeqOdLwmYaQzjC5PzJRG7Y3qxoDYdwgkFkeQSjb+9abStaSMEmvKK'.
+'74cY9XCsUJbo2hYLXzBKkaL2JFwRbLdyzTkwVFyqnxR4RieROrdUZKNtw8gK4g8kOcmOtrjR8stbFrj8SW+D7YktIa4Qb3SMLJZo'.
+'LL1ohVcg81w8PauiOhrxp6O3o+F4Be8obNRrtb9peq5/0aGNXQ0KEeKaNtlhbuA+lObAjTvhsFFrjsCUAwe9UdNfvliF0tBplkeL'.
+'yxbyUXZUw1GUhLTvzHRwKyNYSL6OgdSkBeTHhg42Nd16rM/weLv5HzkWWR6ETCXQEibNoiQH7oExwmOhdqEWoVXHTUW4W5Y2ic34'.
+'YiqRi/inKltXZOvKbMW6lhpmQQ0aoYUYG13rEx2NIKE+rdDECHRRqqDmN48Q1RhRDdrKJWcbMHooT9C0/n35UXrSH0LgwHa6Z6dN'.
+'EoXWnETDMxkAgx/lQNfp3t3dzujODxiekCpBLnD9fjIMxw7Jr/fwZPSI3JgIY/tlDbLjYfvi/Ul7mZ4wfFu9AcodhgMYgeQ8NJSt'.
+'lKFFRbAUlftaL4DHJIy+cdEwehu9BolR5tFODlJsrAU4vn9dmmUYBUntKcTpXeJueXyInBabseI43Ei4zjS4dDx2i2b1RFEjKIpv'.
+'ANfxCKcR0gNN+Rkd4cdy2byNMBiYXaQ0caMrXClHJjW66EmlrzM+2xXIfzNGN+F2ZmU2rRBxP4XB9UZVIrroeNcXyJjWMdbc4Bsc'.
+'kBYNPvtzEiOH0EfeNUfFY2VTf45TuC1cWfyseoBp+ox3c/8b1DZfnaoKK+2RtZVKmjadD9Tt04PTGPRzxmmLi5iyuBins6D6fvRJ'.
+'py1/uVRxKaP4wGj6lNWI7QGtPqzSlO5qCFxkPC4lLi4+LogrRMISCz4afVuKlceptAVEWXImhAFVih4lzh0InzvWyHekLlcR5+0l'.
+'HsOAheABymIw4olaVsfKb18UtGmpHqUcEeoIqAQ41cWg0M8wnutBmBHrgSo4ayQ6l/o+hbiPXyVQNdeiYKVrN0aj/pS5DnQhMShd'.
+'+DTDACDlMicgjDyqH22LxUX8BSN2iJfG+GC3OQ6fTbmBHxp8AgcKcAw5CZy20FPVeR/n8hqh3ZrENOuwkT028JRxs9mFkda+Qc9w'.
+'o9YQvdN1nHTn/0a3QQDJKAhayWn37O5OebfPxeATyh3cALffR0MB+KkF+uV1qg3QKOOamuVva/xtrerbOn+DP0L2nqLVB7zVtXpn'.
+'M6jMMBUV56g8G5SET9Y5Gqv8jk/W+bkQkJTEz9a57HVOlW/WudLR/ElJsAQm5auSYLFCVXUhaELlMJTU8zjtnG2oL0Q/Zp/bQTDu'.
+'Rq1GxxL3GjfaqEattAO7liQ2GKEmqSdQxkiBwpbhlBGBbkBf9TXPcfJ4B2PVSPrR9d0wigdu/67tJmNz1bTH4KbkcpuZoUDCleg/'.
+'ZwjQUMwpT2q0Cu1nyC12N9BlsagT/82ahKX/Tk0i14maJNjwv1+jisMq9zUNH1RTQQR4UdQP3KFeJIng/d+JKtLnRLqkQzE3ckK0'.
+'IqW9mQ0XW7X6VPSnt4CnAb4pZT0Tmj8d57hpzlIH919ZGKMql6cqCixSlRjzijSkhmw/VjtgcbFtflFdBGOV6qKUTapnZg2ieNRV'.
+'ZwG6oKx7VTLqATp3BS0b4AoQhjPAzq54oa15NqIKzOEhS3gDOd+FbXO24qAZbdPq8tWBZIaf6nSLwAivq/sbfAALIDM+enimCgXy'.
+'SzPrwiTnwjklI+k1usjQS9ZF3rOA5xR/5v9uoaEFZbDr+4rMoXzaHthK+ZQjtJbySSfRSCb44i/48jiTwslK/clcYMU7DkZ4jFfm'.
+'5fBskI0WW+A42Ch8jsdOAKlBPxjglRfwNGw5nkF/zRl/EBNReChY3PEMffmU71Nxb4z0YpXUhoSsYB8+YQwgIFZEMSRflrMXtDOt'.
+'tWfPTAv+fjG+eoavruKr/0Z8axm+NRXfWg6f3Jts6eayburY3amN5hnisBg6v7IDNkheCNMldJjK9rrjrGfBd2QOOqtA1F+MX6BO'.
+'p7j2fFu31mcmvFpflPSLuQqGTYB7fCXi07SxbUkYJWWtlLJOKWeVtVk2Nhq/2Pxobpi//E2uFl//dW51eWhhhc0na/azZ1Yuda0y'.
+'dV2kyqr/0Th1V9qbK6+JQmsz86H3B0n3vES65yXSPTcryzfnvzxQ7HJ12cvVFVgu1gI60P3FqFma+H8FyTXXVubm0mvDT1uQHA4A'.
+'MH9D9Fl2oA0IC+mSdJqt6LaDN5hP4q3jY/pAYwDcRfAI8Y9SiI4ewRCcEjoHoovCrTVFm4EP1Ws7JcE545N7uk5XzC4dQO7sABFU'.
+'lhzbd+teTtzGaQ2HK/47s9xPkzhonK49VdK8IOxQGrzjvzWQQV4fzWLICf/Dt0nAL5whjq6HjdP682fW0zX4/5nlT91hrpyWG19k'.
+'uerr33OShIOELLETB1PEBkn8L00OGLhGlcC0i657EQLsdwD33Tp8+ZbT8Y6j4RiaioiV8iK8r1Ug+u4ZwltPRZYIeoCaDVWuP01L'.
+'iGIfzExA9GzdegYNqj3l9DhoSewCMnH7A/AiTtfWoSIAWl9b4w9XIVgdY4B++h1dvFBHPeR3k9Dl0gQVO1G/xQlr9WeINGvw2nf4'.
+'Dpo27ESN02+fUZMgRTSfem+9htU+s/qoF5nU9W/XAddz/CbSmd5ra0+znqF0UVT9KXxY/w4QPc0+QF9AnS3xT6SPwuGFoNV3a1b9'.
+'+3WRPg0wSlk0A/+tEaZBILkBapJ2jtL4gRtHSDxqKgIN3aupYJa1784s6jj+LKiR66/nhFip1Pdr0FVQqdEkHvUDiZdQpd2RJVFn'.
+'cm0ATRL2r4IYAL5fs8S/MwuG2DhQ2oWVLjYW8irjOA/M07VJOOzYPTDmhigOxDu9NtMJOplu3baCdkOHl+BwMv7TBLf/E2huWQjs'.
+'0oKRSZlPU+yA5EwBnFmIcHeI+O5D1APFv+qE5pPucpvziErcl2klzWV0V9ZMmXN3eF9eEISUaXXNfFHPyl9de9KlwlPckGIYKytd'.
+'gX2lrhSwNfFC/8vak2vRl+RDwboaQnGUt55v1nwE97ZLbRk3rLvirHEJKuGAavH4S9tV7Kv7c64Um/aku1Iv9dkcHA80rqLj0vY9'.
+'ybPGnybh8CtaWGjjw3kLTSz34HwkDzbynl4s9eRxcUG33B1kg/tRAoWGT9gif7cLhZvLPaXRDyESeGDwl/Go7X64QtiitE4CzRPA'.
+'mR96Ozej6B48QH/woTbaDVGvUXRtgEytYa9it5hK074AVQiolnuAzFhR0K0APqxYsW/nIkQPj3y7dNmNU7LmQymz+QxQbIpoiMoL'.
+'xfqh5MpxxFYY+w8NUO7Ky3hs1FfkMFDJjxLoATSSHySSdDgUBNk8NNVEULhDYO6mNVOpkC+bR0e+m3bwZPu8DMWFzoE8Sr7n1O1v'.
+'a/Vn3zX5Op9ak6fqB7SMXOpEI1x1+qbj1JWeHPC5/3g6e/9JzV6nzn5BVXM9vEQEJy4G8hDG1afZeje+GqK73+2a/ICK1RisdtNF'.
+'W2hZkSPCFaiBmQ1FI3zSX+mB6sqQrV7kmf9/fDrkqIA8Hz5IgeVBfsD+KxABGNcBvptDBgPo8KRuPzN/N2JgTdSRUrOfPflrGGQe'.
+'cb8QBXT0M5XKr9CTKwz0i3SoAw3TnUoYxSHILStxQcq4hyoOisNbJ7orocrFfy12kk89VteyhOWyYP9txQhR1suLsguUU10qDyjo'.
+'GMAMa89MUzZO6YKLnI6vAMeaqiL+FTjp/v3aeiW11CUFKQ8y/krXqhGwSt/5GKWgNl8Y9dU1+9tnpmoHfWs/e772DM0SREe8TAxv'.
+'rM2FxZZi8wQANK+GD4Xs6fc5CNbstRyG79cVHPOyPC/k+e6pyIUhdxkX3EuM7gvUWUXPyFZ7BnM8WRNUpoGS9vXcboEMK6GapScy'.
+'4qK0wQGSvHltdbULPjH5xQ18z0Jb6GQ/uRyQAuU2dKpT+5eTYBIUA2MCx+UVdKvlqJPpdMEzzomXptejkeuH46l+JoRmVgURxGgE'.
+'lmeL1VFaF7+7E+uGTT52PftKE+zw+Y9t+O/773UR6RNwAFaxbDwzKC3LvcKCWnhKkQjO4ly3hTY0+Cxmq4Cs4c+4Om3ntvipQ8v6'.
+'YMeJtcHbti0a7dRmQRpJ0bZuiaR8Zkq2Auylq/kWd34ja7Bwyv0IN3+Pi2uNSpGBCESeZU0W8ajcagFNdKV7JPhCR3uQhIG4Y5qW'.
+'EZSNLKE3wQ2c7bCPgZakYbw0MsC8zZ7nLSHarYB5SIZOFBh1XgjzOw5//v9XKLNoVJpjO8DdHkkDXx7JLvOhv+xeIsKe54xcER3+'.
+'deO2JcetGDLlUdi6dxS2lVFIIel3d8/Sc1zSwJTscXWt4VZEmKyuNUWQshwqKyszuu4oF6eMq2Q0pKXwsGq4hCcGbisdUrfie6MO'.
+'8tkqDhuz2XbaK2tpdJcPhpv/ot30Mfa6AkmtEsmXFjbLN+xL8auhVS25m+Brh5oMlv29G1WI+/raOrUEL+rtGz3fzkwyYHcqb6qQ'.
+'ONp5c76/c8w3/eI6He2zEKl4uK++2e9r7TDotxItBhxxGLR0BWQNQN65SXIdxQDRioZLY43C4FSgdQTqo77VXJyRJqmQ8LEcGki+'.
+'QaJCPwXovagTDrUw0cLhldsPc0U+g+87AzfsF77/YeH1zs52RXNkclV7wpjbk8Ksqdiv42jYYdx/WHh3dPh6d2+nogDlC5UxlyAq'.
+'IBb0+uSd1pdNpcIsbV2ju3i1QQj8MxkUs61XZrO1owADcP0xSF7KL2v9anP7/Hhn82jrraN/jCaa72KNwIJuaa5GO2w0jtzVrsNx'.
+'F2Q5COWpNnJjdwDaME7sF178Ev+9A2WXaC9cjY4HXFrlg71xG+rSSyDqi1X3paWNI4GaqNwPRDXev9s7hHq8PjzaP9/df+Poq8lq'.
+'OOisnuPdyKvBcJV1pd0J25xh5/z4ZPPk/fGrzaPz7Z3Xm+/3Tk52fj7hfX6OtnQc9ANqazvqY1C9top7u9Vcx5s/7ZxneSjXm2Cs'.
+'4emFVbAnh4d7J7vvOIuApRZQjqSY5Wjn9VER/VHQBhp1IUMyroIvFiHhZTHlXFCx3YM3spxH1HL3Co1X2y7CnhyebO4hmxwLeAA+'.
+'icau6IiGxhk2f9j8+fzD5m5a8ew/yLAVDYdAWChBgT7eOdiuhD4G9YqcQ3szZY32j9+c7xwdaVpllp04jmIt8v0JDLzHWY7jo5/O'.
+'63MKweN/xIWFZFfEgR91huEneAH6jUCWBoIY2OeHP84p+jWRGa3UlpZM6E709qTfnyq1qM4rCNMBtTvpk+pNHucKXKvOsykHwf2F'.
+'YtPXKhGcgJgEBu9HuDqkBRnpgHYamAGYiqKUC2lF13SYNJq3eezr1dhxSasNpL12k+EvIBSkCaz2y+bJyRyKgP0KWghjo/OFPeW9'.
+'uI8eKZ0HYmoydKn1odcPNKV+rw/3tneOKvuLhnaSgR4cahI3IT+Ism8fd45z3z4GSa6L1ufzBPfOkpA7b452t2G04mEU5ziacuBH'.
+'Ad5BwvRm9AT+ZufkfG/34McidilvEokcgc7fH+1V1gXSGSdBvT3Z36uConRAmiiwIFff71dSEKzKKJ4M0goIWXrOcuLdztH5u803'.
+'Owxer2Ut2t59t4d0LQ3GLvMic9xtbaataLf1mRa1tdu12VIZwfnJuz0FQf40AC314VGApJfg2OPoPW6v4dAL3qzOx5PUzeUlTewT'.
+'hiFQKn+WVeCE5Ofbww/nr48O9/Mt0NpxNGgsVQGfHKrNHYf9fhnu/at9VXziWEDzTIHb2X938rFIP+JYaqoC+WoHOm+nAAqQeJKS'.
+'Arb5+gT6CqAeKTDY6JpKdLALzk92T1SmJcDP/8fnv3z+p8///Ot/0j7/4+f/S/v8v37+y6//y+d/+PxPGnz63z//Z+3zvwDEv3z+'.
+'r5//UUW3t31UwofoOPs/ahneYq79j/l8kGt/Who3W4d77/cPzunglxyZYJCVwd4d7f60ebKj0CgOr1x/WoY83v1zHuExKIsy2HaG'.
+'TYzAEcpP7KI50Gsq9HYlWElmoIipaMzO0e7htiqNp6MKsP0dcL+3c3wx1TjevaLZOSGAbDnAY2+q6HNSpE9VU7YO3x+cHH1UlSCg'.
+'i6e/udG7B1uHWVcD2O4QdE4F4Kv3H4/zFXQrOWd7r8Dp231VBh1+OEC7syjEtoWirADNCWcA3UutRaEXjk9guJYE7RHPA1VVEI9K'.
+'rSg7qOo/suXUVo/B4kiq6Pj6MFc+nog5D1/90SOqIc45zS20XmOwTW+S3Ae1RlBvaQ5hPtQ6QW0Jc6I/1eKHSn+uVlLzprQnvwy+'.
+'uXWye3igcjgf4FQCPNpXB3eKujy0918dwuPh+3evPqqKO44mI6hGCfTVx+1NhTUBtOVOkwqwDzs7P6pdeR0EF1Vw+8Aeb48zuEE0'.
+'HHcF4NbbzaMTAVnidDQupcVXAV+SL6T3QKmGUnKo0PeNtyJcJmYknHYV9Seyu/KVBlbND09w2LMhX0KdQqeo54GTt5PCp67OPPD1'.
+'2naefOs1Les5FbK+XyA09UgFgY929nNwozi4CqMJOO7VGZ4XEXfdfntlCl50GXbtYwF2TUNAWV0m7u7xu73Nj+cgy/ePC/0M4nyg'.
+'GM7bO3sFES37I8ABKizJzVcABuLq9S546WoW5LY40KbRBFwY8XDtDsfo7bcIA3ohibCLN6rQCcH5RSjFpLqWpD7+XLRgO23tnMvZ'.
+'BcR9H+IJq3fiESmZWBbnilDlCKPe2X5QJA==';
diff --git a/ext/zlib/tests/compress_zlib_wrapper.phpt b/ext/zlib/tests/compress_zlib_wrapper.phpt
new file mode 100644
index 0000000..4bf6c08
--- /dev/null
+++ b/ext/zlib/tests/compress_zlib_wrapper.phpt
@@ -0,0 +1,22 @@
+--TEST--
+compress.zlib:// wrapper
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) die("skip"); ?>
+--FILE--
+<?php
+chdir(dirname(__FILE__). "/../../..");
+
+$pfx = str_repeat('../', substr_count($_SERVER['PHP_SELF'], '../'));
+
+// Relative path
+$fp = fopen("compress.zlib://{$pfx}ext/xsl/tests/xslt.xsl.gz", "rb");
+fclose($fp);
+
+// Absolute path
+$fp = fopen("compress.zlib://". dirname(__FILE__). "/../../../ext/xsl/tests/xslt.xsl.gz", "rb");
+fclose($fp);
+
+echo "ok\n";
+?>
+--EXPECT--
+ok
diff --git a/ext/zlib/tests/data.inc b/ext/zlib/tests/data.inc
new file mode 100644
index 0000000..fb20f0b
--- /dev/null
+++ b/ext/zlib/tests/data.inc
@@ -0,0 +1,88 @@
+
+<?php
+$data = <<<QUOTE
+To be or not to be, that is the question;
+Whether 'tis nobler in the mind to suffer
+The Slings and Arrows of outrageous Fortune
+Or to take arms against a sea of troubles,
+And by opposing, end them. To die, to sleep;
+No more; and by a sleep to say we end
+The heart-ache and the thousand natural shocks
+That flesh is heir to 'tis a consummation
+Devoutly to be wish'd. To die, to sleep;
+To sleep, perchance to dream. Ay, there's the rub,
+For in that sleep of death what dreams may come,
+When we have shuffled off this mortal coil,
+Must give us pause. There's the respect
+That makes calamity of so long life,
+For who would bear the whips and scorns of time,
+Th'oppressor's wrong, the proud man's contumely,
+The pangs of dispriz'd love, the law's delay,
+The insolence of office, and the spurns
+That patient merit of th'unworthy takes,
+When he himself might his quietus make
+With a bare bodkin? who would fardels bear,
+To grunt and sweat under a weary life,
+But that the dread of something after death,
+The undiscovered country from whose bourn
+No traveller returns, puzzles the will,
+And makes us rather bear those ills we have
+Than fly to others that we know not of?
+Thus conscience does make cowards of us all,
+And thus the native hue of resolution
+Is sicklied o'er with the pale cast of thought,
+And enterprises of great pitch and moment
+With this regard their currents turn away,
+And lose the name of action.
+
+
+Hath not a Jew eyes? Hath not a Jew hands, organs, dimensions,
+senses, affections, passions; fed with the same food, hurt with
+the same weapons, subject to the same diseases, heal'd by
+the same means, warm'd and cool'd by the same winter and summer
+as a Christian is? If you prick us, do we not bleed? If you
+tickle us, do we not laugh? If you poison us, do we not die?
+And if you wrong us, shall we not revenge? If we are like you
+in the rest, we will resemble you in that. If a Jew wrong a
+Christian, what is his humility? Revenge. If a Christian wrong
+a Jew, what should his sufferance be by Christian example? Why,
+revenge. The villainy you teach me, I will execute, and it
+shall go hard but I will better the instruction.
+
+Is this a dagger which I see before me,
+The handle toward my hand? Come, let me clutch thee.
+I have thee not, and yet I see thee still.
+Art thou not, fatal vision, sensible
+To feeling as to sight? or art thou but
+A dagger of the mind, a false creation,
+Proceeding from the heat-oppress'd brain?
+I see thee yet, in form as palpable
+As this which now I draw.
+Thou marshall'st me the way that I was going;
+And such an instrument I was to use.
+Mine eyes are made the fools o' the other senses,
+Or else worth all the rest; I see thee still,
+And on thy blade and dudgeon gouts of blood,
+Which was not so before.
+There's no such thing:
+It is the bloody business which informs Thus to mine eyes.
+Now o'er the one halfworld Nature seems dead,
+and wicked dreams abuse The curtain'd sleep; witchcraft celebrates
+Pale Hecate's offerings, and wither'd murder,
+Alarum'd by his sentinel, the wolf,
+Whose howl's his watch, thus with his stealthy pace.
+With Tarquin's ravishing strides, towards his design
+Moves like a ghost. Thou sure and firm-set earth,
+Hear not my steps, which way they walk,
+for fear Thy very stones prate of my whereabout,
+And take the present horror from the time,
+Which now suits with it.
+Whiles I threat, he lives:
+Words to the heat of deeds too cold breath gives.
+I go, and it is done; the bell invites me.
+Hear it not, Duncan; for it is a knell
+That summons thee to heaven or to hell.
+
+QUOTE;
+
+?>
diff --git a/ext/zlib/tests/func.inc b/ext/zlib/tests/func.inc
new file mode 100644
index 0000000..0a422ca
--- /dev/null
+++ b/ext/zlib/tests/func.inc
@@ -0,0 +1,17 @@
+<?php
+
+function get_zlib_version()
+{
+ $version = NULL;
+
+ ob_start();
+ phpinfo();
+ $info = ob_get_contents();
+ ob_end_clean();
+ if (preg_match(',zlib.*Compiled Version => (\d+\.\d+\.\d+),s', $info, $match)) {
+ $version = $match[1];
+ }
+
+ return $version;
+}
+
diff --git a/ext/zlib/tests/gzclose_basic.phpt b/ext/zlib/tests/gzclose_basic.phpt
new file mode 100644
index 0000000..d61855b
--- /dev/null
+++ b/ext/zlib/tests/gzclose_basic.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Test function gzclose() by calling it with its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+// note that gzclose is an alias to fclose. parameter checking tests will be
+// the same as fclose
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+gzread($h, 20);
+var_dump(gzclose($h));
+
+//should fail.
+gzread($h, 20);
+
+$h = gzopen($f, 'r');
+gzread($h, 20);
+var_dump(fclose($h));
+
+//should fail.
+gzread($h, 20);
+
+
+?>
+===DONE===
+--EXPECTF--
+bool(true)
+
+Warning: gzread(): %d is not a valid stream resource in %s on line %d
+bool(true)
+
+Warning: gzread(): %d is not a valid stream resource in %s on line %d
+===DONE===
diff --git a/ext/zlib/tests/gzclose_error.phpt b/ext/zlib/tests/gzclose_error.phpt
new file mode 100644
index 0000000..ec4b6eb
--- /dev/null
+++ b/ext/zlib/tests/gzclose_error.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test function gzclose() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$extra_arg = 'nothing';
+
+
+
+var_dump(gzclose( $h, $extra_arg ) );
+var_dump(gzclose());
+
+gzclose($h);
+
+
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzclose() expects exactly 1 parameter, 2 given in %s on line %d
+bool(false)
+
+Warning: gzclose() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzcompress_basic1.phpt b/ext/zlib/tests/gzcompress_basic1.phpt
new file mode 100644
index 0000000..1506d0c
--- /dev/null
+++ b/ext/zlib/tests/gzcompress_basic1.phpt
@@ -0,0 +1,125 @@
+--TEST--
+Test gzcompress() function : basic functionality
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzcompress(string data [, int level, [int encoding]])
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+/*
+ * add a comment here to say what the test is supposed to do
+ */
+
+include(dirname(__FILE__) . '/data.inc');
+
+echo "*** Testing gzcompress() : basic functionality ***\n";
+
+// Initialise all required variables
+
+$smallstring = "A small string to compress\n";
+
+
+// Calling gzcompress() with all possible arguments
+
+// Compressing a big string
+for($i = -1; $i < 10; $i++) {
+ echo "-- Compression level $i --\n";
+ $output = gzcompress($data, $i);
+ var_dump(md5($output));
+ var_dump(strcmp(gzuncompress($output), $data));
+}
+
+// Compressing a smaller string
+for($i = -1; $i < 10; $i++) {
+ echo "-- Compression level $i --\n";
+ $output = gzcompress($smallstring, $i);
+ var_dump(bin2hex($output));
+ var_dump(strcmp(gzuncompress($output), $smallstring));
+}
+
+// Calling gzcompress() with mandatory arguments
+echo "\n-- Testing with no specified compression level --\n";
+var_dump( bin2hex(gzcompress($smallstring) ));
+
+?>
+===Done===
+--EXPECT--
+*** Testing gzcompress() : basic functionality ***
+-- Compression level -1 --
+string(32) "764809aef15bb34cb73ad49ecb600d99"
+int(0)
+-- Compression level 0 --
+string(32) "d0136b3fb5424142c0eb26dfec8f56fe"
+int(0)
+-- Compression level 1 --
+string(32) "c2e070f4320d1f674965eaab95b53d9c"
+int(0)
+-- Compression level 2 --
+string(32) "36922f486410d08209d0d0d21b26030e"
+int(0)
+-- Compression level 3 --
+string(32) "a441a2f5169bb303cd45b860a5a9dbf9"
+int(0)
+-- Compression level 4 --
+string(32) "d5b7451e9de2864beccc9de1fc55eb87"
+int(0)
+-- Compression level 5 --
+string(32) "32ba4a01120449ec25508cabfad41f56"
+int(0)
+-- Compression level 6 --
+string(32) "764809aef15bb34cb73ad49ecb600d99"
+int(0)
+-- Compression level 7 --
+string(32) "e083e7e8d05471fed3c2182b9cd0d9eb"
+int(0)
+-- Compression level 8 --
+string(32) "e083e7e8d05471fed3c2182b9cd0d9eb"
+int(0)
+-- Compression level 9 --
+string(32) "e083e7e8d05471fed3c2182b9cd0d9eb"
+int(0)
+-- Compression level -1 --
+string(70) "789c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+int(0)
+-- Compression level 0 --
+string(76) "7801011b00e4ff4120736d616c6c20737472696e6720746f20636f6d70726573730a87a509cb"
+int(0)
+-- Compression level 1 --
+string(70) "7801735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+int(0)
+-- Compression level 2 --
+string(70) "785e735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+int(0)
+-- Compression level 3 --
+string(70) "785e735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+int(0)
+-- Compression level 4 --
+string(70) "785e735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+int(0)
+-- Compression level 5 --
+string(70) "785e735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+int(0)
+-- Compression level 6 --
+string(70) "789c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+int(0)
+-- Compression level 7 --
+string(70) "78da735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+int(0)
+-- Compression level 8 --
+string(70) "78da735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+int(0)
+-- Compression level 9 --
+string(70) "78da735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+int(0)
+
+-- Testing with no specified compression level --
+string(70) "789c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee6020087a509cb"
+===Done===
diff --git a/ext/zlib/tests/gzcompress_error1.phpt b/ext/zlib/tests/gzcompress_error1.phpt
new file mode 100644
index 0000000..9db0a56
--- /dev/null
+++ b/ext/zlib/tests/gzcompress_error1.phpt
@@ -0,0 +1,84 @@
+--TEST--
+Test gzcompress() function : error conditions
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzcompress(string data [, int level, [int encoding]])
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+/*
+ * add a comment here to say what the test is supposed to do
+ */
+
+echo "*** Testing gzcompress() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing gzcompress() function with Zero arguments --\n";
+var_dump( gzcompress() );
+
+//Test gzcompress with one more than the expected number of arguments
+echo "\n-- Testing gzcompress() function with more than expected no. of arguments --\n";
+$data = 'string_val';
+$level = 2;
+$encoding = ZLIB_ENCODING_RAW;
+$extra_arg = 10;
+var_dump( gzcompress($data, $level, $encoding, $extra_arg) );
+
+echo "\n-- Testing with incorrect compression level --\n";
+$bad_level = 99;
+var_dump(gzcompress($data, $bad_level));
+
+echo "\n-- Testing with invalid encoding --\n";
+$data = 'string_val';
+$encoding = 99;
+var_dump(gzcompress($data, $level, $encoding));
+
+echo "\n-- Testing with incorrect parameters --\n";
+
+class Tester {
+ function Hello() {
+ echo "Hello\n";
+ }
+}
+
+$testclass = new Tester();
+var_dump(gzcompress($testclass));
+
+?>
+===Done===
+--EXPECTF--
+*** Testing gzcompress() : error conditions ***
+
+-- Testing gzcompress() function with Zero arguments --
+
+Warning: gzcompress() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing gzcompress() function with more than expected no. of arguments --
+
+Warning: gzcompress() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+
+-- Testing with incorrect compression level --
+
+Warning: gzcompress(): compression level (99) must be within -1..9 in %s on line %d
+bool(false)
+
+-- Testing with invalid encoding --
+
+Warning: gzcompress(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
+bool(false)
+
+-- Testing with incorrect parameters --
+
+Warning: gzcompress() expects parameter 1 to be string, object given in %s on line %d
+NULL
+===Done===
diff --git a/ext/zlib/tests/gzcompress_variation1.phpt b/ext/zlib/tests/gzcompress_variation1.phpt
new file mode 100644
index 0000000..7a8457c
--- /dev/null
+++ b/ext/zlib/tests/gzcompress_variation1.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test gzcompress() function : variation
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzcompress(string data [, int level, [int encoding]])
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+include(dirname(__FILE__) . '/data.inc');
+
+echo "*** Testing gzcompress() : variation ***\n";
+
+echo "\n-- Testing multiple compression --\n";
+$output = gzcompress($data);
+var_dump( md5($output));
+var_dump(md5(gzcompress($output)));
+
+?>
+===Done===
+--EXPECTF--
+*** Testing gzcompress() : variation ***
+
+-- Testing multiple compression --
+string(32) "764809aef15bb34cb73ad49ecb600d99"
+string(32) "eba942bc2061f23ea8688cc5101872a4"
+===Done===
diff --git a/ext/zlib/tests/gzdeflate_basic1.phpt b/ext/zlib/tests/gzdeflate_basic1.phpt
new file mode 100644
index 0000000..a2ae0f0
--- /dev/null
+++ b/ext/zlib/tests/gzdeflate_basic1.phpt
@@ -0,0 +1,125 @@
+--TEST--
+Test gzdeflate() function : basic functionality
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzdeflate(string data [, int level, [int encoding]])
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+/*
+ * add a comment here to say what the test is supposed to do
+ */
+
+include(dirname(__FILE__) . '/data.inc');
+
+echo "*** Testing gzdeflate() : basic functionality ***\n";
+
+// Initialise all required variables
+
+$smallstring = "A small string to compress\n";
+
+
+// Calling gzdeflate() with all possible arguments
+
+// Compressing a big string
+for($i = -1; $i < 10; $i++) {
+ echo "-- Compression level $i --\n";
+ $output = gzdeflate($data, $i);
+ var_dump(md5($output));
+ var_dump(strcmp(gzinflate($output), $data));
+}
+
+// Compressing a smaller string
+for($i = -1; $i < 10; $i++) {
+ echo "-- Compression level $i --\n";
+ $output = gzdeflate($smallstring, $i);
+ var_dump(bin2hex($output));
+ var_dump(strcmp(gzinflate($output), $smallstring));
+}
+
+// Calling gzdeflate() with just mandatory arguments
+echo "\n-- Testing with no specified compression level --\n";
+var_dump( bin2hex(gzdeflate($smallstring) ));
+
+?>
+===Done===
+--EXPECT--
+*** Testing gzdeflate() : basic functionality ***
+-- Compression level -1 --
+string(32) "078554fe65e06f6ff01eab51cfc7ae9b"
+int(0)
+-- Compression level 0 --
+string(32) "a71e54d2499aff9e48643cb1c260b60c"
+int(0)
+-- Compression level 1 --
+string(32) "05e80f4dc0d422e1f333cbed555d381f"
+int(0)
+-- Compression level 2 --
+string(32) "0fb33656e4ed0750f977df83246fce7a"
+int(0)
+-- Compression level 3 --
+string(32) "bc6e9c1dccc3e951e006315ee669ee08"
+int(0)
+-- Compression level 4 --
+string(32) "a61727d7a28c634470eb6e97a4a81b24"
+int(0)
+-- Compression level 5 --
+string(32) "a2a1a14b7542c82e8943200d093d5f27"
+int(0)
+-- Compression level 6 --
+string(32) "078554fe65e06f6ff01eab51cfc7ae9b"
+int(0)
+-- Compression level 7 --
+string(32) "078554fe65e06f6ff01eab51cfc7ae9b"
+int(0)
+-- Compression level 8 --
+string(32) "078554fe65e06f6ff01eab51cfc7ae9b"
+int(0)
+-- Compression level 9 --
+string(32) "078554fe65e06f6ff01eab51cfc7ae9b"
+int(0)
+-- Compression level -1 --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+int(0)
+-- Compression level 0 --
+string(64) "011b00e4ff4120736d616c6c20737472696e6720746f20636f6d70726573730a"
+int(0)
+-- Compression level 1 --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+int(0)
+-- Compression level 2 --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+int(0)
+-- Compression level 3 --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+int(0)
+-- Compression level 4 --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+int(0)
+-- Compression level 5 --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+int(0)
+-- Compression level 6 --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+int(0)
+-- Compression level 7 --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+int(0)
+-- Compression level 8 --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+int(0)
+-- Compression level 9 --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+int(0)
+
+-- Testing with no specified compression level --
+string(58) "735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200"
+===Done===
diff --git a/ext/zlib/tests/gzdeflate_error1.phpt b/ext/zlib/tests/gzdeflate_error1.phpt
new file mode 100644
index 0000000..8abd5be
--- /dev/null
+++ b/ext/zlib/tests/gzdeflate_error1.phpt
@@ -0,0 +1,86 @@
+--TEST--
+Test gzdeflate() function : error conditions
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzdeflate(string data [, int level, [int encoding]])
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+/*
+ * add a comment here to say what the test is supposed to do
+ */
+
+echo "*** Testing gzdeflate() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing gzdeflate() function with Zero arguments --\n";
+var_dump( gzdeflate() );
+
+//Test gzdeflate with one more than the expected number of arguments
+echo "\n-- Testing gzdeflate() function with more than expected no. of arguments --\n";
+$data = 'string_val';
+$level = 2;
+$encoding = ZLIB_ENCODING_RAW;
+$extra_arg = 10;
+var_dump( gzdeflate($data, $level, $encoding, $extra_arg) );
+
+echo "\n-- Testing with incorrect compression level --\n";
+$bad_level = 99;
+var_dump(gzdeflate($data, $bad_level));
+
+echo "\n-- Testing with incorrect encoding --\n";
+$bad_encoding = 99;
+var_dump(gzdeflate($data, $level, $bad_encoding));
+
+class Tester {
+ function Hello() {
+ echo "Hello\n";
+ }
+}
+
+echo "\n-- Testing with incorrect parameters --\n";
+$testclass = new Tester();
+var_dump(gzdeflate($testclass));
+var_dump(gzdeflate($data, $testclass));
+
+?>
+===Done===
+--EXPECTF--
+*** Testing gzdeflate() : error conditions ***
+
+-- Testing gzdeflate() function with Zero arguments --
+
+Warning: gzdeflate() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing gzdeflate() function with more than expected no. of arguments --
+
+Warning: gzdeflate() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+
+-- Testing with incorrect compression level --
+
+Warning: gzdeflate(): compression level (99) must be within -1..9 in %s on line %d
+bool(false)
+
+-- Testing with incorrect encoding --
+
+Warning: gzdeflate(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
+bool(false)
+
+-- Testing with incorrect parameters --
+
+Warning: gzdeflate() expects parameter 1 to be string, object given in %s on line %d
+NULL
+
+Warning: gzdeflate() expects parameter 2 to be long, object given in %s on line %d
+NULL
+===Done===
diff --git a/ext/zlib/tests/gzdeflate_variation1.phpt b/ext/zlib/tests/gzdeflate_variation1.phpt
new file mode 100644
index 0000000..75eb16e
--- /dev/null
+++ b/ext/zlib/tests/gzdeflate_variation1.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Test gzdeflate() function : variation
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzdeflate(string data [, int level])
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+include(dirname(__FILE__) . '/data.inc');
+
+echo "*** Testing gzdeflate() : variation ***\n";
+
+
+
+echo "\n-- Testing multiple compression --\n";
+$output = gzdeflate($data);
+var_dump( md5($output));
+var_dump(md5(gzdeflate($output)));
+
+?>
+===Done===
+--EXPECT--
+*** Testing gzdeflate() : variation ***
+
+-- Testing multiple compression --
+string(32) "078554fe65e06f6ff01eab51cfc7ae9b"
+string(32) "86b9f895ef1377da5269ec3cb2729f71"
+===Done===
diff --git a/ext/zlib/tests/gzencode_basic1.phpt b/ext/zlib/tests/gzencode_basic1.phpt
new file mode 100644
index 0000000..3c0ec55
--- /dev/null
+++ b/ext/zlib/tests/gzencode_basic1.phpt
@@ -0,0 +1,115 @@
+--TEST--
+Test gzencode() function : basic functionality
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzencode ( string $data [, int $level [, int $encoding_mode ]] )
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+/*
+ * Test basic function of gzencode
+ */
+
+include(dirname(__FILE__) . '/data.inc');
+
+echo "*** Testing gzencode() : basic functionality ***\n";
+
+// Initialise all required variables
+
+$smallstring = "A small string to compress\n";
+
+
+// Calling gzencode() with various compression levels
+
+// Compressing a big string
+for($i = -1; $i < 10; $i++) {
+ echo "-- Compression level $i --\n";
+ $output = gzencode($data, $i);
+
+ // Clear OS byte before encode
+ $output[9] = "\x00";
+
+ var_dump(md5($output));
+}
+
+// Compressing a smaller string
+for($i = -1; $i < 10; $i++) {
+ echo "-- Compression level $i --\n";
+ $output = gzencode($smallstring, $i);
+
+ // Clear OS byte before encode
+ $output[9] = "\x00";
+
+ var_dump(md5($output));
+}
+
+// Calling gzencode() with mandatory arguments
+echo "\n-- Testing with no specified compression level --\n";
+var_dump(bin2hex(gzencode($smallstring)));
+
+echo "\n-- Testing gzencode with mode specified --\n";
+var_dump(bin2hex(gzencode($smallstring, -1, FORCE_GZIP)));
+
+?>
+===Done===
+--EXPECTF--
+*** Testing gzencode() : basic functionality ***
+-- Compression level -1 --
+string(32) "d9ede02415ce91d21e5a94274e2b9c42"
+-- Compression level 0 --
+string(32) "bbf32d5508e5f1f4e6d42790489dae15"
+-- Compression level 1 --
+string(32) "0bfaaa7a5a57f8fb533074fca6c85eeb"
+-- Compression level 2 --
+string(32) "7ddbfed63a76c42808722b66f1c133fc"
+-- Compression level 3 --
+string(32) "ca2b85d194dfa2a4e8a162b646c99265"
+-- Compression level 4 --
+string(32) "cfe28033eaf260bc33ddc04b53d3ba39"
+-- Compression level 5 --
+string(32) "ae357fada2b515422f8bea0aa3bcc48f"
+-- Compression level 6 --
+string(32) "d9ede02415ce91d21e5a94274e2b9c42"
+-- Compression level 7 --
+string(32) "d9ede02415ce91d21e5a94274e2b9c42"
+-- Compression level 8 --
+string(32) "d9ede02415ce91d21e5a94274e2b9c42"
+-- Compression level 9 --
+string(32) "0f220a09e9895bcb3a1308d2bc99cfdf"
+-- Compression level -1 --
+string(32) "f77bd31e1e4dd11d12828fb661a08010"
+-- Compression level 0 --
+string(32) "9c5005db88490d6fe102ea2c233b2872"
+-- Compression level 1 --
+string(32) "d24ff7c4c20cef69b9c3abd603368db9"
+-- Compression level 2 --
+string(32) "f77bd31e1e4dd11d12828fb661a08010"
+-- Compression level 3 --
+string(32) "f77bd31e1e4dd11d12828fb661a08010"
+-- Compression level 4 --
+string(32) "f77bd31e1e4dd11d12828fb661a08010"
+-- Compression level 5 --
+string(32) "f77bd31e1e4dd11d12828fb661a08010"
+-- Compression level 6 --
+string(32) "f77bd31e1e4dd11d12828fb661a08010"
+-- Compression level 7 --
+string(32) "f77bd31e1e4dd11d12828fb661a08010"
+-- Compression level 8 --
+string(32) "f77bd31e1e4dd11d12828fb661a08010"
+-- Compression level 9 --
+string(32) "8849e9a1543c04b3f882b5ce20839ed2"
+
+-- Testing with no specified compression level --
+string(94) "1f8b08000000000000%c%c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200edc4e40b1b000000"
+
+-- Testing gzencode with mode specified --
+string(94) "1f8b08000000000000%c%c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200edc4e40b1b000000"
+===Done===
diff --git a/ext/zlib/tests/gzencode_error1.phpt b/ext/zlib/tests/gzencode_error1.phpt
new file mode 100644
index 0000000..9ecf4b8
--- /dev/null
+++ b/ext/zlib/tests/gzencode_error1.phpt
@@ -0,0 +1,98 @@
+--TEST--
+Test gzencode() function : error conditions
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzencode ( string $data [, int $level [, int $encoding_mode ]] )
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+/*
+ * Test error cases for gzencode
+ */
+
+echo "*** Testing gzencode() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing gzencode() function with Zero arguments --\n";
+var_dump( gzencode() );
+
+//Test gzencode with one more than the expected number of arguments
+echo "\n-- Testing gzencode() function with more than expected no. of arguments --\n";
+$data = 'string_val';
+$level = 2;
+$encoding_mode = FORCE_DEFLATE;
+$extra_arg = 10;
+var_dump( gzencode($data, $level, $encoding_mode, $extra_arg) );
+
+echo "\n-- Testing with incorrect compression level --\n";
+$bad_level = 99;
+var_dump(gzencode($data, $bad_level));
+
+echo "\n-- Testing with incorrect encoding_mode --\n";
+$bad_mode = 99;
+var_dump(gzencode($data, $level, $bad_mode));
+
+class Tester {
+ function Hello() {
+ echo "Hello\n";
+ }
+}
+
+echo "\n-- Testing with incorrect parameters --\n";
+$testclass = new Tester();
+var_dump(gzencode($testclass));
+var_dump(gzencode($data, $testclass));
+var_dump(gzencode($data, -1, 99.99));
+var_dump(gzencode($data, -1, $testclass));
+var_dump(gzencode($data, "a very none numeric string\n"));
+
+?>
+===Done===
+--EXPECTF--
+*** Testing gzencode() : error conditions ***
+
+-- Testing gzencode() function with Zero arguments --
+
+Warning: gzencode() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing gzencode() function with more than expected no. of arguments --
+
+Warning: gzencode() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+
+-- Testing with incorrect compression level --
+
+Warning: gzencode(): compression level (99) must be within -1..9 in %s on line %d
+bool(false)
+
+-- Testing with incorrect encoding_mode --
+
+Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
+bool(false)
+
+-- Testing with incorrect parameters --
+
+Warning: gzencode() expects parameter 1 to be string, object given in %s on line %d
+NULL
+
+Warning: gzencode() expects parameter 2 to be long, object given in %s on line %d
+NULL
+
+Warning: gzencode(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
+bool(false)
+
+Warning: gzencode() expects parameter 3 to be long, object given in %s on line %d
+NULL
+
+Warning: gzencode() expects parameter 2 to be long, string given in %s on line %d
+NULL
+===Done===
diff --git a/ext/zlib/tests/gzencode_variation1-win32.phpt b/ext/zlib/tests/gzencode_variation1-win32.phpt
new file mode 100644
index 0000000..5ff5778
--- /dev/null
+++ b/ext/zlib/tests/gzencode_variation1-win32.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test gzencode() function : variation
+--SKIPIF--
+<?php
+
+if( substr(PHP_OS, 0, 3) != "WIN" ) {
+ die("skip only for Windows");
+}
+
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzencode ( string $data [, int $level [, int $encoding_mode ]] )
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+if(!function_exists("gzdecode")) {
+ function gzdecode($data)
+ {
+ return gzinflate(substr($data,10,-8));
+ }
+}
+
+
+include(dirname(__FILE__) . '/data.inc');
+
+echo "*** Testing gzencode() : variation ***\n";
+
+echo "\n-- Testing multiple compression --\n";
+$output = gzencode(gzencode($data));
+
+$back = gzdecode(gzdecode($output));
+var_dump($data === $back);
+?>
+===Done===
+--EXPECT--
+*** Testing gzencode() : variation ***
+
+-- Testing multiple compression --
+bool(true)
+===Done===
diff --git a/ext/zlib/tests/gzencode_variation1.phpt b/ext/zlib/tests/gzencode_variation1.phpt
new file mode 100644
index 0000000..ef1d3a7
--- /dev/null
+++ b/ext/zlib/tests/gzencode_variation1.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Test gzencode() function : variation
+--SKIPIF--
+<?php
+
+if( substr(PHP_OS, 0, 3) == "WIN" ) {
+ die("skip.. Do not run on Windows");
+}
+
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzencode ( string $data [, int $level [, int $encoding_mode ]] )
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+include(dirname(__FILE__) . '/data.inc');
+
+echo "*** Testing gzencode() : variation ***\n";
+
+echo "\n-- Testing multiple compression --\n";
+$output = gzencode($data);
+var_dump(bin2hex(gzencode($output)));
+
+?>
+===Done===
+--EXPECT--
+*** Testing gzencode() : variation ***
+
+-- Testing multiple compression --
+string(3658) "1f8b0800000000000003010e07f1f81f8b08000000000000036d574d6fe4c80dbdeb57d4ad2f3dfe01eb83e1ec22980e309b4562c067b64449159754dafab0b6e7d7e73d96da1e4c72184c4b2ab2c8f7c847fa25baabba98dc1a8b2b7c38bb324b713ee37f757f56cdc5c7f5b17b9d152f923b157c5ae335e0b75fedd0e2d781c6b98ea3a6ee05affe1dfc3a6527f8f09c52dcb38ba38bb5249934d6ecfe1e53a9ab76ff4c342cf2a64ed2028349fc9a8b139755685352acb82b9fbb67f8bade5cdcb698e1fcec94b7ceba3cb897e806cfc8114350dd1ebbdfa35b62d2478b0056d23ed809b9b95d696d91ce2aa97c911e3fa539c43f84c887554a4d125c9e63ff96711cc08c0866263cb37a0bbe2122ae8f6baecb2284abfb4ddf916db8354cddeef37c1afe5fa02fc7afb3db34f5b3acbdf2eb905490d8f38d7468d253a323d5ebb903760d7944d3b2024e834a99ddce77669bdd823cfbb8e899d4ad4c799677452e6029e80023a03b2374005590641f7d3877df2ad09f3c0e82a54d6a5644fd63049a37ed4bc362016fd9f51264f1e5c630727421ae930b7ed416e93e47b7c71a400390361ffbecb7561bb98f69b5da289e91becc27f08b3b724cb8704f9144d366431d0cb870c56b205deaa2e17636063761a911039fb7e4bf9f06c4f0aecd2ec80e8b41831ca7515e31286166458ea3ef71f2ce7cde2ae269c96d60525724a9c9170b713ed5750758f3cd2a361fc8b288fc92358ce884692e8ea0fe59bd969a0da2eed5831b715749eaae7178f3ebd30fb88c92105f367cce2c882955dc6bf8eca0d5d57540b3092894743ba0fd5b2dad021836191f1afc0bba14dde1642cb0b1aa6879c38907dcefa0720082b801bec61417469219175267dfa047df35b0bd1332001c28cdfafd3bcabe91e74368cdd8d8478e494c190e7ee90c67f2bde288e68ab6b15e883c995be4f8feb6c6dda4278e4f38578ddbdc7be36788daf0c3cb1d1819c73822f7000a0d1813fa94153b572315e51343b536bc64977dff163cebfd8418773261f524017e251fccc60ae29a5770ae097594d52e9c1229d87ce967a36401c46b69945afb249d101c9d420ffa9a123e232c20e76467d5d169202a2dd4c582949e013e745df7958d4b0cc4fd4377a737cd4feea7974070000f314d423e0634cb9a618fdf5dc64fd422181fd59c9230c9f6f9d18dc8fc23e9cccbc7188733b04aa57de83ebea0be3633cff5fa1ff83269be7f44f5a8d84550cc703255fd345dd402034d0b3e11a73ec6e3d4a77f4f685b614329f1b3132ae7af33d02e1e55e291fa6574b758d1f0200e7423dbc852211818043a7c9ce80aa9d59fce0401959f5ea2cf71fde90824f8c9192dbe9d329db143794675ddcf257dd7755273b67340414e3ccad12e3f661f8aad9cf9957dc1275d10a51d3934fa81e68dc6768fb8ee23e373936c8e13feab8b0f50d227f7af76f561fb0950f3d099bbc316c3892a42fb36806d8660e800fa4f43fd4b962d2097d71933a54b77ff948677848eb17bb3a88b621682cfb3bbb49cf42fed6b3944124ad8358ca688aa44dd5f2144c7c9ab16f25b9aca9654ef357ec9ad55c40d324d6cc3d9e3920b863c231d31a95d937fb5520f9c816c79b7dcecc593fb9593cc05a51ebb1eeddd5b49eb437769738d0f64adc579d372b8b7f7c0208487ee3915ebf5766e148ebd77cf4e01f3ec285047011e55838968b6494d517fe29224777b24dd3ddf933101695b102e87db805eef291b74dcfd91628fb2a53f93dbd2968ef2e598746c9204f89fba1f0246fc671610a0591806e46a1346f77c40d910a47c5e20ffb23f003c04b648327a4ed98032c1965bd35bb0044f5344248f56fdb99aa61d6451d68e33489a83bffbe6573541b2da5f64681ea12090f778b2075374778810f73965fa3626a9d41f4df2f83f7c34658cec921b5a9bde49dd5007ec882b02adc514f81aa85898b5cc98e1b137733c0a8789b7f5648d2d231b80bf74978f25d61ce08a8abd11801fd8f995e066676307192ff7641f1cc6e0dee68565b8b22ac3889cd067bf732754a6b270af1044c6a8776811a4f6d8bd0477a9f516064201b920b92d7cd4dc7eee13e6b3eb3528a82f9abb3f388ebe6a8f871393461b73816ec54c99d604174bc5a6801de13908f86aea6a7d0fea107d682bcf1ec348b83872e6b8a316ecd02eb8f8dc86a609bf59a2dd03f1dfa4079436d55e24617be1a2854d008b2b2b1705e2078a7f3946318df1c24f6bf70d4b456eca286ec2b585b28262cc048a098c3e2d5f325a92bb36f691afdc14c822da1b116c9c1c07bb362eb0a04b78834c812134230ebf2044ac2e3c0e3ad00f848dc5010f3bf917ec2fc700b7bf26dacea8440620e04f90f4d97d6dd77cfde8a05c7d3930f1e5811fb8ec5c70964dcc8187ec90e32fdd6b64eec7586413b7d55bed65c4cce39a9b6c15e70e9da94e53fc904e6286f01f5b5562c94211befbc23507e01b2a3865e2f45b5d7b591f290087a5605b82495b4e393f31aa5b37211ec40241a746d903c5eebf117a4d3ddb0d00007b64cbc70e070000"
+===Done===
diff --git a/ext/zlib/tests/gzencode_variation2-win32.phpt b/ext/zlib/tests/gzencode_variation2-win32.phpt
new file mode 100644
index 0000000..7adda31
--- /dev/null
+++ b/ext/zlib/tests/gzencode_variation2-win32.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test gzencode() function : variation - verify header contents with all encoding modes
+--SKIPIF--
+<?php
+
+if( substr(PHP_OS, 0, 3) != "WIN" ) {
+ die("skip.. only for Windows");
+}
+
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzencode ( string $data [, int $level [, int $encoding_mode ]] )
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzencode() : variation ***\n";
+
+$data = "A small string to encode\n";
+
+echo "\n-- Testing with each encoding_mode --\n";
+var_dump(bin2hex(gzencode($data, -1)));
+var_dump(bin2hex(gzencode($data, -1, FORCE_GZIP)));
+var_dump(bin2hex(gzencode($data, -1, FORCE_DEFLATE)));
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzencode() : variation ***
+
+-- Testing with each encoding_mode --
+string(90) "1f8b080000000000000b735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000"
+string(90) "1f8b080000000000000b735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000"
+string(66) "789c735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200735808cd"
+===DONE===
diff --git a/ext/zlib/tests/gzencode_variation2.phpt b/ext/zlib/tests/gzencode_variation2.phpt
new file mode 100644
index 0000000..de63b71
--- /dev/null
+++ b/ext/zlib/tests/gzencode_variation2.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test gzencode() function : variation - verify header contents with all encoding modes
+--SKIPIF--
+<?php
+
+if( substr(PHP_OS, 0, 3) == "WIN" ) {
+ die("skip.. Do not run on Windows");
+}
+
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzencode ( string $data [, int $level [, int $encoding_mode ]] )
+ * Description: Gzip-compress a string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzencode() : variation ***\n";
+
+$data = "A small string to encode\n";
+
+echo "\n-- Testing with each encoding_mode --\n";
+var_dump(bin2hex(gzencode($data, -1)));
+var_dump(bin2hex(gzencode($data, -1, FORCE_GZIP)));
+var_dump(bin2hex(gzencode($data, -1, FORCE_DEFLATE)));
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzencode() : variation ***
+
+-- Testing with each encoding_mode --
+string(90) "1f8b0800000000000003735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000"
+string(90) "1f8b0800000000000003735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200d7739de519000000"
+string(66) "789c735428ce4dccc951282e29cacc4b5728c95748cd4bce4f49e50200735808cd"
+===DONE===
diff --git a/ext/zlib/tests/gzeof_basic.phpt b/ext/zlib/tests/gzeof_basic.phpt
new file mode 100644
index 0000000..f5d2617
--- /dev/null
+++ b/ext/zlib/tests/gzeof_basic.phpt
@@ -0,0 +1,58 @@
+--TEST--
+Test function feof() by calling it with its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+// note that gzeof is an alias to gzeof. parameter checking tests will be
+// the same as gzeof
+
+$f = dirname(__FILE__)."/004.txt.gz";
+
+echo "-- test 1 --\n";
+$h = gzopen($f, 'r');
+var_dump(gzeof($h));
+gzpassthru($h);
+var_dump(gzeof($h));
+gzclose($h);
+
+echo "\n-- test 2 --\n";
+$h = gzopen($f, 'r');
+echo "reading 50 characters. eof should be false\n";
+gzread($h, 50)."\n";
+var_dump(gzeof($h));
+echo "reading 250 characters. eof should be true\n";
+gzread($h, 250)."\n";
+var_dump(gzeof($h));
+echo "reading 20 characters. eof should be true still\n";
+gzread($h, 20)."\n";
+var_dump(gzeof($h));
+gzclose($h);
+
+
+
+?>
+===DONE===
+--EXPECT--
+-- test 1 --
+bool(false)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+bool(true)
+
+-- test 2 --
+reading 50 characters. eof should be false
+bool(false)
+reading 250 characters. eof should be true
+bool(true)
+reading 20 characters. eof should be true still
+bool(true)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzeof_error.phpt b/ext/zlib/tests/gzeof_error.phpt
new file mode 100644
index 0000000..af0f7c1
--- /dev/null
+++ b/ext/zlib/tests/gzeof_error.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test function gzeof() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$extra_arg = 'nothing';
+var_dump(gzeof( $h, $extra_arg ) );
+var_dump(gzeof() );
+gzclose($h)
+
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzeof() expects exactly 1 parameter, 2 given in %s on line %d
+bool(false)
+
+Warning: gzeof() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzeof_variation1.phpt b/ext/zlib/tests/gzeof_variation1.phpt
new file mode 100644
index 0000000..6d1e040
--- /dev/null
+++ b/ext/zlib/tests/gzeof_variation1.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test function gzeof while writing.
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$filename = dirname(__FILE__)."/temp.txt.gz";
+$h = gzopen($filename, 'w');
+$str = "Here is the string to be written. ";
+$length = 10;
+gzwrite( $h, $str );
+var_dump(gzeof($h));
+gzwrite( $h, $str, $length);
+var_dump(gzeof($h));
+gzclose($h);
+var_dump(gzeof($h));
+unlink($filename);
+?>
+===DONE===
+--EXPECTF--
+bool(false)
+bool(false)
+
+Warning: gzeof(): %d is not a valid stream resource in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_basic.phpt b/ext/zlib/tests/gzfile_basic.phpt
new file mode 100644
index 0000000..fd7ba18
--- /dev/null
+++ b/ext/zlib/tests/gzfile_basic.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Test function gzfile() reading a gzip relative file
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+$plaintxt = b<<<EOT
+hello world
+is a very common test
+for all languages
+EOT;
+$dirname = 'gzfile_temp';
+$filename = $dirname.'/plainfile.txt.gz';
+mkdir($dirname);
+$h = gzopen($filename, 'w');
+gzwrite($h, $plaintxt);
+gzclose($h);
+
+
+var_dump(gzfile( $filename ) );
+
+unlink($filename);
+rmdir($dirname);
+?>
+===DONE===
+--EXPECT--
+array(3) {
+ [0]=>
+ string(12) "hello world
+"
+ [1]=>
+ string(22) "is a very common test
+"
+ [2]=>
+ string(17) "for all languages"
+}
+===DONE===
diff --git a/ext/zlib/tests/gzfile_basic2.phpt b/ext/zlib/tests/gzfile_basic2.phpt
new file mode 100644
index 0000000..9124d33
--- /dev/null
+++ b/ext/zlib/tests/gzfile_basic2.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Test function gzfile() reading a plain relative file
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+$plaintxt = b<<<EOT
+hello world
+is a very common test
+for all languages
+EOT;
+$dirname = 'gzfile_temp';
+$filename = $dirname.'/plainfile.txt';
+mkdir($dirname);
+$h = fopen($filename, 'w');
+fwrite($h, $plaintxt);
+fclose($h);
+
+
+var_dump(gzfile( $filename ) );
+
+unlink($filename);
+rmdir($dirname);
+?>
+===DONE===
+--EXPECT--
+array(3) {
+ [0]=>
+ string(12) "hello world
+"
+ [1]=>
+ string(22) "is a very common test
+"
+ [2]=>
+ string(17) "for all languages"
+}
+===DONE===
diff --git a/ext/zlib/tests/gzfile_error.phpt b/ext/zlib/tests/gzfile_error.phpt
new file mode 100644
index 0000000..6089f3e
--- /dev/null
+++ b/ext/zlib/tests/gzfile_error.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Test function gzfile() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+$use_include_path = false;
+$extra_arg = 'nothing';
+
+var_dump(gzfile( $filename, $use_include_path, $extra_arg ) );
+
+var_dump(gzfile( ) );
+
+
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzfile() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+
+Warning: gzfile() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_variation1.phpt b/ext/zlib/tests/gzfile_variation1.phpt
new file mode 100644
index 0000000..767abb7
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation1.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test function gzfile() by substituting agument 1 with array values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+$index_array = array(1, 2, 3);
+$assoc_array = array(1 => 'one', 2 => 'two');
+
+$variation = array(
+ 'empty array' => array(),
+ 'int indexed array' => $index_array,
+ 'associative array' => $assoc_array,
+ 'nested arrays' => array('foo', $index_array, $assoc_array),
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzfile() expects parameter 1 to be a valid path, array given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 1 to be a valid path, array given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 1 to be a valid path, array given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 1 to be a valid path, array given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/zlib/tests/gzfile_variation10.phpt b/ext/zlib/tests/gzfile_variation10.phpt
new file mode 100644
index 0000000..2a6d891
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation10.phpt
@@ -0,0 +1,119 @@
+--TEST--
+Test function gzfile() by substituting agument 2 with emptyUnsetUndefNull values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+
+
+$unset_var = 10;
+unset($unset_var);
+
+$variation = array(
+ 'unset var' => @$unset_var,
+ 'undefined var' => @$undefined_var,
+ 'empty string DQ' => "",
+ 'empty string SQ' => '',
+ 'uppercase NULL' => NULL,
+ 'lowercase null' => null,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECTF--
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+
+Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_variation11.phpt b/ext/zlib/tests/gzfile_variation11.phpt
new file mode 100644
index 0000000..02faa45
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation11.phpt
@@ -0,0 +1,129 @@
+--TEST--
+Test function gzfile() by substituting agument 2 with float values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+
+
+$variation = array(
+ 'float 10.5' => 10.5,
+ 'float -10.5' => -10.5,
+ 'float 12.3456789000e10' => 12.3456789000e10,
+ 'float -12.3456789000e10' => -12.3456789000e10,
+ 'float .5' => .5,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECT--
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_variation12.phpt b/ext/zlib/tests/gzfile_variation12.phpt
new file mode 100644
index 0000000..a8efc76
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation12.phpt
@@ -0,0 +1,108 @@
+--TEST--
+Test function gzfile() by substituting agument 2 with int values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+
+
+$variation = array (
+ 'int 0' => 0,
+ 'int 1' => 1,
+ 'int 12345' => 12345,
+ 'int -12345' => -2345,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECT--
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_variation13.phpt b/ext/zlib/tests/gzfile_variation13.phpt
new file mode 100644
index 0000000..8014d7d
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation13.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Test function gzfile() by substituting agument 2 with object values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = $filename = dirname(__FILE__)."/004.txt.gz";
+
+
+function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
+ if (error_reporting() != 0) {
+ // report non-silenced errors
+ echo "Error: $err_no - $err_msg, $filename($linenum)\n";
+ }
+}
+set_error_handler('test_error_handler');
+
+
+
+class classWithToString
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+class classWithoutToString
+{
+}
+
+$variation = array(
+ 'instance of classWithToString' => new classWithToString(),
+ 'instance of classWithoutToString' => new classWithoutToString(),
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECTF--
+Error: 2 - gzfile() expects parameter 2 to be long, object given, %s(%d)
+NULL
+Error: 2 - gzfile() expects parameter 2 to be long, object given, %s(%d)
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_variation14.phpt b/ext/zlib/tests/gzfile_variation14.phpt
new file mode 100644
index 0000000..8eb183c
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation14.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Test function gzfile() by substituting agument 2 with string values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = $filename = dirname(__FILE__)."/004.txt.gz";
+
+
+$heredoc = <<<EOT
+hello world
+EOT;
+
+$variation_array = array(
+ 'string DQ' => "string",
+ 'string SQ' => 'string',
+ 'mixed case string' => "sTrInG",
+ 'heredoc' => $heredoc
+ );
+
+
+foreach ( $variation_array as $var ) {
+ var_dump(gzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_variation15.phpt b/ext/zlib/tests/gzfile_variation15.phpt
new file mode 100644
index 0000000..08360da
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation15.phpt
@@ -0,0 +1,109 @@
+--TEST--
+Test gzfile() function : variation: use include path (relative directories in path)
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+require_once('reading_include_path.inc');
+
+//define the files to go into these directories, create one in dir2
+set_include_path($newIncludePath);
+test_gzfile();
+restore_include_path();
+
+// remove the directory structure
+chdir($baseDir);
+rmdir($workingDir);
+foreach($newdirs as $newdir) {
+ rmdir($newdir);
+}
+
+chdir("..");
+rmdir($thisTestDir);
+
+function test_gzfile() {
+ global $scriptFile, $secondFile, $firstFile, $filename;
+
+ // create a file in the middle directory
+ $h = gzopen($secondFile, "w");
+ gzwrite($h, "This is a file in dir2");
+ gzclose($h);
+
+ // should read dir2 file
+ var_dump(gzfile($filename, true));
+ echo "\n";
+
+ //create a file in dir1
+ $h = gzopen($firstFile, "w");
+ gzwrite($h, "This is a file in dir1");
+ gzclose($h);
+
+ //should now read dir1 file
+ var_dump(gzfile($filename, true));
+ echo "\n";
+
+ // create a file in working directory
+ $h = gzopen($filename, "w");
+ gzwrite($h, "This is a file in working dir");
+ gzclose($h);
+
+ //should still read dir1 file
+ var_dump(gzfile($filename, true));
+ echo "\n";
+
+ unlink($firstFile);
+ unlink($secondFile);
+
+ //should read the file in working directory
+ var_dump(gzfile($filename, true));
+ echo "\n";
+
+ // create a file in the script directory
+ $h = gzopen($scriptFile, "w");
+ gzwrite($h, "This is a file in script dir");
+ gzclose($h);
+
+ //should read the file in script dir
+ var_dump(gzfile($filename, true));
+ echo "\n";
+
+ //cleanup
+ unlink($filename);
+ unlink($scriptFile);
+
+}
+
+?>
+===DONE===
+--EXPECTF--
+array(1) {
+ [0]=>
+ string(22) "This is a file in dir2"
+}
+
+array(1) {
+ [0]=>
+ string(22) "This is a file in dir1"
+}
+
+array(1) {
+ [0]=>
+ string(22) "This is a file in dir1"
+}
+
+array(1) {
+ [0]=>
+ string(29) "This is a file in working dir"
+}
+
+array(1) {
+ [0]=>
+ string(28) "This is a file in script dir"
+}
+
+===DONE===
+
diff --git a/ext/zlib/tests/gzfile_variation2.phpt b/ext/zlib/tests/gzfile_variation2.phpt
new file mode 100644
index 0000000..2f75c7f
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation2.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test function gzfile() by substituting agument 1 with boolean values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path =
+
+
+$variation = array(
+ 'lowercase true' => true,
+ 'lowercase false' =>false,
+ 'uppercase TRUE' =>TRUE,
+ 'uppercase FALSE' =>FALSE,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_variation3.phpt b/ext/zlib/tests/gzfile_variation3.phpt
new file mode 100644
index 0000000..8a6f2ce
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation3.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Test function gzfile() by substituting agument 1 with emptyUnsetUndefNull values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+$unset_var = 10;
+unset($unset_var);
+
+$variation = array(
+ 'unset var' => @$unset_var,
+ 'undefined var' => @$undefined_var,
+ 'empty string DQ' => "",
+ 'empty string SQ' => '',
+ 'uppercase NULL' => NULL,
+ 'lowercase null' => null,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+Warning: gzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: gzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: gzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: gzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: gzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: gzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_variation4.phpt b/ext/zlib/tests/gzfile_variation4.phpt
new file mode 100644
index 0000000..b3c8ac4
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation4.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test function gzfile() by substituting agument 1 with float values.
+--SKIPIF--
+<?php
+if (!extension_loaded(zlib)) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+$variation = array(
+ 'float 10.5' => 10.5,
+ 'float -10.5' => -10.5,
+ 'float 12.3456789000e10' => 12.3456789000e10,
+ 'float -12.3456789000e10' => -12.3456789000e10,
+ 'float .5' => .5,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+Warning: gzfile(10.5): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile(-10.5): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile(123456789000): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile(-123456789000): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile(0.5): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/zlib/tests/gzfile_variation5.phpt b/ext/zlib/tests/gzfile_variation5.phpt
new file mode 100644
index 0000000..5e210b6
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation5.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Test function gzfile() by substituting agument 1 with int values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+$variation = array (
+ 'int 0' => 0,
+ 'int 1' => 1,
+ 'int 12345' => 12345,
+ 'int -12345' => -2345,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+Warning: gzfile(0): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile(1): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile(12345): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile(-2345): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_variation6.phpt b/ext/zlib/tests/gzfile_variation6.phpt
new file mode 100644
index 0000000..1ce1be6
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation6.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Test function gzfile() by substituting agument 1 with object values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
+ if (error_reporting() != 0) {
+ // report non-silenced errors
+ echo "Error: $err_no - $err_msg, $filename($linenum)\n";
+ }
+}
+set_error_handler('test_error_handler');
+
+
+
+class classWithToString
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+class classWithoutToString
+{
+}
+
+$variation = array(
+ 'instance of classWithToString' => new classWithToString(),
+ 'instance of classWithoutToString' => new classWithoutToString(),
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $var , $use_include_path ) );
+}
+?>
+--EXPECTF--
+Error: 2 - gzfile(Class A object): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+Error: 2 - gzfile() expects parameter 1 to be a valid path, object given, %s(%d)
+NULL
diff --git a/ext/zlib/tests/gzfile_variation7.phpt b/ext/zlib/tests/gzfile_variation7.phpt
new file mode 100644
index 0000000..b441dd6
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation7.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Test function gzfile() by substituting agument 1 with string values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+$heredoc = <<<EOT
+hello world
+EOT;
+
+$variation_array = array(
+ 'string DQ' => "string",
+ 'string SQ' => 'string',
+ 'mixed case string' => "sTrInG",
+ 'heredoc' => $heredoc
+ );
+
+
+foreach ( $variation_array as $var ) {
+ var_dump(gzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzfile(string): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile(string): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile(sTrInG): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: gzfile(hello world): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/zlib/tests/gzfile_variation8.phpt b/ext/zlib/tests/gzfile_variation8.phpt
new file mode 100644
index 0000000..32d9693
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation8.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test function gzfile() by substituting agument 2 with array values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+
+
+$index_array = array(1, 2, 3);
+$assoc_array = array(1 => 'one', 2 => 'two');
+
+$variation = array(
+ 'empty array' => array(),
+ 'int indexed array' => $index_array,
+ 'associative array' => $assoc_array,
+ 'nested arrays' => array('foo', $index_array, $assoc_array),
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: gzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfile_variation9.phpt b/ext/zlib/tests/gzfile_variation9.phpt
new file mode 100644
index 0000000..c2c24ae
--- /dev/null
+++ b/ext/zlib/tests/gzfile_variation9.phpt
@@ -0,0 +1,107 @@
+--TEST--
+Test function gzfile() by substituting agument 2 with boolean values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+
+$variation = array(
+ 'lowercase true' => true,
+ 'lowercase false' =>false,
+ 'uppercase TRUE' =>TRUE,
+ 'uppercase FALSE' =>FALSE,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(gzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECT--
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzfilegzreadfile.phpt b/ext/zlib/tests/gzfilegzreadfile.phpt
new file mode 100644
index 0000000..2d6843d
--- /dev/null
+++ b/ext/zlib/tests/gzfilegzreadfile.phpt
@@ -0,0 +1,82 @@
+--TEST--
+gzfile(), gzreadfile()
+--SKIPIF--
+<?php /* $Id$ */
+if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+$original = <<<EOD
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+
+EOD;
+
+$filename = tempnam("/tmp", "phpt");
+
+$fp = gzopen($filename, "wb");
+gzwrite($fp, $original);
+var_dump(strlen($original));
+fclose($fp);
+
+readgzfile($filename);
+
+echo "\n";
+
+$lines = gzfile($filename);
+
+unlink($filename);
+
+foreach ($lines as $line) {
+ echo $line;
+}
+
+?>
+--EXPECT--
+int(560)
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
+blah blah blah blah blah blah blah
diff --git a/ext/zlib/tests/gzgetc_basic.phpt b/ext/zlib/tests/gzgetc_basic.phpt
new file mode 100644
index 0000000..5c814e0
--- /dev/null
+++ b/ext/zlib/tests/gzgetc_basic.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test function gzgetc() by calling it with its expected arguments zlib 1.2.5
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+include 'func.inc';
+if (version_compare(get_zlib_version(), '1.2.5') > 0) {
+ die('skip - only for zlib <= 1.2.5');
+}
+?>
+--FILE--
+<?php
+
+// note that gzgets is an alias to fgets. parameter checking tests will be
+// the same as gzgets
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+
+$count = 0;
+while (gzeof($h) === false) {
+ $count++;
+ echo fgetc( $h );
+}
+
+echo "\ncharacters counted=$count\n";
+gzclose($h);
+
+?>
+===DONE===
+--EXPECT--
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+
+characters counted=176
+===DONE===
diff --git a/ext/zlib/tests/gzgetc_basic_1.phpt b/ext/zlib/tests/gzgetc_basic_1.phpt
new file mode 100644
index 0000000..59e3eb6
--- /dev/null
+++ b/ext/zlib/tests/gzgetc_basic_1.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test function gzgetc() by calling it with its expected arguments zlib 1.2.7
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+include 'func.inc';
+if (version_compare(get_zlib_version(), '1.2.7') < 0) {
+ die('skip - only for zlib >= 1.2.7');
+}
+?>
+--FILE--
+<?php
+
+// note that gzgets is an alias to fgets. parameter checking tests will be
+// the same as gzgets
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+if ($h) {
+ $count = 0;
+ while (($c = fgetc( $h )) !== false) {
+ $count++;
+ echo $c;
+ }
+
+ echo "\ncharacters counted=$count\n";
+ gzclose($h);
+}
+
+?>
+===DONE===
+--EXPECT--
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+
+characters counted=176
+===DONE===
diff --git a/ext/zlib/tests/gzgetc_error.phpt b/ext/zlib/tests/gzgetc_error.phpt
new file mode 100644
index 0000000..cbeabe3
--- /dev/null
+++ b/ext/zlib/tests/gzgetc_error.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Test function gzgetc() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$extra_arg = 'nothing';
+var_dump(gzgetc( $h, $extra_arg ) );
+
+var_dump(gzgetc() );
+
+gzclose($h);
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzgetc() expects exactly 1 parameter, 2 given in %s on line %d
+bool(false)
+
+Warning: gzgetc() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzgets_basic.phpt b/ext/zlib/tests/gzgets_basic.phpt
new file mode 100644
index 0000000..3ebc759
--- /dev/null
+++ b/ext/zlib/tests/gzgets_basic.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test function gzgets() by calling it with its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+// note that gzgets is an alias to fgets. parameter checking tests will be
+// the same as fgets
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$lengths = array(10, 14, 7, 99);
+foreach ($lengths as $length) {
+ var_dump(gzgets( $h, $length ) );
+}
+
+while (gzeof($h) === false) {
+ var_dump(gzgets($h));
+}
+gzclose($h);
+
+
+?>
+===DONE===
+--EXPECT--
+string(9) "When you'"
+string(13) "re taught thr"
+string(6) "ough f"
+string(8) "eelings
+"
+string(26) "Destiny flying high above
+"
+string(38) "all I know is that you can realize it
+"
+string(18) "Destiny who cares
+"
+string(19) "as it turns around
+"
+string(39) "and I know that it descends down on me
+"
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzgets_error.phpt b/ext/zlib/tests/gzgets_error.phpt
new file mode 100644
index 0000000..fe224f1
--- /dev/null
+++ b/ext/zlib/tests/gzgets_error.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Test function gzgets() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$length = 10;
+$extra_arg = 'nothing';
+var_dump(gzgets( $h, $length, $extra_arg ) );
+
+var_dump(gzgets());
+
+
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzgets() expects at most 2 parameters, 3 given in %s on line %d
+bool(false)
+
+Warning: gzgets() expects at least 1 parameter, 0 given in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzinflate-bug42663.phpt b/ext/zlib/tests/gzinflate-bug42663.phpt
new file mode 100644
index 0000000..4f0ca9f
--- /dev/null
+++ b/ext/zlib/tests/gzinflate-bug42663.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Bug #42663 (gzinflate() try to allocate all memory with truncated $data)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+// build a predictable string
+$string = '';
+for($i=0; $i<30000; ++$i) $string .= $i . ' ';
+var_dump(strlen($string));
+// deflate string
+$deflated = gzdeflate($string,9);
+var_dump(strlen($deflated));
+// truncate $deflated string
+$truncated = substr($deflated, 0, 65535);
+var_dump(strlen($truncated));
+// inflate $truncated string (check if it will not eat all memory)
+var_dump(gzinflate($truncated));
+?>
+--EXPECTF--
+int(168890)
+int(66743)
+int(65535)
+
+Warning: gzinflate(): data error in %s on line %d
+bool(false)
diff --git a/ext/zlib/tests/gzinflate_error1.phpt b/ext/zlib/tests/gzinflate_error1.phpt
new file mode 100644
index 0000000..6dc8113
--- /dev/null
+++ b/ext/zlib/tests/gzinflate_error1.phpt
@@ -0,0 +1,75 @@
+--TEST--
+Test gzinflate() function : error conditions
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzinflate(string data [, int length])
+ * Description: Unzip a gzip-compressed string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+include(dirname(__FILE__) . '/data.inc');
+
+echo "*** Testing gzinflate() : error conditions ***\n";
+
+echo "\n-- Testing gzcompress() function with Zero arguments --\n";
+var_dump( gzinflate() );
+
+echo "\n-- Testing gzcompress() function with more than expected no. of arguments --\n";
+$data = 'string_val';
+$length = 10;
+$extra_arg = 10;
+var_dump( gzinflate($data, $length, $extra_arg) );
+
+echo "\n-- Testing with a buffer that is too small --\n";
+$short_len = strlen($data) - 1;
+$compressed = gzcompress($data);
+
+var_dump(gzinflate($compressed, $short_len));
+
+echo "\n-- Testing with incorrect parameters --\n";
+
+class Tester {
+ function Hello() {
+ echo "Hello\n";
+ }
+}
+
+$testclass = new Tester();
+var_dump(gzinflate($testclass));
+var_dump(gzinflate($data, $testclass));
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzinflate() : error conditions ***
+
+-- Testing gzcompress() function with Zero arguments --
+
+Warning: gzinflate() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing gzcompress() function with more than expected no. of arguments --
+
+Warning: gzinflate() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+
+-- Testing with a buffer that is too small --
+
+Warning: gzinflate(): data error in %s on line %d
+bool(false)
+
+-- Testing with incorrect parameters --
+
+Warning: gzinflate() expects parameter 1 to be string, object given in %s on line %d
+NULL
+
+Warning: gzinflate() expects parameter 2 to be long, object given in %s on line %d
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzinflate_length.phpt b/ext/zlib/tests/gzinflate_length.phpt
new file mode 100644
index 0000000..6e86d86
--- /dev/null
+++ b/ext/zlib/tests/gzinflate_length.phpt
@@ -0,0 +1,26 @@
+--TEST--
+gzinflate() and $length argument
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+$original = 'aaaaaaaaaaaaaaa';
+$packed=gzdeflate($original);
+echo strlen($packed)." ".strlen($original)."\n";
+$unpacked=gzinflate($packed, strlen($original));
+if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
+
+$unpacked=gzinflate($packed, strlen($original)*10);
+if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
+
+$unpacked=gzinflate($packed, 1);
+if ($unpacked === false) echo "Failed (as expected)\n";
+?>
+--EXPECTF--
+5 15
+Strings are equal
+Strings are equal
+
+Warning: gzinflate(): insufficient memory in %s on line %d
+Failed (as expected)
+
diff --git a/ext/zlib/tests/gzopen_basic.phpt b/ext/zlib/tests/gzopen_basic.phpt
new file mode 100644
index 0000000..e369773
--- /dev/null
+++ b/ext/zlib/tests/gzopen_basic.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Test gzopen() function : basic functionality
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzopen() : basic functionality ***\n";
+
+
+// Initialise all required variables
+$filename = dirname(__FILE__)."/004.txt.gz";
+$mode = 'r';
+$use_include_path = false;
+
+// Calling gzopen() with all possible arguments
+$h = gzopen($filename, $mode, $use_include_path);
+gzpassthru($h);
+gzclose($h);
+
+// Calling gzopen() with mandatory arguments
+$h = gzopen($filename, $mode);
+gzpassthru($h);
+gzclose($h);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzopen() : basic functionality ***
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+===DONE===
diff --git a/ext/zlib/tests/gzopen_basic2.phpt b/ext/zlib/tests/gzopen_basic2.phpt
new file mode 100644
index 0000000..5cc02cd
--- /dev/null
+++ b/ext/zlib/tests/gzopen_basic2.phpt
@@ -0,0 +1,52 @@
+--TEST--
+Test gzopen() function : basic functionality for writing
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzopen() : basic functionality ***\n";
+
+
+// Initialise all required variables
+$filename = "temp.txt.gz";
+$modes = array('w', 'w+');
+$data = "This was the information that was written";
+
+foreach($modes as $mode) {
+ echo "testing mode -- $mode --\n";
+ $h = gzopen($filename, $mode);
+ if ($h !== false) {
+ gzwrite($h, $data);
+ gzclose($h);
+ $h = gzopen($filename, 'r');
+ gzpassthru($h);
+ gzclose($h);
+ echo "\n";
+ unlink($filename);
+ }
+ else {
+ var_dump($h);
+ }
+}
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzopen() : basic functionality ***
+testing mode -- w --
+This was the information that was written
+testing mode -- w+ --
+
+Warning: gzopen(): cannot open a zlib stream for reading and writing at the same time! in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/zlib/tests/gzopen_error.phpt b/ext/zlib/tests/gzopen_error.phpt
new file mode 100644
index 0000000..a71791f
--- /dev/null
+++ b/ext/zlib/tests/gzopen_error.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Test gzopen() function : error conditions
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzopen() : error conditions ***\n";
+
+
+//Test gzopen with one more than the expected number of arguments
+echo "\n-- Testing gzopen() function with more than expected no. of arguments --\n";
+$filename = 'string_val';
+$mode = 'string_val';
+$use_include_path = 10;
+$extra_arg = 10;
+var_dump( gzopen($filename, $mode, $use_include_path, $extra_arg) );
+
+// Testing gzopen with one less than the expected number of arguments
+echo "\n-- Testing gzopen() function with less than expected no. of arguments --\n";
+$filename = 'string_val';
+var_dump( gzopen($filename) );
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzopen() : error conditions ***
+
+-- Testing gzopen() function with more than expected no. of arguments --
+
+Warning: gzopen() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+
+-- Testing gzopen() function with less than expected no. of arguments --
+
+Warning: gzopen() expects at least 2 parameters, 1 given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/zlib/tests/gzopen_include_path.inc b/ext/zlib/tests/gzopen_include_path.inc
new file mode 100644
index 0000000..7d6723a
--- /dev/null
+++ b/ext/zlib/tests/gzopen_include_path.inc
@@ -0,0 +1,92 @@
+<?php
+$pwd = getcwd();
+$f = basename(__FILE__);
+$dir1 = $pwd."/".$f.".dir1";
+$dir2 = $pwd."/".$f.".dir2";
+$dir3 = $pwd."/".$f.".dir3";
+//invalid directory
+$dir4 = $pwd."/".$f.".dir4";
+$newdirs = array($dir1, $dir2, $dir3);
+
+$reldirs = array("dir1", "dir2", "dir3");
+
+function generate_next_rel_path() {
+ global $reldirs;
+ //create the include directory structure
+ $pathSep = ":";
+ $newIncludePath = "";
+ if(substr(PHP_OS, 0, 3) == 'WIN' ) {
+ $pathSep = ";";
+ }
+ foreach($reldirs as $newdir) {
+ $newIncludePath .= $newdir.$pathSep;
+ }
+ return "dir4".$pathSep . $newIncludePath;
+}
+
+function generate_next_path() {
+ global $newdirs, $dir4;
+ //create the include directory structure
+ $pathSep = ":";
+ $newIncludePath = "";
+ if(substr(PHP_OS, 0, 3) == 'WIN' ) {
+ $pathSep = ";";
+ }
+ foreach($newdirs as $newdir) {
+ $newIncludePath .= $newdir.$pathSep;
+ }
+ return $dir4.$pathSep . $newIncludePath;
+}
+
+
+function create_include_path() {
+
+ global $newdirs;
+ //create the include directory structure
+ $pathSep = ":";
+ $newIncludePath = "";
+ if(substr(PHP_OS, 0, 3) == 'WIN' ) {
+ $pathSep = ";";
+ }
+ foreach($newdirs as $newdir) {
+ mkdir($newdir);
+ $newIncludePath .= $newdir.$pathSep;
+ }
+ return $newIncludePath;
+}
+
+function relative_include_path() {
+
+ global $reldirs;
+ //create the include directory structure
+ $pathSep = ":";
+ $newIncludePath = "";
+ if(substr(PHP_OS, 0, 3) == 'WIN' ) {
+ $pathSep = ";";
+ }
+ foreach($reldirs as $newdir) {
+ mkdir($newdir);
+ $newIncludePath .= $newdir.$pathSep;
+ }
+ return $newIncludePath;
+}
+
+
+function teardown_include_path() {
+
+ global $newdirs;
+ // remove the directory structure
+ foreach($newdirs as $newdir) {
+ rmdir($newdir);
+ }
+}
+
+function teardown_relative_path() {
+
+ global $reldirs;
+ // remove the directory structure
+ foreach($reldirs as $newdir) {
+ rmdir($newdir);
+ }
+}
+?> \ No newline at end of file
diff --git a/ext/zlib/tests/gzopen_variation1.phpt b/ext/zlib/tests/gzopen_variation1.phpt
new file mode 100644
index 0000000..c5a47f4
--- /dev/null
+++ b/ext/zlib/tests/gzopen_variation1.phpt
@@ -0,0 +1,228 @@
+--TEST--
+Test gzopen() function : usage variation
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - zlib extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzopen() : usage variation ***\n";
+
+// Define error handler
+function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
+ if (error_reporting() != 0) {
+ // report non-silenced errors
+ echo "Error: $err_no - $err_msg, $filename($linenum)\n";
+ }
+}
+set_error_handler('test_error_handler');
+
+// Initialise function arguments not being substituted (if any)
+$mode = 'r';
+$use_include_path = false;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// define some classes
+class classWithToString
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+class classWithoutToString
+{
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// add arrays
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+//array of values to iterate over
+$inputs = array(
+
+ // int data
+ 'int 0' => 0,
+ 'int 1' => 1,
+ 'int 12345' => 12345,
+ 'int -12345' => -2345,
+
+ // float data
+ 'float 10.5' => 10.5,
+ 'float -10.5' => -10.5,
+ 'float 12.3456789000e10' => 12.3456789000e10,
+ 'float -12.3456789000e10' => -12.3456789000e10,
+ 'float .5' => .5,
+
+ // array data
+ 'empty array' => array(),
+ 'int indexed array' => $index_array,
+ 'associative array' => $assoc_array,
+ 'nested arrays' => array('foo', $index_array, $assoc_array),
+
+ // null data
+ 'uppercase NULL' => NULL,
+ 'lowercase null' => null,
+
+ // boolean data
+ 'lowercase true' => true,
+ 'lowercase false' =>false,
+ 'uppercase TRUE' =>TRUE,
+ 'uppercase FALSE' =>FALSE,
+
+ // empty data
+ 'empty string DQ' => "",
+ 'empty string SQ' => '',
+
+ // object data
+ 'instance of classWithToString' => new classWithToString(),
+ 'instance of classWithoutToString' => new classWithoutToString(),
+
+ // undefined data
+ 'undefined var' => @$undefined_var,
+
+ // unset data
+ 'unset var' => @$unset_var,
+
+ // resource variable
+ 'resource' => $fp
+);
+
+// loop through each element of the array for filename
+
+foreach($inputs as $key =>$value) {
+ echo "\n--$key--\n";
+ var_dump( gzopen($value, $mode, $use_include_path) );
+};
+
+fclose($fp);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzopen() : usage variation ***
+
+--int 0--
+Error: 2 - gzopen(0): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--int 1--
+Error: 2 - gzopen(1): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--int 12345--
+Error: 2 - gzopen(12345): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--int -12345--
+Error: 2 - gzopen(-2345): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--float 10.5--
+Error: 2 - gzopen(10.5): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--float -10.5--
+Error: 2 - gzopen(-10.5): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--float 12.3456789000e10--
+Error: 2 - gzopen(123456789000): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--float -12.3456789000e10--
+Error: 2 - gzopen(-123456789000): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--float .5--
+Error: 2 - gzopen(0.5): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--empty array--
+Error: 2 - gzopen() expects parameter 1 to be string, array given, %s(%d)
+NULL
+
+--int indexed array--
+Error: 2 - gzopen() expects parameter 1 to be string, array given, %s(%d)
+NULL
+
+--associative array--
+Error: 2 - gzopen() expects parameter 1 to be string, array given, %s(%d)
+NULL
+
+--nested arrays--
+Error: 2 - gzopen() expects parameter 1 to be string, array given, %s(%d)
+NULL
+
+--uppercase NULL--
+Error: 2 - gzopen(): Filename cannot be empty, %s(%d)
+bool(false)
+
+--lowercase null--
+Error: 2 - gzopen(): Filename cannot be empty, %s(%d)
+bool(false)
+
+--lowercase true--
+Error: 2 - gzopen(1): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--lowercase false--
+Error: 2 - gzopen(): Filename cannot be empty, %s(%d)
+bool(false)
+
+--uppercase TRUE--
+Error: 2 - gzopen(1): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--uppercase FALSE--
+Error: 2 - gzopen(): Filename cannot be empty, %s(%d)
+bool(false)
+
+--empty string DQ--
+Error: 2 - gzopen(): Filename cannot be empty, %s(%d)
+bool(false)
+
+--empty string SQ--
+Error: 2 - gzopen(): Filename cannot be empty, %s(%d)
+bool(false)
+
+--instance of classWithToString--
+Error: 2 - gzopen(Class A object): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+
+--instance of classWithoutToString--
+Error: 2 - gzopen() expects parameter 1 to be string, object given, %s(%d)
+NULL
+
+--undefined var--
+Error: 2 - gzopen(): Filename cannot be empty, %s(%d)
+bool(false)
+
+--unset var--
+Error: 2 - gzopen(): Filename cannot be empty, %s(%d)
+bool(false)
+
+--resource--
+Error: 2 - gzopen() expects parameter 1 to be string, resource given, %s(%d)
+NULL
+===DONE===
+
diff --git a/ext/zlib/tests/gzopen_variation2.phpt b/ext/zlib/tests/gzopen_variation2.phpt
new file mode 100644
index 0000000..4582935
--- /dev/null
+++ b/ext/zlib/tests/gzopen_variation2.phpt
@@ -0,0 +1,227 @@
+--TEST--
+Test gzopen() function : usage variation
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - zlib extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzopen() : usage variation ***\n";
+
+// Define error handler
+function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
+ if (error_reporting() != 0) {
+ // report non-silenced errors
+ echo "Error: $err_no - $err_msg, $filename($linenum)\n";
+ }
+}
+set_error_handler('test_error_handler');
+
+// Initialise function arguments not being substituted (if any)
+$filename = dirname(__FILE__)."/004.txt.gz";
+$use_include_path = false;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// define some classes
+class classWithToString
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+class classWithoutToString
+{
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// add arrays
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+//array of values to iterate over
+$inputs = array(
+
+ // int data
+ 'int 0' => 0,
+ 'int 1' => 1,
+ 'int 12345' => 12345,
+ 'int -12345' => -2345,
+
+ // float data
+ 'float 10.5' => 10.5,
+ 'float -10.5' => -10.5,
+ 'float 12.3456789000e10' => 12.3456789000e10,
+ 'float -12.3456789000e10' => -12.3456789000e10,
+ 'float .5' => .5,
+
+ // array data
+ 'empty array' => array(),
+ 'int indexed array' => $index_array,
+ 'associative array' => $assoc_array,
+ 'nested arrays' => array('foo', $index_array, $assoc_array),
+
+ // null data
+ 'uppercase NULL' => NULL,
+ 'lowercase null' => null,
+
+ // boolean data
+ 'lowercase true' => true,
+ 'lowercase false' =>false,
+ 'uppercase TRUE' =>TRUE,
+ 'uppercase FALSE' =>FALSE,
+
+ // empty data
+ 'empty string DQ' => "",
+ 'empty string SQ' => '',
+
+ // object data
+ 'instance of classWithToString' => new classWithToString(),
+ 'instance of classWithoutToString' => new classWithoutToString(),
+
+ // undefined data
+ 'undefined var' => @$undefined_var,
+
+ // unset data
+ 'unset var' => @$unset_var,
+
+ // resource variable
+ 'resource' => $fp
+);
+
+// loop through each element of the array for mode
+
+foreach($inputs as $key =>$value) {
+ echo "\n--$key--\n";
+ var_dump( gzopen($filename, $value, $use_include_path) );
+};
+
+fclose($fp);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzopen() : usage variation ***
+
+--int 0--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--int 1--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--int 12345--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--int -12345--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--float 10.5--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--float -10.5--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--float 12.3456789000e10--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--float -12.3456789000e10--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--float .5--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--empty array--
+Error: 2 - gzopen() expects parameter 2 to be string, array given, %s(%d)
+NULL
+
+--int indexed array--
+Error: 2 - gzopen() expects parameter 2 to be string, array given, %s(%d)
+NULL
+
+--associative array--
+Error: 2 - gzopen() expects parameter 2 to be string, array given, %s(%d)
+NULL
+
+--nested arrays--
+Error: 2 - gzopen() expects parameter 2 to be string, array given, %s(%d)
+NULL
+
+--uppercase NULL--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--lowercase null--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--lowercase true--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--lowercase false--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--uppercase TRUE--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--uppercase FALSE--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--empty string DQ--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--empty string SQ--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--instance of classWithToString--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--instance of classWithoutToString--
+Error: 2 - gzopen() expects parameter 2 to be string, object given, %s(%d)
+NULL
+
+--undefined var--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--unset var--
+Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
+bool(false)
+
+--resource--
+Error: 2 - gzopen() expects parameter 2 to be string, resource given, %s(%d)
+NULL
+===DONE===
diff --git a/ext/zlib/tests/gzopen_variation3.phpt b/ext/zlib/tests/gzopen_variation3.phpt
new file mode 100644
index 0000000..59e45a8
--- /dev/null
+++ b/ext/zlib/tests/gzopen_variation3.phpt
@@ -0,0 +1,218 @@
+--TEST--
+Test gzopen() function : usage variation
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - zlib extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzopen() : usage variation ***\n";
+
+// Define error handler
+function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
+ if (error_reporting() != 0) {
+ // report non-silenced errors
+ echo "Error: $err_no - $err_msg, $filename($linenum)\n";
+ }
+}
+set_error_handler('test_error_handler');
+
+// Initialise function arguments not being substituted (if any)
+$filename = dirname(__FILE__)."/004.txt.gz";
+$mode = 'r';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// define some classes
+class classWithToString
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+class classWithoutToString
+{
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// add arrays
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+//array of values to iterate over
+$inputs = array(
+
+ // float data
+ 'float 10.5' => 10.5,
+ 'float -10.5' => -10.5,
+ 'float 12.3456789000e10' => 12.3456789000e10,
+ 'float -12.3456789000e10' => -12.3456789000e10,
+ 'float .5' => .5,
+
+ // array data
+ 'empty array' => array(),
+ 'int indexed array' => $index_array,
+ 'associative array' => $assoc_array,
+ 'nested arrays' => array('foo', $index_array, $assoc_array),
+
+ // null data
+ 'uppercase NULL' => NULL,
+ 'lowercase null' => null,
+
+ // boolean data
+ 'lowercase true' => true,
+ 'lowercase false' =>false,
+ 'uppercase TRUE' =>TRUE,
+ 'uppercase FALSE' =>FALSE,
+
+ // empty data
+ 'empty string DQ' => "",
+ 'empty string SQ' => '',
+
+ // string data
+ 'string DQ' => "string",
+ 'string SQ' => 'string',
+ 'mixed case string' => "sTrInG",
+ 'heredoc' => $heredoc,
+
+ // object data
+ 'instance of classWithToString' => new classWithToString(),
+ 'instance of classWithoutToString' => new classWithoutToString(),
+
+ // undefined data
+ 'undefined var' => @$undefined_var,
+
+ // unset data
+ 'unset var' => @$unset_var,
+
+ // resource variable
+ 'resource' => $fp
+);
+
+// loop through each element of the array for use_include_path
+
+foreach($inputs as $key =>$value) {
+ echo "\n--$key--\n";
+ $res = gzopen($filename, $mode, $value);
+ var_dump($res);
+ if ($res === true) {
+ gzclose($res);
+ }
+};
+
+fclose($fp);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzopen() : usage variation ***
+
+--float 10.5--
+resource(%d) of type (stream)
+
+--float -10.5--
+resource(%d) of type (stream)
+
+--float 12.3456789000e10--
+resource(%d) of type (stream)
+
+--float -12.3456789000e10--
+resource(%d) of type (stream)
+
+--float .5--
+resource(%d) of type (stream)
+
+--empty array--
+Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d)
+NULL
+
+--int indexed array--
+Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d)
+NULL
+
+--associative array--
+Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d)
+NULL
+
+--nested arrays--
+Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d)
+NULL
+
+--uppercase NULL--
+resource(%d) of type (stream)
+
+--lowercase null--
+resource(%d) of type (stream)
+
+--lowercase true--
+resource(%d) of type (stream)
+
+--lowercase false--
+resource(%d) of type (stream)
+
+--uppercase TRUE--
+resource(%d) of type (stream)
+
+--uppercase FALSE--
+resource(%d) of type (stream)
+
+--empty string DQ--
+Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
+NULL
+
+--empty string SQ--
+Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
+NULL
+
+--string DQ--
+Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
+NULL
+
+--string SQ--
+Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
+NULL
+
+--mixed case string--
+Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
+NULL
+
+--heredoc--
+Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
+NULL
+
+--instance of classWithToString--
+Error: 2 - gzopen() expects parameter 3 to be long, object given, %s(%d)
+NULL
+
+--instance of classWithoutToString--
+Error: 2 - gzopen() expects parameter 3 to be long, object given, %s(%d)
+NULL
+
+--undefined var--
+resource(%d) of type (stream)
+
+--unset var--
+resource(%d) of type (stream)
+
+--resource--
+Error: 2 - gzopen() expects parameter 3 to be long, resource given, %s(%d)
+NULL
+===DONE===
diff --git a/ext/zlib/tests/gzopen_variation4.phpt b/ext/zlib/tests/gzopen_variation4.phpt
new file mode 100644
index 0000000..f829acf
--- /dev/null
+++ b/ext/zlib/tests/gzopen_variation4.phpt
@@ -0,0 +1,161 @@
+--TEST--
+Test gzopen() function : variation: use include path (relative directories in path)
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzopen() : usage variation ***\n";
+
+require_once('reading_include_path.inc');
+
+//define the files to go into these directories, create one in dir2
+echo "\n--- testing include path ---\n";
+set_include_path($newIncludePath);
+$modes = array("r", "r+", "rt");
+foreach($modes as $mode) {
+ test_gzopen($mode);
+}
+restore_include_path();
+
+// remove the directory structure
+chdir($baseDir);
+rmdir($workingDir);
+foreach($newdirs as $newdir) {
+ rmdir($newdir);
+}
+
+chdir("..");
+rmdir($thisTestDir);
+
+function test_gzopen($mode) {
+ global $scriptFile, $secondFile, $firstFile, $filename;
+
+ // create a file in the middle directory
+ $h = gzopen($secondFile, "w");
+ gzwrite($h, "This is a file in dir2");
+ gzclose($h);
+
+ echo "\n** testing with mode=$mode **\n";
+ // should read dir2 file
+ $h = gzopen($filename, $mode, true);
+ gzpassthru($h);
+ gzclose($h);
+ echo "\n";
+
+ //create a file in dir1
+ $h = gzopen($firstFile, "w");
+ gzwrite($h, "This is a file in dir1");
+ gzclose($h);
+
+ //should now read dir1 file
+ $h = gzopen($filename, $mode, true);
+ gzpassthru($h);
+ gzclose($h);
+ echo "\n";
+
+ // create a file in working directory
+ $h = gzopen($filename, "w");
+ gzwrite($h, "This is a file in working dir");
+ gzclose($h);
+
+ //should still read dir1 file
+ $h = gzopen($filename, $mode, true);
+ gzpassthru($h);
+ gzclose($h);
+ echo "\n";
+
+ unlink($firstFile);
+ unlink($secondFile);
+
+ //should read the file in working dir
+ $h = gzopen($filename, $mode, true);
+ gzpassthru($h);
+ gzclose($h);
+ echo "\n";
+
+ // create a file in the script directory
+ $h = gzopen($scriptFile, "w");
+ gzwrite($h, "This is a file in script dir");
+ gzclose($h);
+
+ //should read the file in script dir
+ $h = gzopen($filename, $mode, true);
+ gzpassthru($h);
+ gzclose($h);
+ echo "\n";
+
+ //cleanup
+ unlink($filename);
+ unlink($scriptFile);
+
+}
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzopen() : usage variation ***
+
+--- testing include path ---
+
+** testing with mode=r **
+This is a file in dir2
+This is a file in dir1
+This is a file in dir1
+This is a file in working dir
+This is a file in script dir
+
+** testing with mode=r+ **
+
+Warning: gzopen(): cannot open a zlib stream for reading and writing at the same time! in %s on line %d
+
+Warning: gzpassthru() expects parameter 1 to be resource, boolean given in %s on line %d
+
+Warning: gzclose() expects parameter 1 to be resource, boolean given in %s on line %d
+
+
+Warning: gzopen(): cannot open a zlib stream for reading and writing at the same time! in %s on line %d
+
+Warning: gzpassthru() expects parameter 1 to be resource, boolean given in %s on line %d
+
+Warning: gzclose() expects parameter 1 to be resource, boolean given in %s on line %d
+
+
+Warning: gzopen(): cannot open a zlib stream for reading and writing at the same time! in %s on line %d
+
+Warning: gzpassthru() expects parameter 1 to be resource, boolean given in %s on line %d
+
+Warning: gzclose() expects parameter 1 to be resource, boolean given in %s on line %d
+
+
+Warning: gzopen(): cannot open a zlib stream for reading and writing at the same time! in %s on line %d
+
+Warning: gzpassthru() expects parameter 1 to be resource, boolean given in %s on line %d
+
+Warning: gzclose() expects parameter 1 to be resource, boolean given in %s on line %d
+
+
+Warning: gzopen(): cannot open a zlib stream for reading and writing at the same time! in %s on line %d
+
+Warning: gzpassthru() expects parameter 1 to be resource, boolean given in %s on line %d
+
+Warning: gzclose() expects parameter 1 to be resource, boolean given in %s on line %d
+
+
+** testing with mode=rt **
+This is a file in dir2
+This is a file in dir1
+This is a file in dir1
+This is a file in working dir
+This is a file in script dir
+===DONE===
+
diff --git a/ext/zlib/tests/gzopen_variation5.phpt b/ext/zlib/tests/gzopen_variation5.phpt
new file mode 100644
index 0000000..de505f7
--- /dev/null
+++ b/ext/zlib/tests/gzopen_variation5.phpt
@@ -0,0 +1,71 @@
+--TEST--
+Test gzopen() function : variation: use include path and stream context create a file, relative path
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+require_once('gzopen_include_path.inc');
+
+echo "*** Testing gzopen() : variation ***\n";
+$thisTestDir = "gzopenVariation5.dir";
+mkdir($thisTestDir);
+chdir($thisTestDir);
+
+$newpath = relative_include_path();
+set_include_path($newpath);
+runtest();
+$newpath = generate_next_rel_path();
+set_include_path($newpath);
+runtest();
+
+teardown_relative_path();
+restore_include_path();
+chdir("..");
+rmdir($thisTestDir);
+
+function runtest() {
+ $tmpfile = 'gzopen_variation5.tmp';
+ $h = gzopen($tmpfile, "w", true);
+ fwrite($h, "This is the test file");
+ fclose($h);
+
+
+ $h = @gzopen($tmpfile, "r");
+ if ($h === false) {
+ echo "Not created in working dir\n";
+ }
+ else {
+ echo "created in working dir\n";
+ gzclose($h);
+ unlink($tmpfile);
+ }
+
+ $h = @gzopen('dir1/'.$tmpfile, "r");
+ if ($h === false) {
+ echo "Not created in dir1\n";
+ }
+ else {
+ echo "created in dir1\n";
+ gzclose($h);
+ unlink('dir1/'.$tmpfile);
+ }
+}
+?>
+===DONE===
+--EXPECT--
+*** Testing gzopen() : variation ***
+created in working dir
+Not created in dir1
+created in working dir
+Not created in dir1
+===DONE===
diff --git a/ext/zlib/tests/gzopen_variation6.phpt b/ext/zlib/tests/gzopen_variation6.phpt
new file mode 100644
index 0000000..9fe3f24
--- /dev/null
+++ b/ext/zlib/tests/gzopen_variation6.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Test gzopen() function : variation: relative/absolute file
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzopen() : variation ***\n";
+$absfile = __FILE__.'.tmp';
+$relfile = "gzopen_variation6.tmp";
+
+$h = gzopen($absfile, "w");
+gzwrite($h, "This is an absolute file");
+gzclose($h);
+
+$h = gzopen($relfile, "w");
+gzwrite($h, "This is a relative file");
+gzclose($h);
+
+$h = gzopen($absfile, "r");
+gzpassthru($h);
+fclose($h);
+echo "\n";
+
+$h = gzopen($relfile, "r");
+gzpassthru($h);
+gzclose($h);
+echo "\n";
+
+unlink($absfile);
+unlink($relfile);
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzopen() : variation ***
+This is an absolute file
+This is a relative file
+===DONE===
diff --git a/ext/zlib/tests/gzopen_variation7.phpt b/ext/zlib/tests/gzopen_variation7.phpt
new file mode 100644
index 0000000..92642b0
--- /dev/null
+++ b/ext/zlib/tests/gzopen_variation7.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test function gzopen() by calling it twice on the same file and not closing one of them at the end of the script
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h1 = gzopen($f, 'r');
+$h2 = gzopen($f, 'r');
+
+var_dump(gzread($h1, 30));
+var_dump(gzread($h2, 10));
+var_dump(gzread($h1, 15));
+gzclose($h1);
+var_dump(gzread($h2, 50));
+// deliberately do not close $h2
+?>
+===DONE===
+--EXPECT--
+string(30) "When you're taught through fee"
+string(10) "When you'r"
+string(15) "lings
+Destiny f"
+string(50) "e taught through feelings
+Destiny flying high abov"
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzopen_variation8.phpt b/ext/zlib/tests/gzopen_variation8.phpt
new file mode 100644
index 0000000..bb01262
--- /dev/null
+++ b/ext/zlib/tests/gzopen_variation8.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test gzopen() function : variation: opening a plain file
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzopen() : variation ***\n";
+
+$data = <<<EOT
+Here is some plain
+text to be read
+and displayed.
+EOT;
+
+$file = "gzopen_variation8.tmp";
+$h = fopen($file, 'w');
+fwrite($h, $data);
+fclose($h);
+
+$h = gzopen($file, 'r');
+gzpassthru($h);
+gzclose($h);
+echo "\n";
+unlink($file);
+?>
+===DONE===
+--EXPECT--
+*** Testing gzopen() : variation ***
+Here is some plain
+text to be read
+and displayed.
+===DONE===
diff --git a/ext/zlib/tests/gzopen_variation9.phpt b/ext/zlib/tests/gzopen_variation9.phpt
new file mode 100644
index 0000000..7a44b6e
--- /dev/null
+++ b/ext/zlib/tests/gzopen_variation9.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Test gzopen() function : variation: try opening with possibly invalid modes
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
+ * Description: Open a .gz-file and return a .gz-file pointer
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzopen() : variation ***\n";
+
+$modes = array('r+', 'rf', 'w+' , 'e');
+
+$file = dirname(__FILE__)."/004.txt.gz";
+
+foreach ($modes as $mode) {
+ echo "mode=$mode\n";
+ $h = gzopen($file, $mode);
+ echo "gzopen=";
+ var_dump($h);
+ if ($h !== false) {
+ gzclose($h);
+ }
+ echo "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzopen() : variation ***
+mode=r+
+
+Warning: gzopen(): cannot open a zlib stream for reading and writing at the same time! in %s on line %d
+gzopen=bool(false)
+
+mode=rf
+gzopen=resource(%d) of type (stream)
+
+mode=w+
+
+Warning: gzopen(): cannot open a zlib stream for reading and writing at the same time! in %s on line %d
+gzopen=bool(false)
+
+mode=e
+
+Warning: gzopen(%s/004.txt.gz): failed to open stream: %s in %s on line %d
+gzopen=bool(false)
+
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzpassthru_basic.phpt b/ext/zlib/tests/gzpassthru_basic.phpt
new file mode 100644
index 0000000..931c2b2
--- /dev/null
+++ b/ext/zlib/tests/gzpassthru_basic.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Test function gzpassthru() by calling it with its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+// note that gzpassthru is an alias to fpassthru. parameter checking tests will be
+// the same as fpassthru
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+var_dump(gzpassthru($h));
+var_dump(gzpassthru($h));
+gzclose($h);
+
+?>
+===DONE===
+--EXPECTF--
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+int(0)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzpassthru_error.phpt b/ext/zlib/tests/gzpassthru_error.phpt
new file mode 100644
index 0000000..18d72ef
--- /dev/null
+++ b/ext/zlib/tests/gzpassthru_error.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Test function gzpassthru() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$extra_arg = 'nothing';
+var_dump(gzpassthru( $h, $extra_arg ) );
+var_dump(gzpassthru() );
+gzclose($h);
+
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzpassthru() expects exactly 1 parameter, 2 given in %s on line %d
+bool(false)
+
+Warning: gzpassthru() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzputs_basic.phpt b/ext/zlib/tests/gzputs_basic.phpt
new file mode 100644
index 0000000..7566e74
--- /dev/null
+++ b/ext/zlib/tests/gzputs_basic.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test function gzputs() by calling it with its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$filename = dirname(__FILE__)."/temp.txt.gz";
+$h = gzopen($filename, 'w');
+$str = "Here is the string to be written. ";
+$length = 10;
+var_dump(gzputs( $h, $str ) );
+var_dump(gzputs( $h, $str, $length ) );
+gzclose($h);
+
+$h = gzopen($filename, 'r');
+gzpassthru($h);
+gzclose($h);
+echo "\n";
+unlink($filename);
+?>
+===DONE===
+--EXPECT--
+int(34)
+int(10)
+Here is the string to be written. Here is th
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzread_basic.phpt b/ext/zlib/tests/gzread_basic.phpt
new file mode 100644
index 0000000..ecb62a8
--- /dev/null
+++ b/ext/zlib/tests/gzread_basic.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Test function gzread() by calling it with its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+// note that gzread is an alias to fread. parameter checking tests will be
+// the same as fread
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$lengths = array(10, 14, 7, 99, 2000);
+
+foreach ($lengths as $length) {
+ var_dump(gzread( $h, $length ) );
+}
+gzclose($h);
+
+?>
+===DONE===
+--EXPECT--
+string(10) "When you'r"
+string(14) "e taught throu"
+string(7) "gh feel"
+string(99) "ings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns "
+string(46) "around
+and I know that it descends down on me
+"
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzread_error.phpt b/ext/zlib/tests/gzread_error.phpt
new file mode 100644
index 0000000..989e832
--- /dev/null
+++ b/ext/zlib/tests/gzread_error.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Test function gzread() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$length = 10;
+$extra_arg = 'nothing';
+
+var_dump(gzread( $h, $length, $extra_arg ) );
+
+var_dump(gzread());
+
+gzclose($h);
+
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzread() expects exactly 2 parameters, 3 given in %s on line %d
+bool(false)
+
+Warning: gzread() expects exactly 2 parameters, 0 given in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzread_error2.phpt b/ext/zlib/tests/gzread_error2.phpt
new file mode 100644
index 0000000..fae6356
--- /dev/null
+++ b/ext/zlib/tests/gzread_error2.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Test function gzread() by calling it invalid lengths
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+var_dump(gzread($h, 10));
+var_dump(gzread($h, 0));
+var_dump(gzread($h, 5));
+var_dump(gzread($h, -1));
+var_dump(gzread($h, 8));
+gzclose($h);
+
+?>
+===DONE===
+--EXPECTF--
+string(10) "When you'r"
+
+Warning: gzread(): Length parameter must be greater than 0 in %s on line %d
+bool(false)
+string(5) "e tau"
+
+Warning: gzread(): Length parameter must be greater than 0 in %s on line %d
+bool(false)
+string(8) "ght thro"
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzread_variation1.phpt b/ext/zlib/tests/gzread_variation1.phpt
new file mode 100644
index 0000000..1f50d77
--- /dev/null
+++ b/ext/zlib/tests/gzread_variation1.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test function gzread() by calling it while file open for writing
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$filename = "temp.txt.gz";
+$h = gzopen($filename, 'w');
+$str = "Here is the string to be written. ";
+var_dump(gzread($h, 100));
+gzwrite( $h, $str);
+var_dump(gzread($h, 100));
+gzrewind($h);
+var_dump(gzread($h, 100));
+gzclose($h);
+
+$h = gzopen($filename, 'r');
+gzpassthru($h);
+gzclose($h);
+echo "\n";
+unlink($filename);
+?>
+===DONE===
+--EXPECT--
+string(0) ""
+string(0) ""
+string(0) ""
+Here is the string to be written.
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzreadgzwrite.phpt b/ext/zlib/tests/gzreadgzwrite.phpt
new file mode 100644
index 0000000..71d728b
--- /dev/null
+++ b/ext/zlib/tests/gzreadgzwrite.phpt
@@ -0,0 +1,36 @@
+--TEST--
+gzopen(), gzread(), gzwrite()
+--SKIPIF--
+<?php # vim600:syn=php:
+if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+$original = str_repeat(b"hallo php",4096);
+$filename = tempnam("/tmp", "phpt");
+
+$fp = gzopen($filename, "wb");
+gzwrite($fp, $original);
+var_dump(strlen($original));
+var_dump(gztell($fp));
+fclose($fp);
+
+$fp = gzopen($filename, "rb");
+
+$data = '';
+while ($buf = gzread($fp, 8092)) {
+ $data .= $buf;
+}
+
+if ($data == $original) {
+ echo "Strings are equal\n";
+} else {
+ echo "Strings are not equal\n";
+ var_dump($data);
+}
+gzclose($fp);
+unlink($filename);
+?>
+--EXPECT--
+int(36864)
+int(36864)
+Strings are equal
diff --git a/ext/zlib/tests/gzreadgzwriteplain.phpt b/ext/zlib/tests/gzreadgzwriteplain.phpt
new file mode 100644
index 0000000..6a752b6
--- /dev/null
+++ b/ext/zlib/tests/gzreadgzwriteplain.phpt
@@ -0,0 +1,54 @@
+--TEST--
+gzopen(), gzread(), gzwrite() for non-compressed data
+--SKIPIF--
+<?php # vim600:syn=php:
+if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+$original = str_repeat(b"hallo php",4096);
+$filename = tempnam("/tmp", "phpt");
+
+$fp = fopen($filename, "wb");
+fwrite($fp, $original);
+var_dump(strlen($original));
+var_dump(ftell($fp));
+fclose($fp);
+
+$fp = gzopen($filename, "rb");
+
+$data = '';
+while ($buf = gzread($fp, 8192)) {
+ $data .= $buf;
+}
+
+if ($data == $original) {
+ echo "Strings are equal\n";
+} else {
+ echo "Strings are not equal\n";
+ var_dump($data);
+}
+
+gzseek($fp, strlen($original) / 2);
+
+$data = '';
+while ($buf = gzread($fp, 8192)) {
+ $data .= $buf;
+}
+
+var_dump(strlen($data));
+if ($data == substr($original, strlen($original) / 2)) {
+ echo "Strings are equal\n";
+} else {
+ echo "Strings are not equal\n";
+ var_dump($data);
+}
+
+gzclose($fp);
+unlink($filename);
+?>
+--EXPECT--
+int(36864)
+int(36864)
+Strings are equal
+int(18432)
+Strings are equal
diff --git a/ext/zlib/tests/gzrewind_basic.phpt b/ext/zlib/tests/gzrewind_basic.phpt
new file mode 100644
index 0000000..959f0fc
--- /dev/null
+++ b/ext/zlib/tests/gzrewind_basic.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Test function gzrewind() by calling it with its expected arguments when reading
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+echo "test rewind before doing anything\n";
+var_dump(gzrewind($h));
+var_dump(gztell($h));
+echo "\nfirst 30 characters=".gzread($h, 30)."\n";
+var_dump(gztell($h));
+gzrewind($h);
+var_dump(gztell($h));
+echo "first 10 characters=".gzread($h, 10)."\n";
+gzrewind($h);
+echo "first 20 characters=".gzread($h, 20)."\n";
+gzclose($h);
+?>
+===DONE===
+--EXPECT--
+test rewind before doing anything
+bool(true)
+int(0)
+
+first 30 characters=When you're taught through fee
+int(30)
+int(0)
+first 10 characters=When you'r
+first 20 characters=When you're taught t
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzrewind_basic2.phpt b/ext/zlib/tests/gzrewind_basic2.phpt
new file mode 100644
index 0000000..f51751c
--- /dev/null
+++ b/ext/zlib/tests/gzrewind_basic2.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test function gzrewind() by calling it with its expected arguments when reading
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+
+// read to the end of the file
+echo "read to the end of the file, then rewind\n";
+gzread($h, 10000);
+var_dump(gzeof($h));
+var_dump(gztell($h));
+gzrewind($h);
+var_dump(gzeof($h));
+var_dump(gztell($h));
+echo "first 20 characters=".gzread($h,20)."\n";
+
+gzclose($h);
+?>
+===DONE===
+--EXPECT--
+read to the end of the file, then rewind
+bool(true)
+int(176)
+bool(false)
+int(0)
+first 20 characters=When you're taught t
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzrewind_error.phpt b/ext/zlib/tests/gzrewind_error.phpt
new file mode 100644
index 0000000..3a1e4c9
--- /dev/null
+++ b/ext/zlib/tests/gzrewind_error.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test function gzrewind() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$extra_arg = 'nothing';
+var_dump(gzrewind( $h, $extra_arg ) );
+var_dump(gzrewind());
+gzclose($h);
+
+?>
+===DONE===
+--EXPECTF--
+Warning: gzrewind() expects exactly 1 parameter, 2 given in %s on line %d
+bool(false)
+
+Warning: gzrewind() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzrewind_variation1.phpt b/ext/zlib/tests/gzrewind_variation1.phpt
new file mode 100644
index 0000000..8201862
--- /dev/null
+++ b/ext/zlib/tests/gzrewind_variation1.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test function gzrewind() by calling it with its expected arguments when writing
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = "temp2.txt.gz";
+$h = gzopen($f, 'w');
+gzwrite($h, b'The first string.');
+var_dump(gzrewind($h));
+gzwrite($h, b'The second string.');
+gzclose($h);
+
+$h = gzopen($f, 'r');
+gzpassthru($h);
+gzclose($h);
+unlink($f);
+echo "\n";
+?>
+===DONE===
+--EXPECT--
+bool(false)
+The first string.The second string.
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzseek_basic.phpt b/ext/zlib/tests/gzseek_basic.phpt
new file mode 100644
index 0000000..d641bad
--- /dev/null
+++ b/ext/zlib/tests/gzseek_basic.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Test function gzseek() by calling it with its expected arguments when reading
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+
+echo "move to the 50th byte\n";
+var_dump(gzseek( $h, 50 ) );
+echo "tell=".gztell($h)."\n";
+//read the next 10
+var_dump(gzread($h, 10));
+
+echo "\nmove forward to the 100th byte\n";
+var_dump(gzseek( $h, 100 ) );
+echo "tell=".gztell($h)."\n";
+//read the next 10
+var_dump(gzread($h, 10));
+
+echo "\nmove backward to the 20th byte\n";
+var_dump(gzseek( $h, 20 ) );
+echo "tell=".gztell($h)."\n";
+//read the next 10
+var_dump(gzread($h, 10));
+gzclose($h);
+?>
+===DONE===
+--EXPECT--
+move to the 50th byte
+int(0)
+tell=50
+string(10) " high abov"
+
+move forward to the 100th byte
+int(0)
+tell=100
+string(10) "Destiny wh"
+
+move backward to the 20th byte
+int(0)
+tell=20
+string(10) "hrough fee"
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzseek_basic2.phpt b/ext/zlib/tests/gzseek_basic2.phpt
new file mode 100644
index 0000000..a815b8f
--- /dev/null
+++ b/ext/zlib/tests/gzseek_basic2.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test function gzseek() by calling it with its expected arguments when writing
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = "temp3.txt.gz";
+$h = gzopen($f, 'w');
+$str1 = "This is the first line.";
+$str2 = "This is the second line.";
+gzwrite($h, $str1);
+echo "tell=".gztell($h)."\n";
+
+//seek forwards 20 bytes.
+gzseek($h, strlen($str1) + 20);
+echo "tell=".gztell($h)."\n";
+gzwrite($h, $str2);
+echo "tell=".gztell($h)."\n";
+gzclose($h);
+echo "\nreading the output file\n";
+$h = gzopen($f, 'r');
+echo gzread($h, strlen($str1))."\n";
+echo var_dump(bin2hex(gzread($h, 20)));
+echo gzread($h, strlen($str2))."\n";
+gzclose($h);
+unlink($f);
+?>
+===DONE===
+--EXPECT--
+tell=23
+tell=43
+tell=67
+
+reading the output file
+This is the first line.
+string(40) "0000000000000000000000000000000000000000"
+This is the second line.
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzseek_error.phpt b/ext/zlib/tests/gzseek_error.phpt
new file mode 100644
index 0000000..ab6c965
--- /dev/null
+++ b/ext/zlib/tests/gzseek_error.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test function gzseek() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$offset = 1;
+$whence = SEEK_SET;
+$extra_arg = 'nothing';
+
+var_dump(gzseek( $h, $offset, $whence, $extra_arg ) );
+var_dump(gzseek($h));
+var_dump(gzseek());
+
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzseek() expects at most 3 parameters, 4 given in %s on line %d
+bool(false)
+
+Warning: gzseek() expects at least 2 parameters, 1 given in %s on line %d
+bool(false)
+
+Warning: gzseek() expects at least 2 parameters, 0 given in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzseek_variation1.phpt b/ext/zlib/tests/gzseek_variation1.phpt
new file mode 100644
index 0000000..301b57d
--- /dev/null
+++ b/ext/zlib/tests/gzseek_variation1.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test function gzseek() by seeking forward in write mode
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = "temp3.txt.gz";
+$h = gzopen($f, 'w');
+$str1 = "This is the first line.";
+$str2 = "This is the second line.";
+gzwrite($h, $str1);
+
+//seek forwards 20 bytes.
+gzseek($h, strlen($str1) + 20);
+gzwrite($h, $str2);
+gzclose($h);
+$h = gzopen($f, 'r');
+echo gzread($h, strlen($str1))."\n";
+echo var_dump(bin2hex(gzread($h, 20)));
+echo gzread($h, strlen($str2))."\n";
+gzclose($h);
+unlink($f);
+?>
+===DONE===
+--EXPECT--
+This is the first line.
+string(40) "0000000000000000000000000000000000000000"
+This is the second line.
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzseek_variation2.phpt b/ext/zlib/tests/gzseek_variation2.phpt
new file mode 100644
index 0000000..e70d6dd
--- /dev/null
+++ b/ext/zlib/tests/gzseek_variation2.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Test function gzseek() by calling it with SEEK_SET when reading
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+
+echo "move to the 50th byte\n";
+var_dump(gzseek( $h, 50, SEEK_SET ) );
+echo "tell=".gztell($h)."\n";
+//read the next 10
+var_dump(gzread($h, 10));
+
+echo "\nmove forward to the 100th byte\n";
+var_dump(gzseek( $h, 100, SEEK_SET ) );
+echo "tell=".gztell($h)."\n";
+//read the next 10
+var_dump(gzread($h, 10));
+
+echo "\nmove backward to the 20th byte\n";
+var_dump(gzseek( $h, 20, SEEK_SET ) );
+echo "tell=".gztell($h)."\n";
+//read the next 10
+var_dump(gzread($h, 10));
+gzclose($h);
+?>
+===DONE===
+--EXPECT--
+move to the 50th byte
+int(0)
+tell=50
+string(10) " high abov"
+
+move forward to the 100th byte
+int(0)
+tell=100
+string(10) "Destiny wh"
+
+move backward to the 20th byte
+int(0)
+tell=20
+string(10) "hrough fee"
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzseek_variation3.phpt b/ext/zlib/tests/gzseek_variation3.phpt
new file mode 100644
index 0000000..dee7c13
--- /dev/null
+++ b/ext/zlib/tests/gzseek_variation3.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Test function gzseek() by calling it with SEEK_CUR when reading
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+
+echo "move to the 50th byte\n";
+var_dump(gzseek( $h, 50, SEEK_CUR ) );
+echo "tell=".gztell($h)."\n";
+//read the next 10
+var_dump(gzread($h, 10));
+
+echo "\nmove forward to the 94th byte\n";
+var_dump(gzseek( $h, 34, SEEK_CUR ) );
+echo "tell=".gztell($h)."\n";
+//read the next 10
+var_dump(gzread($h, 10));
+
+echo "\nmove backward to the 77th byte\n";
+var_dump(gzseek( $h, -27, SEEK_CUR ) );
+echo "tell=".gztell($h)."\n";
+//read the next 10
+var_dump(gzread($h, 10));
+gzclose($h);
+?>
+===DONE===
+--EXPECT--
+move to the 50th byte
+int(0)
+tell=50
+string(10) " high abov"
+
+move forward to the 94th byte
+int(0)
+tell=94
+string(10) "ze it
+Dest"
+
+move backward to the 77th byte
+int(0)
+tell=77
+string(10) "hat you ca"
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzseek_variation4.phpt b/ext/zlib/tests/gzseek_variation4.phpt
new file mode 100644
index 0000000..fc641f6
--- /dev/null
+++ b/ext/zlib/tests/gzseek_variation4.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test function gzseek() by calling it with SEEK_SET when writing
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = "temp3.txt.gz";
+$h = gzopen($f, 'w');
+$str1 = "This is the first line.";
+$str2 = "This is the second line.";
+gzwrite($h, $str1);
+echo "tell=".gztell($h)."\n";
+
+//seek forwards 20 bytes.
+gzseek($h, strlen($str1) + 20, SEEK_SET);
+echo "tell=".gztell($h)."\n";
+gzwrite($h, $str2);
+echo "tell=".gztell($h)."\n";
+gzclose($h);
+echo "\nreading the output file\n";
+$h = gzopen($f, 'r');
+echo gzread($h, strlen($str1))."\n";
+echo var_dump(bin2hex(gzread($h, 20)));
+echo gzread($h, strlen($str2))."\n";
+gzclose($h);
+unlink($f);
+?>
+===DONE===
+--EXPECT--
+tell=23
+tell=43
+tell=67
+
+reading the output file
+This is the first line.
+string(40) "0000000000000000000000000000000000000000"
+This is the second line.
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzseek_variation5.phpt b/ext/zlib/tests/gzseek_variation5.phpt
new file mode 100644
index 0000000..0167e20
--- /dev/null
+++ b/ext/zlib/tests/gzseek_variation5.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test function gzseek() by calling it with SEEK_CUR when writing
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = "temp3.txt.gz";
+$h = gzopen($f, 'w');
+$str1 = "This is the first line.";
+$str2 = "This is the second line.";
+gzwrite($h, $str1);
+echo "tell=".gztell($h)."\n";
+
+//seek forwards 20 bytes.
+gzseek($h, 20, SEEK_CUR);
+echo "tell=".gztell($h)."\n";
+gzwrite($h, $str2);
+echo "tell=".gztell($h)."\n";
+gzclose($h);
+echo "\nreading the output file\n";
+$h = gzopen($f, 'r');
+echo gzread($h, strlen($str1))."\n";
+echo var_dump(bin2hex(gzread($h, 20)));
+echo gzread($h, strlen($str2))."\n";
+gzclose($h);
+unlink($f);
+?>
+===DONE===
+--EXPECT--
+tell=23
+tell=43
+tell=67
+
+reading the output file
+This is the first line.
+string(40) "0000000000000000000000000000000000000000"
+This is the second line.
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzseek_variation6.phpt b/ext/zlib/tests/gzseek_variation6.phpt
new file mode 100644
index 0000000..0c46309
--- /dev/null
+++ b/ext/zlib/tests/gzseek_variation6.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Test function gzseek() by calling it with SEEK_END when reading
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+// move 40 bytes
+echo "move 40 bytes\n";
+gzread($h, 40);
+echo "tell=";
+var_dump(gztell($h));
+echo "move to the end\n";
+var_dump(gzseek( $h, 0, SEEK_END ) );
+echo "tell=";
+var_dump(gztell($h));
+echo "eof=";
+var_dump(gzeof($h));
+//read the next 10
+var_dump(gzread($h, 10));
+gzclose($h);
+?>
+===DONE===
+--EXPECTF--
+move 40 bytes
+tell=int(40)
+move to the end
+
+Warning: gzseek(): SEEK_END is not supported in %s on line %d
+int(-1)
+tell=int(40)
+eof=bool(false)
+string(10) "iny flying"
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzseek_variation7.phpt b/ext/zlib/tests/gzseek_variation7.phpt
new file mode 100644
index 0000000..aab0834
--- /dev/null
+++ b/ext/zlib/tests/gzseek_variation7.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Test function gzseek() by calling it with SEEK_END when writing
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = "temp3.txt.gz";
+$h = gzopen($f, 'w');
+$str1 = "This is the first line.";
+$str2 = "This is the second line.";
+gzwrite($h, $str1);
+echo "tell=";
+var_dump(gztell($h));
+
+//seek to the end which is not sensible of course.
+echo "move to the end of the file\n";
+var_dump(gzseek($h, 0, SEEK_END));
+echo "tell=";
+var_dump(gztell($h));
+gzwrite($h, $str2);
+echo "tell=";
+var_dump(gztell($h));
+gzclose($h);
+echo "\nreading the output file\n";
+$h = gzopen($f, 'r');
+gzpassthru($h);
+gzclose($h);
+echo "\n";
+unlink($f);
+?>
+===DONE===
+--EXPECTF--
+tell=int(23)
+move to the end of the file
+
+Warning: gzseek(): SEEK_END is not supported in %s on line %d
+int(-1)
+tell=int(23)
+tell=int(47)
+
+reading the output file
+This is the first line.This is the second line.
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gztell_basic.phpt b/ext/zlib/tests/gztell_basic.phpt
new file mode 100644
index 0000000..b6baf42
--- /dev/null
+++ b/ext/zlib/tests/gztell_basic.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test function gztell() by calling it with its expected arguments when reading
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$intervals = array(7, 22, 54, 17, 27, 15, 1000);
+// tell should be 7, 29, 83, 100, 127, 142, 176 (176 is length of uncompressed file)
+
+var_dump(gztell($h));
+foreach ($intervals as $interval) {
+ gzread($h, $interval);
+ var_dump(gztell($h));
+}
+
+gzclose($h);
+?>
+===DONE===
+--EXPECT--
+int(0)
+int(7)
+int(29)
+int(83)
+int(100)
+int(127)
+int(142)
+int(176)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gztell_basic2.phpt b/ext/zlib/tests/gztell_basic2.phpt
new file mode 100644
index 0000000..a8574ee
--- /dev/null
+++ b/ext/zlib/tests/gztell_basic2.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test function gztell() by calling it with its expected arguments when writing
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = "temp2.txt.gz";
+$h = gzopen($f, 'w');
+$sizes = array(7, 22, 54, 17, 27, 15, 1000);
+// tell should be 7, 29, 83, 100, 127, 142, 1142
+
+var_dump(gztell($h));
+foreach ($sizes as $size) {
+ echo "bytes written=".gzwrite($h, str_repeat(b'1', $size))."\n";;
+ echo "tell=".gztell($h)."\n";
+}
+
+gzclose($h);
+unlink($f);
+?>
+===DONE===
+--EXPECT--
+int(0)
+bytes written=7
+tell=7
+bytes written=22
+tell=29
+bytes written=54
+tell=83
+bytes written=17
+tell=100
+bytes written=27
+tell=127
+bytes written=15
+tell=142
+bytes written=1000
+tell=1142
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gztell_error.phpt b/ext/zlib/tests/gztell_error.phpt
new file mode 100644
index 0000000..e207c59
--- /dev/null
+++ b/ext/zlib/tests/gztell_error.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test function gztell() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, 'r');
+$extra_arg = 'nothing';
+var_dump(gztell( $h, $extra_arg ) );
+var_dump(gztell());
+gzclose($h);
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gztell() expects exactly 1 parameter, 2 given in %s on line %d
+bool(false)
+
+Warning: gztell() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzuncompress_basic1.phpt b/ext/zlib/tests/gzuncompress_basic1.phpt
new file mode 100644
index 0000000..fa7f175
--- /dev/null
+++ b/ext/zlib/tests/gzuncompress_basic1.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test gzuncompress() function : basic functionality
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzuncompress(string data [, int length])
+ * Description: Unzip a gzip-compressed string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+include(dirname(__FILE__) . '/data.inc');
+
+echo "*** Testing gzuncompress() : basic functionality ***\n";
+
+
+// Initialise all required variables
+$compressed = gzcompress($data);
+
+echo "\n-- Basic decompress --\n";
+var_dump(strcmp($data, gzuncompress($compressed)));
+
+
+$length = 3547;
+echo "\n-- Calling gzuncompress() with max length of $length --\n";
+echo "Result length is ". strlen(gzuncompress($compressed, $length)) . "\n";
+
+?>
+===DONE===
+--EXPECT--
+*** Testing gzuncompress() : basic functionality ***
+
+-- Basic decompress --
+int(0)
+
+-- Calling gzuncompress() with max length of 3547 --
+Result length is 3547
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzuncompress_error1.phpt b/ext/zlib/tests/gzuncompress_error1.phpt
new file mode 100644
index 0000000..f26a4f5
--- /dev/null
+++ b/ext/zlib/tests/gzuncompress_error1.phpt
@@ -0,0 +1,80 @@
+--TEST--
+Test gzuncompress() function : error conditions
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+/* Prototype : string gzuncompress(string data [, int length])
+ * Description: Unzip a gzip-compressed string
+ * Source code: ext/zlib/zlib.c
+ * Alias to functions:
+ */
+
+echo "*** Testing gzuncompress() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing gzuncompress() function with Zero arguments --\n";
+var_dump( gzuncompress() );
+
+//Test gzuncompress with one more than the expected number of arguments
+echo "\n-- Testing gzuncompress() function with more than expected no. of arguments --\n";
+$data = 'string_val';
+$length = 10;
+$extra_arg = 10;
+var_dump( gzuncompress($data, $length, $extra_arg) );
+
+echo "\n-- Testing with a buffer that is too small --\n";
+$short_len = strlen($data) - 1;
+$compressed = gzcompress($data);
+
+var_dump(gzuncompress($compressed, $short_len));
+
+echo "\n-- Testing with incorrect arguments --\n";
+var_dump(gzuncompress(123));
+
+class Tester {
+ function Hello() {
+ echo "Hello\n";
+ }
+}
+
+$testclass = new Tester();
+var_dump(gzuncompress($testclass));
+
+var_dump(gzuncompress($compressed, "this is not a number\n"));
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing gzuncompress() : error conditions ***
+
+-- Testing gzuncompress() function with Zero arguments --
+
+Warning: gzuncompress() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing gzuncompress() function with more than expected no. of arguments --
+
+Warning: gzuncompress() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+
+-- Testing with a buffer that is too small --
+
+Warning: gzuncompress(): insufficient memory in %s on line %d
+bool(false)
+
+-- Testing with incorrect arguments --
+
+Warning: gzuncompress(): data error in %s on line %d
+bool(false)
+
+Warning: gzuncompress() expects parameter 1 to be string, object given in %s on line %d
+NULL
+
+Warning: gzuncompress() expects parameter 2 to be long, string given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/zlib/tests/gzwrite_basic.phpt b/ext/zlib/tests/gzwrite_basic.phpt
new file mode 100644
index 0000000..0d75216
--- /dev/null
+++ b/ext/zlib/tests/gzwrite_basic.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test function gzwrite() by calling it with its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$filename = "temp.txt.gz";
+$h = gzopen($filename, 'w');
+$str = "Here is the string to be written. ";
+$length = 10;
+var_dump(gzwrite( $h, $str ) );
+var_dump(gzwrite( $h, $str, $length ) );
+gzclose($h);
+
+$h = gzopen($filename, 'r');
+gzpassthru($h);
+gzclose($h);
+echo "\n";
+unlink($filename);
+?>
+===DONE===
+--EXPECT--
+int(34)
+int(10)
+Here is the string to be written. Here is th
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzwrite_error.phpt b/ext/zlib/tests/gzwrite_error.phpt
new file mode 100644
index 0000000..b84a1db
--- /dev/null
+++ b/ext/zlib/tests/gzwrite_error.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Test function gzwrite() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$filename = "temp.txt.gz";
+$h = gzopen($filename, 'w');
+$str = "Here is the string to be written. ";
+$length = 10;
+$extra_arg = 'nothing';
+var_dump(gzwrite($h, $str, $length, $extra_arg));
+var_dump(gzwrite($h));
+var_dump(gzwrite());
+
+gzclose($h);
+unlink($filename);
+
+?>
+===DONE===
+--EXPECTF--
+
+Warning: gzwrite() expects at most 3 parameters, 4 given in %s on line %d
+bool(false)
+
+Warning: gzwrite() expects at least 2 parameters, 1 given in %s on line %d
+bool(false)
+
+Warning: gzwrite() expects at least 2 parameters, 0 given in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzwrite_error2.phpt b/ext/zlib/tests/gzwrite_error2.phpt
new file mode 100644
index 0000000..6912750
--- /dev/null
+++ b/ext/zlib/tests/gzwrite_error2.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Test function gzwrite() by calling it invalid lengths
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$filename = "temp.txt.gz";
+$h = gzopen($filename, 'w');
+$str = "Here is the string to be written. ";
+var_dump(gzwrite( $h, $str, 0 ) );
+var_dump(gzwrite( $h, $str, -1 ) );
+gzclose($h);
+
+$h = gzopen($filename, 'r');
+gzpassthru($h);
+gzclose($h);
+echo "\n";
+unlink($filename);
+?>
+===DONE===
+--EXPECT--
+int(0)
+int(0)
+
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/gzwrite_variation1.phpt b/ext/zlib/tests/gzwrite_variation1.phpt
new file mode 100644
index 0000000..ab6c260
--- /dev/null
+++ b/ext/zlib/tests/gzwrite_variation1.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test function gzwrite() by calling it when file is opened for reading
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($filename, 'r');
+$str = b"Here is the string to be written. ";
+$length = 10;
+var_dump(gzwrite( $h, $str ) );
+var_dump(gzread($h, 10));
+var_dump(gzwrite( $h, $str, $length ) );
+gzclose($h);
+
+?>
+===DONE===
+--EXPECT--
+int(0)
+string(10) "When you'r"
+int(0)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/ob_001.phpt b/ext/zlib/tests/ob_001.phpt
new file mode 100644
index 0000000..b074a4f
--- /dev/null
+++ b/ext/zlib/tests/ob_001.phpt
@@ -0,0 +1,20 @@
+--TEST--
+zlib.output_compression
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi");
+?>
+--GET--
+a=b
+--INI--
+zlib.output_compression=1
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--FILE--
+<?php
+echo "hi\n";
+?>
+--EXPECTF--
+‹%s
+
diff --git a/ext/zlib/tests/ob_002.phpt b/ext/zlib/tests/ob_002.phpt
new file mode 100644
index 0000000..53cf25c
--- /dev/null
+++ b/ext/zlib/tests/ob_002.phpt
@@ -0,0 +1,18 @@
+--TEST--
+zlib.output_compression
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+?>
+--INI--
+zlib.output_compression=1
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--FILE--
+<?php
+ini_set("zlib.output_compression", 0);
+echo "hi\n";
+?>
+--EXPECTF--
+hi
+
diff --git a/ext/zlib/tests/ob_003.phpt b/ext/zlib/tests/ob_003.phpt
new file mode 100644
index 0000000..7142df7
--- /dev/null
+++ b/ext/zlib/tests/ob_003.phpt
@@ -0,0 +1,23 @@
+--TEST--
+zlib.output_compression
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi");
+?>
+--INI--
+zlib.output_compression=0
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--POST--
+dummy=42
+--FILE--
+<?php
+ini_set("zlib.output_compression", 1);
+echo "hi\n";
+?>
+--EXPECTF--
+‹%s
+--EXPECTHEADERS--
+Content-Encoding: gzip
+Vary: Accept-Encoding
diff --git a/ext/zlib/tests/ob_004.phpt b/ext/zlib/tests/ob_004.phpt
new file mode 100644
index 0000000..f5e6af5
--- /dev/null
+++ b/ext/zlib/tests/ob_004.phpt
@@ -0,0 +1,24 @@
+--TEST--
+ob_gzhandler
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi");
+?>
+--INI--
+zlib.output_compression=0
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--POST--
+dummy=42
+--FILE--
+<?php
+ob_start("ob_gzhandler");
+echo "hi\n";
+?>
+--EXPECTF--
+‹%s
+--EXPECTHEADERS--
+Content-Encoding: gzip
+Vary: Accept-Encoding
+
diff --git a/ext/zlib/tests/ob_005.phpt b/ext/zlib/tests/ob_005.phpt
new file mode 100644
index 0000000..1979393
--- /dev/null
+++ b/ext/zlib/tests/ob_005.phpt
@@ -0,0 +1,22 @@
+--TEST--
+ob_gzhandler
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi");
+?>
+--INI--
+zlib.output_compression=0
+--ENV--
+HTTP_ACCEPT_ENCODING=gzip
+--POST--
+dummy=42
+--FILE--
+<?php
+ob_start("ob_gzhandler");
+ini_set("zlib.output_compression", 0);
+echo "hi\n";
+?>
+--EXPECTF--
+hi
+--EXPECTHEADERS--
diff --git a/ext/zlib/tests/ob_gzhandler_legacy_002.phpt b/ext/zlib/tests/ob_gzhandler_legacy_002.phpt
new file mode 100644
index 0000000..dad2821
--- /dev/null
+++ b/ext/zlib/tests/ob_gzhandler_legacy_002.phpt
@@ -0,0 +1,24 @@
+--TEST--
+ob_gzhandler legacy
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) die("skip need ext/zlib");
+if (false === stristr(PHP_SAPI, "cgi")) die("skip need sapi/cgi");
+?>
+--INI--
+zlib.output_compression=0
+--ENV--
+HTTP_ACCEPT_ENCODING=
+--POST--
+dummy=42
+--FILE--
+<?php
+if (false !== ob_gzhandler("", PHP_OUTPUT_HANDLER_START)) {
+ ini_set("zlib.output_compression", 0);
+ ob_start("ob_gzhandler");
+}
+echo "hi\n";
+?>
+--EXPECTF--
+hi
+--EXPECTHEADERS--
diff --git a/ext/zlib/tests/readgzfile_basic.phpt b/ext/zlib/tests/readgzfile_basic.phpt
new file mode 100644
index 0000000..2d180c1
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_basic.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test function readgzfile() reading a gzip relative file
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+$plaintxt = b<<<EOT
+hello world
+is a very common test
+for all languages
+
+EOT;
+$dirname = 'readgzfile_temp';
+$filename = $dirname.'/plainfile.txt.gz';
+mkdir($dirname);
+$h = gzopen($filename, 'w');
+gzwrite($h, $plaintxt);
+gzclose($h);
+
+
+var_dump(readgzfile( $filename ) );
+
+unlink($filename);
+rmdir($dirname);
+?>
+===DONE===
+--EXPECT--
+hello world
+is a very common test
+for all languages
+int(52)
+===DONE===
diff --git a/ext/zlib/tests/readgzfile_basic2.phpt b/ext/zlib/tests/readgzfile_basic2.phpt
new file mode 100644
index 0000000..99d216a
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_basic2.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test function readgzfile() reading a plain relative file
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+$plaintxt = b<<<EOT
+hello world
+is a very common test
+for all languages
+
+EOT;
+$dirname = 'readgzfile_temp';
+$filename = $dirname.'/plainfile.txt';
+mkdir($dirname);
+$h = fopen($filename, 'w');
+fwrite($h, $plaintxt);
+fclose($h);
+
+
+var_dump(readgzfile( $filename ) );
+
+unlink($filename);
+rmdir($dirname);
+?>
+===DONE===
+--EXPECT--
+hello world
+is a very common test
+for all languages
+int(52)
+===DONE===
diff --git a/ext/zlib/tests/readgzfile_error.phpt b/ext/zlib/tests/readgzfile_error.phpt
new file mode 100644
index 0000000..4ec76d0
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_error.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Test function readgzfile() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+$use_include_path = false;
+$extra_arg = 'nothing';
+
+var_dump(readgzfile( $filename, $use_include_path, $extra_arg ) );
+
+var_dump(readgzfile( ) );
+
+
+?>
+===DONE===
+--EXPECTF--
+
+Warning: readgzfile() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+
+Warning: readgzfile() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation1.phpt b/ext/zlib/tests/readgzfile_variation1.phpt
new file mode 100644
index 0000000..e31824c
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation1.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test function readgzfile() by substituting agument 1 with array values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+$index_array = array(1, 2, 3);
+$assoc_array = array(1 => 'one', 2 => 'two');
+
+$variation = array(
+ 'empty array' => array(),
+ 'int indexed array' => $index_array,
+ 'associative array' => $assoc_array,
+ 'nested arrays' => array('foo', $index_array, $assoc_array),
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+
+Warning: readgzfile() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 1 to be string, array given in %s on line %d
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation10.phpt b/ext/zlib/tests/readgzfile_variation10.phpt
new file mode 100644
index 0000000..29249a1
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation10.phpt
@@ -0,0 +1,67 @@
+--TEST--
+Test function readgzfile() by substituting agument 2 with emptyUnsetUndefNull values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+
+
+$unset_var = 10;
+unset($unset_var);
+
+$variation = array(
+ 'unset var' => @$unset_var,
+ 'undefined var' => @$undefined_var,
+ 'empty string DQ' => "",
+ 'empty string SQ' => '',
+ 'uppercase NULL' => NULL,
+ 'lowercase null' => null,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECTF--
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+
+Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation11.phpt b/ext/zlib/tests/readgzfile_variation11.phpt
new file mode 100644
index 0000000..4023211
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation11.phpt
@@ -0,0 +1,64 @@
+--TEST--
+Test function readgzfile() by substituting agument 2 with float values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+
+
+$variation = array(
+ 'float 10.5' => 10.5,
+ 'float -10.5' => -10.5,
+ 'float 12.3456789000e10' => 12.3456789000e10,
+ 'float -12.3456789000e10' => -12.3456789000e10,
+ 'float .5' => .5,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECT--
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation12.phpt b/ext/zlib/tests/readgzfile_variation12.phpt
new file mode 100644
index 0000000..8c291a4
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation12.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Test function readgzfile() by substituting agument 2 with int values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+
+
+$variation = array (
+ 'int 0' => 0,
+ 'int 1' => 1,
+ 'int 12345' => 12345,
+ 'int -12345' => -2345,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECT--
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation13.phpt b/ext/zlib/tests/readgzfile_variation13.phpt
new file mode 100644
index 0000000..117860e
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation13.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Test function readgzfile() by substituting agument 2 with object values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = $filename = dirname(__FILE__)."/004.txt.gz";
+
+
+function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
+ if (error_reporting() != 0) {
+ // report non-silenced errors
+ echo "Error: $err_no - $err_msg, $filename($linenum)\n";
+ }
+}
+set_error_handler('test_error_handler');
+
+
+
+class classWithToString
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+class classWithoutToString
+{
+}
+
+$variation = array(
+ 'instance of classWithToString' => new classWithToString(),
+ 'instance of classWithoutToString' => new classWithoutToString(),
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECTF--
+Error: 2 - readgzfile() expects parameter 2 to be long, object given, %s(%d)
+NULL
+Error: 2 - readgzfile() expects parameter 2 to be long, object given, %s(%d)
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation14.phpt b/ext/zlib/tests/readgzfile_variation14.phpt
new file mode 100644
index 0000000..ee0d6d6
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation14.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Test function readgzfile() by substituting agument 2 with string values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = $filename = dirname(__FILE__)."/004.txt.gz";
+
+
+$heredoc = <<<EOT
+hello world
+EOT;
+
+$variation_array = array(
+ 'string DQ' => "string",
+ 'string SQ' => 'string',
+ 'mixed case string' => "sTrInG",
+ 'heredoc' => $heredoc
+ );
+
+
+foreach ( $variation_array as $var ) {
+ var_dump(readgzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECTF--
+
+Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 2 to be long, string given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/zlib/tests/readgzfile_variation15.phpt b/ext/zlib/tests/readgzfile_variation15.phpt
new file mode 100644
index 0000000..36ff6ff
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation15.phpt
@@ -0,0 +1,94 @@
+--TEST--
+Test readgzfile() function : variation: use include path (relative directories in path)
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+require_once('reading_include_path.inc');
+
+//define the files to go into these directories, create one in dir2
+set_include_path($newIncludePath);
+test_readgzfile();
+restore_include_path();
+
+// remove the directory structure
+chdir($baseDir);
+rmdir($workingDir);
+foreach($newdirs as $newdir) {
+ rmdir($newdir);
+}
+
+chdir("..");
+rmdir($thisTestDir);
+
+function test_readgzfile() {
+ global $scriptFile, $secondFile, $firstFile, $filename;
+
+ // create a file in the middle directory
+ $h = gzopen($secondFile, "w");
+ gzwrite($h, "This is a file in dir2");
+ gzclose($h);
+
+ // should read dir2 file
+ echo "file content:";
+ readgzfile($filename, true);
+ echo "\n";
+
+ //create a file in dir1
+ $h = gzopen($firstFile, "w");
+ gzwrite($h, "This is a file in dir1");
+ gzclose($h);
+
+ //should now read dir1 file
+ echo "file content:";
+ readgzfile($filename, true);
+ echo "\n";
+
+ // create a file in working directory
+ $h = gzopen($filename, "w");
+ gzwrite($h, "This is a file in working dir");
+ gzclose($h);
+
+ //should still read dir1 file
+ echo "file content:";
+ readgzfile($filename, true);
+ echo "\n";
+
+ unlink($firstFile);
+ unlink($secondFile);
+
+ //should read the file in working dir
+ echo "file content:";
+ readgzfile($filename, true);
+ echo "\n";
+
+ // create a file in the script directory
+ $h = gzopen($scriptFile, "w");
+ gzwrite($h, "This is a file in script dir");
+ gzclose($h);
+
+ //should read the file in script dir
+ echo "file content:";
+ readgzfile($filename, true);
+ echo "\n";
+
+ //cleanup
+ unlink($filename);
+ unlink($scriptFile);
+
+}
+
+?>
+===DONE===
+--EXPECT--
+file content:This is a file in dir2
+file content:This is a file in dir1
+file content:This is a file in dir1
+file content:This is a file in working dir
+file content:This is a file in script dir
+===DONE===
+
diff --git a/ext/zlib/tests/readgzfile_variation2.phpt b/ext/zlib/tests/readgzfile_variation2.phpt
new file mode 100644
index 0000000..367cc40
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation2.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test function readgzfile() by substituting agument 1 with boolean values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path =
+
+
+$variation = array(
+ 'lowercase true' => true,
+ 'lowercase false' =>false,
+ 'uppercase TRUE' =>TRUE,
+ 'uppercase FALSE' =>FALSE,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+
+Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation3.phpt b/ext/zlib/tests/readgzfile_variation3.phpt
new file mode 100644
index 0000000..6645d67
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation3.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Test function readgzfile() by substituting agument 1 with emptyUnsetUndefNull values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+$unset_var = 10;
+unset($unset_var);
+
+$variation = array(
+ 'unset var' => @$unset_var,
+ 'undefined var' => @$undefined_var,
+ 'empty string DQ' => "",
+ 'empty string SQ' => '',
+ 'uppercase NULL' => NULL,
+ 'lowercase null' => null,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+Warning: readgzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: readgzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: readgzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: readgzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: readgzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: readgzfile(): Filename cannot be empty in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation4.phpt b/ext/zlib/tests/readgzfile_variation4.phpt
new file mode 100644
index 0000000..ece84a9
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation4.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test function readgzfile() by substituting agument 1 with float values.
+--SKIPIF--
+<?php
+if (!extension_loaded(zlib)) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+$variation = array(
+ 'float 10.5' => 10.5,
+ 'float -10.5' => -10.5,
+ 'float 12.3456789000e10' => 12.3456789000e10,
+ 'float -12.3456789000e10' => -12.3456789000e10,
+ 'float .5' => .5,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+Warning: readgzfile(10.5): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: readgzfile(-10.5): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: readgzfile(123456789000): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: readgzfile(-123456789000): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: readgzfile(0.5): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/zlib/tests/readgzfile_variation5.phpt b/ext/zlib/tests/readgzfile_variation5.phpt
new file mode 100644
index 0000000..460e188
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation5.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Test function readgzfile() by substituting agument 1 with int values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+$variation = array (
+ 'int 0' => 0,
+ 'int 1' => 1,
+ 'int 12345' => 12345,
+ 'int -12345' => -2345,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+Warning: readgzfile(0): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: readgzfile(1): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: readgzfile(12345): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: readgzfile(-2345): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/zlib/tests/readgzfile_variation6.phpt b/ext/zlib/tests/readgzfile_variation6.phpt
new file mode 100644
index 0000000..69a4dc1
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation6.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Test function readgzfile() by substituting agument 1 with object values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
+ if (error_reporting() != 0) {
+ // report non-silenced errors
+ echo "Error: $err_no - $err_msg, $filename($linenum)\n";
+ }
+}
+set_error_handler('test_error_handler');
+
+
+
+class classWithToString
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+class classWithoutToString
+{
+}
+
+$variation = array(
+ 'instance of classWithToString' => new classWithToString(),
+ 'instance of classWithoutToString' => new classWithoutToString(),
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $var , $use_include_path ) );
+}
+?>
+--EXPECTF--
+Error: 2 - readgzfile(Class A object): failed to open stream: No such file or directory, %s(%d)
+bool(false)
+Error: 2 - readgzfile() expects parameter 1 to be string, object given, %s(%d)
+NULL \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation7.phpt b/ext/zlib/tests/readgzfile_variation7.phpt
new file mode 100644
index 0000000..20162b5
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation7.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test function readgzfile() by substituting agument 1 with string values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$use_include_path = false;
+
+
+$heredoc = <<<EOT
+hello world
+EOT;
+
+$variation_array = array(
+ 'string DQ' => "string",
+ 'string SQ' => 'string',
+ 'mixed case string' => "sTrInG",
+ 'heredoc' => $heredoc
+ );
+
+
+foreach ( $variation_array as $var ) {
+ var_dump(readgzfile( $var , $use_include_path ) );
+}
+?>
+===DONE===
+--EXPECTF--
+Warning: readgzfile(string): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: readgzfile(string): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: readgzfile(sTrInG): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: readgzfile(hello world): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/zlib/tests/readgzfile_variation8.phpt b/ext/zlib/tests/readgzfile_variation8.phpt
new file mode 100644
index 0000000..2e15528
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation8.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test function readgzfile() by substituting agument 2 with array values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+
+
+$index_array = array(1, 2, 3);
+$assoc_array = array(1 => 'one', 2 => 'two');
+
+$variation = array(
+ 'empty array' => array(),
+ 'int indexed array' => $index_array,
+ 'associative array' => $assoc_array,
+ 'nested arrays' => array('foo', $index_array, $assoc_array),
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECTF--
+
+Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+Warning: readgzfile() expects parameter 2 to be long, array given in %s on line %d
+NULL
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/readgzfile_variation9.phpt b/ext/zlib/tests/readgzfile_variation9.phpt
new file mode 100644
index 0000000..5cdb5b5
--- /dev/null
+++ b/ext/zlib/tests/readgzfile_variation9.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Test function readgzfile() by substituting agument 2 with boolean values.
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build');
+?>
+--FILE--
+<?php
+
+
+$filename = dirname(__FILE__)."/004.txt.gz";
+
+$variation = array(
+ 'lowercase true' => true,
+ 'lowercase false' =>false,
+ 'uppercase TRUE' =>TRUE,
+ 'uppercase FALSE' =>FALSE,
+ );
+
+
+foreach ( $variation as $var ) {
+ var_dump(readgzfile( $filename, $var ) );
+}
+?>
+===DONE===
+--EXPECT--
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+int(176)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/reading_include_path.inc b/ext/zlib/tests/reading_include_path.inc
new file mode 100644
index 0000000..ee71bb9
--- /dev/null
+++ b/ext/zlib/tests/reading_include_path.inc
@@ -0,0 +1,27 @@
+<?php
+$thisTestDir = "zlibVariation.dir";
+mkdir($thisTestDir);
+chdir($thisTestDir);
+
+//create the include directory structure
+$workingDir = "workdir";
+$filename = "afile.txt.gz";
+$scriptDir = dirname(__FILE__);
+$baseDir = getcwd();
+$secondFile = $baseDir."/dir2/".$filename;
+$firstFile = "../dir1/".$filename;
+$scriptFile = $scriptDir.'/'.$filename;
+
+$newdirs = array("dir1", "dir2", "dir3");
+$pathSep = ":";
+$newIncludePath = "";
+if(substr(PHP_OS, 0, 3) == 'WIN' ) {
+ $pathSep = ";";
+}
+foreach($newdirs as $newdir) {
+ mkdir($newdir);
+ $newIncludePath .= '../'.$newdir.$pathSep;
+}
+mkdir($workingDir);
+chdir($workingDir);
+?> \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_filter_deflate.phpt b/ext/zlib/tests/zlib_filter_deflate.phpt
new file mode 100644
index 0000000..1811779
--- /dev/null
+++ b/ext/zlib/tests/zlib_filter_deflate.phpt
@@ -0,0 +1,17 @@
+--TEST--
+zlib.deflate (with convert.base64-encode)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php /* $Id$ */
+$text = 'I am the very model of a modern major general, I\'ve information vegetable, animal, and mineral.';
+
+$fp = fopen('php://stdout', 'w');
+stream_filter_append($fp, 'zlib.deflate', STREAM_FILTER_WRITE);
+stream_filter_append($fp, 'convert.base64-encode', STREAM_FILTER_WRITE);
+fwrite($fp, $text);
+fclose($fp);
+
+?>
+--EXPECT--
+HctBDoAgDETRq8zOjfEeHKOGATG0TRpC4u1Vdn/xX4IoxkVMxgP1zA4vkJVhULk9UGkM6TvSNolmxUNlNLePVQ45O3eINf0fsQxtCxwv
diff --git a/ext/zlib/tests/zlib_filter_deflate2.phpt b/ext/zlib/tests/zlib_filter_deflate2.phpt
new file mode 100644
index 0000000..764a760
--- /dev/null
+++ b/ext/zlib/tests/zlib_filter_deflate2.phpt
@@ -0,0 +1,16 @@
+--TEST--
+zlib.deflate (with level parameter set)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+$text = 'I am the very model of a modern major general, I\'ve information vegetable, animal, and mineral.';
+
+$fp = fopen('php://stdout', 'w');
+stream_filter_append($fp, 'zlib.deflate', STREAM_FILTER_WRITE, array('level' => 9));
+fwrite($fp, $text);
+fclose($fp);
+
+?>
+--EXPECT--
+ËA€ DÑ«ÌÎñ£†1´MBâíUvñ_‚(ÆELÆõÌ/•aP¹=Pi é;Ò6‰fÅCe4·U9;wˆ5ý± m /
diff --git a/ext/zlib/tests/zlib_filter_inflate.phpt b/ext/zlib/tests/zlib_filter_inflate.phpt
new file mode 100644
index 0000000..026f192
--- /dev/null
+++ b/ext/zlib/tests/zlib_filter_inflate.phpt
@@ -0,0 +1,17 @@
+--TEST--
+zlib.inflate (with convert.base64-decode)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php /* $Id$ */
+$text = 'HctBDoAgDETRq8zOjfEeHKOGATG0TRpC4u1Vdn/xX4IoxkVMxgP1zA4vkJVhULk9UGkM6TvSNolmxUNlNLePVQ45O3eINf0fsQxtCxwv';
+
+$fp = fopen('php://stdout', 'w');
+stream_filter_append($fp, 'convert.base64-decode', STREAM_FILTER_WRITE);
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_WRITE);
+fwrite($fp, $text);
+fclose($fp);
+
+?>
+--EXPECT--
+I am the very model of a modern major general, I've information vegetable, animal, and mineral.
diff --git a/ext/zlib/tests/zlib_filter_inflate2.phpt b/ext/zlib/tests/zlib_filter_inflate2.phpt
new file mode 100644
index 0000000..a2099b6
--- /dev/null
+++ b/ext/zlib/tests/zlib_filter_inflate2.phpt
@@ -0,0 +1,41 @@
+--TEST--
+zlib.inflate of gzip-encoded stream
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php /* $Id$ */
+
+$a = gzopen(dirname(__FILE__) . '/test.txt.gz', 'w');
+fwrite($a, b"This is quite the thing ain't it\n");
+fclose($a);
+
+$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
+echo fread($fp, 2000);
+fclose($fp);
+echo "1\n";
+$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
+// zlib format
+$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ, array('window' => 15+16));
+echo "2\n";
+echo fread($fp, 2000);
+fclose($fp);
+// auto-detect
+$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ, array('window' => 15+32));
+echo "3\n";
+echo fread($fp, 2000);
+fclose($fp);
+
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/test.txt.gz');
+?>
+--EXPECT--
+1
+2
+This is quite the thing ain't it
+3
+This is quite the thing ain't it
diff --git a/ext/zlib/tests/zlib_scheme_copy_basic.phpt b/ext/zlib/tests/zlib_scheme_copy_basic.phpt
new file mode 100644
index 0000000..028c029
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_copy_basic.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Test compress.zlib:// scheme with the copy function: compressed to compressed
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$outputFileName = __FILE__.'.tmp';
+
+$srcFile = "compress.zlib://$inputFileName";
+$destFile = "compress.zlib://$outputFileName";
+copy($srcFile, $destFile);
+
+$h = gzopen($inputFileName, 'r');
+$org_data = gzread($h, 4096);
+gzclose($h);
+
+$h = gzopen($outputFileName, 'r');
+$copied_data = gzread($h, 4096);
+gzclose($h);
+
+if ($org_data == $copied_data) {
+ echo "OK: Copy identical\n";
+}
+else {
+ echo "FAILED: Copy not identical";
+}
+unlink($outputFileName);
+?>
+===DONE===
+--EXPECT--
+OK: Copy identical
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_copy_variation1.phpt b/ext/zlib/tests/zlib_scheme_copy_variation1.phpt
new file mode 100644
index 0000000..3c997ef
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_copy_variation1.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Test compress.zlib:// scheme with the copy function: compressed to uncompressed
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$outputFileName = __FILE__.'.tmp';
+
+$srcFile = "compress.zlib://$inputFileName";
+$destFile = $outputFileName;
+copy($srcFile, $destFile);
+
+$h = gzopen($inputFileName, 'r');
+$org_data = gzread($h, 4096);
+gzclose($h);
+
+// can only read uncompressed data
+$h = fopen($outputFileName, 'r');
+$copied_data = fread($h, 4096);
+gzclose($h);
+
+if ($org_data == $copied_data) {
+ echo "OK: Copy identical\n";
+}
+else {
+ echo "FAILED: Copy not identical";
+}
+unlink($outputFileName);
+?>
+===DONE===
+--EXPECT--
+OK: Copy identical
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_copy_variation2.phpt b/ext/zlib/tests/zlib_scheme_copy_variation2.phpt
new file mode 100644
index 0000000..0b56ec4
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_copy_variation2.phpt
@@ -0,0 +1,53 @@
+--TEST--
+Test compress.zlib:// scheme with the copy function: uncompressed to compressed
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$org_data = <<<EOT
+uncompressed contents of 004.txt.gz is:
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+EOT;
+
+$inputFileName = __FILE__.'.org';
+$outputFileName = __FILE__.'.tmp';
+
+file_put_contents($inputFileName, $org_data);
+
+$srcFile = $inputFileName;
+$destFile = "compress.zlib://$outputFileName";
+copy($srcFile, $destFile);
+
+$h = gzopen($outputFileName, 'r');
+$copied_data = gzread($h, 4096);
+gzclose($h);
+
+//gzopen can read compressed and uncompressed so we
+//also need to look for the magic number (x1f x8b) to prove it
+//was compressed.
+$h = fopen($outputFileName, 'r');
+$magic = fread($h, 2);
+fclose($h);
+
+if ($org_data == $copied_data && bin2hex($magic) === '1f8b') {
+ echo "OK: Copy identical\n";
+}
+else {
+ echo "FAILED: Copy not identical\n";
+}
+unlink($inputFileName);
+unlink($outputFileName);
+?>
+===DONE===
+--EXPECT--
+OK: Copy identical
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_dir_basic.phpt b/ext/zlib/tests/zlib_scheme_dir_basic.phpt
new file mode 100644
index 0000000..02fe4fd
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_dir_basic.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test compress.zlib:// scheme with the directory functions
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/dir.gz";
+$srcFile = "compress.zlib://$inputFileName";
+var_dump(mkdir($srcFile));
+var_dump(is_dir($srcFile));
+var_dump(opendir($srcFile));
+var_dump(rmdir($srcFile));
+?>
+===DONE===
+--EXPECTF--
+bool(false)
+bool(false)
+
+Warning: opendir(compress.zlib://%s/dir.gz): failed to open dir: not implemented in %s on line %d
+bool(false)
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_file_basic.phpt b/ext/zlib/tests/zlib_scheme_file_basic.phpt
new file mode 100644
index 0000000..b8b60e4
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_file_basic.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Test compress.zlib:// scheme with the file
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$srcFile = "compress.zlib://$inputFileName";
+$contents = file($srcFile);
+var_dump($contents);
+?>
+===DONE===
+--EXPECT--
+array(6) {
+ [0]=>
+ string(36) "When you're taught through feelings
+"
+ [1]=>
+ string(26) "Destiny flying high above
+"
+ [2]=>
+ string(38) "all I know is that you can realize it
+"
+ [3]=>
+ string(18) "Destiny who cares
+"
+ [4]=>
+ string(19) "as it turns around
+"
+ [5]=>
+ string(39) "and I know that it descends down on me
+"
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_file_get_contents_basic.phpt b/ext/zlib/tests/zlib_scheme_file_get_contents_basic.phpt
new file mode 100644
index 0000000..c679c46
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_file_get_contents_basic.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Test compress.zlib:// scheme with the file_get_contents
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$srcFile = "compress.zlib://$inputFileName";
+$contents = file_get_contents($srcFile);
+echo $contents;
+?>
+===DONE===
+--EXPECT--
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_file_put_contents_basic.phpt b/ext/zlib/tests/zlib_scheme_file_put_contents_basic.phpt
new file mode 100644
index 0000000..8ea41df
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_file_put_contents_basic.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test compress.zlib:// scheme with the file_get_contents
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$outputFileName = __FILE__.'tmp';
+$outFile = "compress.zlib://$outputFileName";
+$data = <<<EOT
+Here is some plain
+text to be read
+and displayed.
+EOT;
+
+file_put_contents($outFile, $data);
+$h = gzopen($outputFileName, 'r');
+gzpassthru($h);
+gzclose($h);
+echo "\n";
+unlink($outputFileName);
+?>
+===DONE===
+--EXPECT--
+Here is some plain
+text to be read
+and displayed.
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_file_read_file_basic.phpt b/ext/zlib/tests/zlib_scheme_file_read_file_basic.phpt
new file mode 100644
index 0000000..ef44292
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_file_read_file_basic.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Test compress.zlib:// scheme with the file_get_contents
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$srcFile = "compress.zlib://$inputFileName";
+readfile($srcFile);
+?>
+===DONE===
+--EXPECT--
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_fopen_basic.phpt b/ext/zlib/tests/zlib_scheme_fopen_basic.phpt
new file mode 100644
index 0000000..d6d4514
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_fopen_basic.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Test compress.zlib:// scheme with the fopen
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$srcFile = "compress.zlib://$inputFileName";
+$h = fopen($srcFile, 'r');
+fpassthru($h);
+fclose($h);
+?>
+===DONE===
+--EXPECT--
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_fopen_variation1.phpt b/ext/zlib/tests/zlib_scheme_fopen_variation1.phpt
new file mode 100644
index 0000000..8c26492
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_fopen_variation1.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Test compress.zlib:// scheme with the fopen on a file scheme
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$srcFile = "file://$inputFileName";
+$compressedFile = "compress.zlib://$srcFile";
+
+echo "file=$compressedFile\n\n";
+$h = fopen($compressedFile, 'r');
+fpassthru($h);
+fclose($h);
+?>
+===DONE===
+--EXPECTF--
+file=compress.zlib://file://%s/004.txt.gz
+
+When you're taught through feelings
+Destiny flying high above
+all I know is that you can realize it
+Destiny who cares
+as it turns around
+and I know that it descends down on me
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_rename_basic.phpt b/ext/zlib/tests/zlib_scheme_rename_basic.phpt
new file mode 100644
index 0000000..9de55aa
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_rename_basic.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test compress.zlib:// scheme with the unlink function
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$srcFile = "compress.zlib://$inputFileName";
+rename($srcFile, 'something.tmp');
+var_dump(file_exists($inputFileName));
+?>
+===DONE===
+--EXPECTF--
+
+Warning: rename(): ZLIB wrapper does not support renaming in %s on line %d
+bool(true)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_stat_basic.phpt b/ext/zlib/tests/zlib_scheme_stat_basic.phpt
new file mode 100644
index 0000000..10cd9a4
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_stat_basic.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Test compress.zlib:// scheme with the unlink function
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$srcFile = "compress.zlib://$inputFileName";
+stat($srcFile);
+lstat($srcFile);
+?>
+===DONE===
+--EXPECTF--
+
+Warning: stat(): stat failed for compress.zlib://%s/004.txt.gz in %s on line %d
+
+Warning: lstat(): Lstat failed for compress.zlib://%s/004.txt.gz in %s on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_stat_basic2.phpt b/ext/zlib/tests/zlib_scheme_stat_basic2.phpt
new file mode 100644
index 0000000..e78bcd7
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_stat_basic2.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test compress.zlib:// scheme with the unlink function
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$srcFile = "compress.zlib://$inputFileName";
+echo "file_exists=";
+var_dump(file_exists($srcFile));
+echo "is_file=";
+var_dump(is_file($srcFile));
+echo "is_dir=";
+var_dump(is_dir($srcFile));
+echo "is_readable=";
+var_dump(is_readable($srcFile));
+echo "\n";
+echo "filesize=";
+var_dump(filesize($srcFile));
+echo "filetype=";
+var_dump(filetype($srcFile));
+echo "fileatime=";
+var_dump(fileatime($srcFile));
+
+?>
+===DONE===
+--EXPECTF--
+file_exists=bool(false)
+is_file=bool(false)
+is_dir=bool(false)
+is_readable=bool(false)
+
+filesize=
+Warning: filesize(): stat failed for compress.zlib://%s004.txt.gz in %s on line %d
+bool(false)
+filetype=
+Warning: filetype(): Lstat failed for compress.zlib://%s004.txt.gz in %s on line %d
+bool(false)
+fileatime=
+Warning: fileatime(): stat failed for compress.zlib://%s004.txt.gz in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_scheme_unlink_basic.phpt b/ext/zlib/tests/zlib_scheme_unlink_basic.phpt
new file mode 100644
index 0000000..b05e45b
--- /dev/null
+++ b/ext/zlib/tests/zlib_scheme_unlink_basic.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test compress.zlib:// scheme with the unlink function
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$inputFileName = dirname(__FILE__)."/004.txt.gz";
+$srcFile = "compress.zlib://$inputFileName";
+unlink($srcFile);
+var_dump(file_exists($inputFileName));
+?>
+===DONE===
+--EXPECTF--
+
+Warning: unlink(): ZLIB does not allow unlinking in %s on line %d
+bool(true)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_wrapper_fflush_basic.phpt b/ext/zlib/tests/zlib_wrapper_fflush_basic.phpt
new file mode 100644
index 0000000..74ccc0d
--- /dev/null
+++ b/ext/zlib/tests/zlib_wrapper_fflush_basic.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test function fflush() on a zlib stream wrapper
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+
+$filename = "temp.txt.gz";
+$h = gzopen($filename, 'w');
+$str = "Here is the string to be written.";
+$length = 10;
+var_dump(fflush($h));
+gzwrite( $h, $str);
+gzwrite( $h, $str);
+var_dump(fflush($h));
+gzclose($h);
+
+$h = gzopen($filename, 'r');
+gzpassthru($h);
+gzclose($h);
+echo "\n";
+unlink($filename);
+?>
+===DONE===
+--EXPECT--
+bool(true)
+bool(true)
+Here is the string to be written.Here is the string to be written.
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_wrapper_flock_basic.phpt b/ext/zlib/tests/zlib_wrapper_flock_basic.phpt
new file mode 100644
index 0000000..9cefce4
--- /dev/null
+++ b/ext/zlib/tests/zlib_wrapper_flock_basic.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test function stream_get_meta_data on a zlib stream
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f,'r');
+var_dump(flock($h, LOCK_SH));
+gzclose($h);
+?>
+===DONE===
+--EXPECT--
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_wrapper_fstat_basic.phpt b/ext/zlib/tests/zlib_wrapper_fstat_basic.phpt
new file mode 100644
index 0000000..41f957e
--- /dev/null
+++ b/ext/zlib/tests/zlib_wrapper_fstat_basic.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test function fstat() on zlib wrapper
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f, "r");
+var_dump(fstat($h));
+fclose($h);
+?>
+===DONE===
+--EXPECT--
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_wrapper_ftruncate_basic.phpt b/ext/zlib/tests/zlib_wrapper_ftruncate_basic.phpt
new file mode 100644
index 0000000..53b140a
--- /dev/null
+++ b/ext/zlib/tests/zlib_wrapper_ftruncate_basic.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Test function ftruncate() on zlib wrapper by calling it with its expected arguments
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+$f = dirname(__FILE__)."/004.txt.gz";
+$f2 = "temp.txt.gz";
+copy($f, $f2);
+
+$h = gzopen($f2, "r");
+ftruncate($h, 20);
+fclose($h);
+unlink($f2);
+
+$h = gzopen($f2, "w");
+ftruncate($h, 20);
+fclose($h);
+unlink($f2);
+
+?>
+===DONE===
+--EXPECTF--
+
+Warning: ftruncate(): Can't truncate this stream! in %s on line %d
+
+Warning: ftruncate(): Can't truncate this stream! in %s on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_wrapper_meta_data_basic.phpt b/ext/zlib/tests/zlib_wrapper_meta_data_basic.phpt
new file mode 100644
index 0000000..2f76b46
--- /dev/null
+++ b/ext/zlib/tests/zlib_wrapper_meta_data_basic.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Test function stream_get_meta_data on a zlib stream
+--SKIPIF--
+<?php
+if (!extension_loaded("zlib")) {
+ print "skip - ZLIB extension not loaded";
+}
+?>
+--FILE--
+<?php
+echo "no wrapper\n";
+$f = dirname(__FILE__)."/004.txt.gz";
+$h = gzopen($f,'r');
+var_dump(stream_get_meta_data($h));
+gzclose($h);
+echo "\nwith wrapper\n";
+$f = "compress.zlib://".dirname(__FILE__)."/004.txt.gz";
+$h = fopen($f,'r');
+var_dump(stream_get_meta_data($h));
+gzclose($h);
+
+
+?>
+===DONE===
+--EXPECTF--
+no wrapper
+array(7) {
+ ["stream_type"]=>
+ string(4) "ZLIB"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+with wrapper
+array(9) {
+ ["wrapper_type"]=>
+ string(4) "ZLIB"
+ ["stream_type"]=>
+ string(4) "ZLIB"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%d) "compress.zlib://%s/004.txt.gz"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
new file mode 100644
index 0000000..1a202e3
--- /dev/null
+++ b/ext/zlib/zlib.c
@@ -0,0 +1,1037 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.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> |
+ | Zeev Suraski <zeev@zend.com> |
+ | Jade Nicoletti <nicoletti@nns.ch> |
+ | Michael Wallner <mike@php.net> |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "php.h"
+#include "SAPI.h"
+#include "php_ini.h"
+#include "ext/standard/info.h"
+#include "ext/standard/file.h"
+#include "ext/standard/php_string.h"
+#include "php_zlib.h"
+
+ZEND_DECLARE_MODULE_GLOBALS(zlib);
+
+/* {{{ Memory management wrappers */
+
+static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size)
+{
+ return (voidpf)safe_emalloc(items, size, 0);
+}
+
+static void php_zlib_free(voidpf opaque, voidpf address)
+{
+ efree((void*)address);
+}
+/* }}} */
+
+/* {{{ php_zlib_output_conflict_check() */
+static int php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len TSRMLS_DC)
+{
+ if (php_output_get_level(TSRMLS_C) > 0) {
+ if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC)
+ || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_gzhandler") TSRMLS_CC)
+ || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler") TSRMLS_CC)
+ || php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("URL-Rewriter") TSRMLS_CC)) {
+ return FAILURE;
+ }
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ php_zlib_output_encoding() */
+static int php_zlib_output_encoding(TSRMLS_D)
+{
+ zval **enc;
+
+ if (!ZLIBG(compression_coding)) {
+ zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC);
+ if (PG(http_globals)[TRACK_VARS_SERVER] && SUCCESS == zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void *) &enc)) {
+ convert_to_string(*enc);
+ if (strstr(Z_STRVAL_PP(enc), "gzip")) {
+ ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP;
+ } else if (strstr(Z_STRVAL_PP(enc), "deflate")) {
+ ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE;
+ }
+ }
+ }
+ return ZLIBG(compression_coding);
+}
+/* }}} */
+
+/* {{{ php_zlib_output_handler_ex() */
+static int php_zlib_output_handler_ex(php_zlib_context *ctx, php_output_context *output_context)
+{
+ int flags = Z_SYNC_FLUSH;
+ PHP_OUTPUT_TSRMLS(output_context);
+
+ if (output_context->op & PHP_OUTPUT_HANDLER_START) {
+ /* start up */
+ if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) {
+ return FAILURE;
+ }
+ }
+
+ if (output_context->op & PHP_OUTPUT_HANDLER_CLEAN) {
+ /* free buffers */
+ deflateEnd(&ctx->Z);
+
+ if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
+ /* discard */
+ return SUCCESS;
+ } else {
+ /* restart */
+ if (Z_OK != deflateInit2(&ctx->Z, ZLIBG(output_compression_level), Z_DEFLATED, ZLIBG(compression_coding), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) {
+ return FAILURE;
+ }
+ ctx->buffer.used = 0;
+ }
+ } else {
+ if (output_context->in.used) {
+ /* append input */
+ if (ctx->buffer.free < output_context->in.used) {
+ if (!(ctx->buffer.aptr = erealloc_recoverable(ctx->buffer.data, ctx->buffer.used + ctx->buffer.free + output_context->in.used))) {
+ deflateEnd(&ctx->Z);
+ return FAILURE;
+ }
+ ctx->buffer.data = ctx->buffer.aptr;
+ ctx->buffer.free += output_context->in.used;
+ }
+ memcpy(ctx->buffer.data + ctx->buffer.used, output_context->in.data, output_context->in.used);
+ ctx->buffer.free -= output_context->in.used;
+ ctx->buffer.used += output_context->in.used;
+ }
+ output_context->out.size = PHP_ZLIB_BUFFER_SIZE_GUESS(output_context->in.used);
+ output_context->out.data = emalloc(output_context->out.size);
+ output_context->out.free = 1;
+ output_context->out.used = 0;
+
+ ctx->Z.avail_in = ctx->buffer.used;
+ ctx->Z.next_in = (Bytef *) ctx->buffer.data;
+ ctx->Z.avail_out = output_context->out.size;
+ ctx->Z.next_out = (Bytef *) output_context->out.data;
+
+ if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
+ flags = Z_FINISH;
+ } else if (output_context->op & PHP_OUTPUT_HANDLER_FLUSH) {
+ flags = Z_FULL_FLUSH;
+ }
+
+ switch (deflate(&ctx->Z, flags)) {
+ case Z_OK:
+ if (flags == Z_FINISH) {
+ deflateEnd(&ctx->Z);
+ return FAILURE;
+ }
+ case Z_STREAM_END:
+ if (ctx->Z.avail_in) {
+ memmove(ctx->buffer.data, ctx->buffer.data + ctx->buffer.used - ctx->Z.avail_in, ctx->Z.avail_in);
+ }
+ ctx->buffer.free += ctx->buffer.used - ctx->Z.avail_in;
+ ctx->buffer.used = ctx->Z.avail_in;
+ output_context->out.used = output_context->out.size - ctx->Z.avail_out;
+ break;
+ default:
+ deflateEnd(&ctx->Z);
+ return FAILURE;
+ }
+
+ if (output_context->op & PHP_OUTPUT_HANDLER_FINAL) {
+ deflateEnd(&ctx->Z);
+ }
+ }
+
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ php_zlib_output_handler() */
+static int php_zlib_output_handler(void **handler_context, php_output_context *output_context)
+{
+ php_zlib_context *ctx = *(php_zlib_context **) handler_context;
+ PHP_OUTPUT_TSRMLS(output_context);
+
+ if (!php_zlib_output_encoding(TSRMLS_C)) {
+ /* "Vary: Accept-Encoding" header sent along uncompressed content breaks caching in MSIE,
+ so let's just send it with successfully compressed content or unless the complete
+ buffer gets discarded, see http://bugs.php.net/40325;
+
+ Test as follows:
+ +Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";'
+ +Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n";'
+ -Vary: $ HTTP_ACCEPT_ENCODING=gzip ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();'
+ -Vary: $ HTTP_ACCEPT_ENCODING= ./sapi/cgi/php <<<'<?php ob_start("ob_gzhandler"); echo "foo\n"; ob_end_clean();'
+ */
+ if ((output_context->op & PHP_OUTPUT_HANDLER_START)
+ && (output_context->op != (PHP_OUTPUT_HANDLER_START|PHP_OUTPUT_HANDLER_CLEAN|PHP_OUTPUT_HANDLER_FINAL))
+ ) {
+ sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 1 TSRMLS_CC);
+ }
+ return FAILURE;
+ }
+
+ if (SUCCESS != php_zlib_output_handler_ex(ctx, output_context)) {
+ return FAILURE;
+ }
+
+ if (!(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) {
+ int flags;
+
+ if (SUCCESS == php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS, &flags TSRMLS_CC)) {
+ /* only run this once */
+ if (!(flags & PHP_OUTPUT_HANDLER_STARTED)) {
+ if (SG(headers_sent) || !ZLIBG(output_compression)) {
+ deflateEnd(&ctx->Z);
+ return FAILURE;
+ }
+ switch (ZLIBG(compression_coding)) {
+ case PHP_ZLIB_ENCODING_GZIP:
+ sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC);
+ break;
+ case PHP_ZLIB_ENCODING_DEFLATE:
+ sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC);
+ break;
+ default:
+ deflateEnd(&ctx->Z);
+ return FAILURE;
+ }
+ sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 1 TSRMLS_CC);
+ php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC);
+ }
+ }
+ }
+
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ php_zlib_output_handler_context_init() */
+static php_zlib_context *php_zlib_output_handler_context_init(TSRMLS_D)
+{
+ php_zlib_context *ctx = (php_zlib_context *) ecalloc(1, sizeof(php_zlib_context));
+ ctx->Z.zalloc = php_zlib_alloc;
+ ctx->Z.zfree = php_zlib_free;
+ return ctx;
+}
+/* }}} */
+
+/* {{{ php_zlib_output_handler_context_dtor() */
+static void php_zlib_output_handler_context_dtor(void *opaq TSRMLS_DC)
+{
+ php_zlib_context *ctx = (php_zlib_context *) opaq;
+
+ if (ctx) {
+ if (ctx->buffer.data) {
+ efree(ctx->buffer.data);
+ }
+ efree(ctx);
+ }
+}
+/* }}} */
+
+/* {{{ php_zlib_output_handler_init() */
+static php_output_handler *php_zlib_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags TSRMLS_DC)
+{
+ php_output_handler *h = NULL;
+
+ if (!ZLIBG(output_compression)) {
+ ZLIBG(output_compression) = chunk_size ? chunk_size : PHP_OUTPUT_HANDLER_DEFAULT_SIZE;
+ }
+
+ ZLIBG(handler_registered) = 1;
+
+ if ((h = php_output_handler_create_internal(handler_name, handler_name_len, php_zlib_output_handler, chunk_size, flags TSRMLS_CC))) {
+ php_output_handler_set_context(h, php_zlib_output_handler_context_init(TSRMLS_C), php_zlib_output_handler_context_dtor TSRMLS_CC);
+ }
+
+ return h;
+}
+/* }}} */
+
+/* {{{ php_zlib_output_compression_start() */
+static void php_zlib_output_compression_start(TSRMLS_D)
+{
+ zval *zoh;
+ php_output_handler *h;
+
+ switch (ZLIBG(output_compression)) {
+ case 0:
+ break;
+ case 1:
+ ZLIBG(output_compression) = PHP_OUTPUT_HANDLER_DEFAULT_SIZE;
+ /* break omitted intentionally */
+ default:
+ if ( php_zlib_output_encoding(TSRMLS_C) &&
+ (h = php_zlib_output_handler_init(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC)) &&
+ (SUCCESS == php_output_handler_start(h TSRMLS_CC))) {
+ if (ZLIBG(output_handler) && *ZLIBG(output_handler)) {
+ MAKE_STD_ZVAL(zoh);
+ ZVAL_STRING(zoh, ZLIBG(output_handler), 1);
+ php_output_start_user(zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
+ zval_ptr_dtor(&zoh);
+ }
+ }
+ break;
+ }
+}
+/* }}} */
+
+/* {{{ php_zlib_encode() */
+static int php_zlib_encode(const char *in_buf, size_t in_len, char **out_buf, size_t *out_len, int encoding, int level TSRMLS_DC)
+{
+ int status;
+ z_stream Z;
+
+ memset(&Z, 0, sizeof(z_stream));
+ Z.zalloc = php_zlib_alloc;
+ Z.zfree = php_zlib_free;
+
+ if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, encoding, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
+ *out_len = PHP_ZLIB_BUFFER_SIZE_GUESS(in_len);
+ *out_buf = emalloc(*out_len);
+
+ Z.next_in = (Bytef *) in_buf;
+ Z.next_out = (Bytef *) *out_buf;
+ Z.avail_in = in_len;
+ Z.avail_out = *out_len;
+
+ status = deflate(&Z, Z_FINISH);
+ deflateEnd(&Z);
+
+ if (Z_STREAM_END == status) {
+ /* size buffer down to actual length */
+ *out_buf = erealloc(*out_buf, Z.total_out + 1);
+ (*out_buf)[*out_len = Z.total_out] = '\0';
+ return SUCCESS;
+ } else {
+ efree(*out_buf);
+ }
+ }
+
+ *out_buf = NULL;
+ *out_len = 0;
+
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
+ return FAILURE;
+}
+/* }}} */
+
+/* {{{ php_zlib_inflate_rounds() */
+static inline int php_zlib_inflate_rounds(z_stream *Z, size_t max, char **buf, size_t *len)
+{
+ int status, round = 0;
+ php_zlib_buffer buffer = {NULL, NULL, 0, 0, 0};
+
+ *buf = NULL;
+ *len = 0;
+
+ buffer.size = (max && (max < Z->avail_in)) ? max : Z->avail_in;
+
+ do {
+ if ((max && (max <= buffer.used)) || !(buffer.aptr = erealloc_recoverable(buffer.data, buffer.size))) {
+ status = Z_MEM_ERROR;
+ } else {
+ buffer.data = buffer.aptr;
+ Z->avail_out = buffer.free = buffer.size - buffer.used;
+ Z->next_out = (Bytef *) buffer.data + buffer.used;
+#if 0
+ fprintf(stderr, "\n%3d: %3d PRIOR: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
+#endif
+ status = inflate(Z, Z_NO_FLUSH);
+
+ buffer.used += buffer.free - Z->avail_out;
+ buffer.free = Z->avail_out;
+#if 0
+ fprintf(stderr, "%3d: %3d AFTER: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
+#endif
+ buffer.size += (buffer.size >> 3) + 1;
+ }
+ } while ((Z_BUF_ERROR == status || (Z_OK == status && Z->avail_in)) && ++round < 100);
+
+ if (status == Z_STREAM_END) {
+ buffer.data = erealloc(buffer.data, buffer.used + 1);
+ buffer.data[buffer.used] = '\0';
+ *buf = buffer.data;
+ *len = buffer.used;
+ } else {
+ if (buffer.data) {
+ efree(buffer.data);
+ }
+ /* HACK: See zlib/examples/zpipe.c inf() function for explanation. */
+ /* This works as long as this function is not used for streaming. Required to catch very short invalid data. */
+ status = (status == Z_OK) ? Z_DATA_ERROR : status;
+ }
+ return status;
+}
+/* }}} */
+
+/* {{{ php_zlib_decode() */
+static int php_zlib_decode(const char *in_buf, size_t in_len, char **out_buf, size_t *out_len, int encoding, size_t max_len TSRMLS_DC)
+{
+ int status = Z_DATA_ERROR;
+ z_stream Z;
+
+ memset(&Z, 0, sizeof(z_stream));
+ Z.zalloc = php_zlib_alloc;
+ Z.zfree = php_zlib_free;
+
+ if (in_len) {
+retry_raw_inflate:
+ status = inflateInit2(&Z, encoding);
+ if (Z_OK == status) {
+ Z.next_in = (Bytef *) in_buf;
+ Z.avail_in = in_len + 1; /* NOTE: data must be zero terminated */
+
+ switch (status = php_zlib_inflate_rounds(&Z, max_len, out_buf, out_len)) {
+ case Z_STREAM_END:
+ inflateEnd(&Z);
+ return SUCCESS;
+
+ case Z_DATA_ERROR:
+ /* raw deflated data? */
+ if (PHP_ZLIB_ENCODING_ANY == encoding) {
+ inflateEnd(&Z);
+ encoding = PHP_ZLIB_ENCODING_RAW;
+ goto retry_raw_inflate;
+ }
+ }
+ inflateEnd(&Z);
+ }
+ }
+
+ *out_buf = NULL;
+ *out_len = 0;
+
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
+ return FAILURE;
+}
+/* }}} */
+
+/* {{{ php_zlib_cleanup_ob_gzhandler_mess() */
+static void php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_D)
+{
+ if (ZLIBG(ob_gzhandler)) {
+ deflateEnd(&(ZLIBG(ob_gzhandler)->Z));
+ php_zlib_output_handler_context_dtor(ZLIBG(ob_gzhandler) TSRMLS_CC);
+ ZLIBG(ob_gzhandler) = NULL;
+ }
+}
+/* }}} */
+
+/* {{{ proto string ob_gzhandler(string data, int flags)
+ Legacy hack */
+static PHP_FUNCTION(ob_gzhandler)
+{
+ char *in_str;
+ int in_len;
+ long flags = 0;
+ php_output_context ctx = {0};
+ int encoding, rv;
+
+ /*
+ * NOTE that the real ob_gzhandler is an alias to "zlib output compression".
+ * This is a really bad hack, because
+ * - we have to initialize a php_zlib_context on demand
+ * - we have to clean it up in RSHUTDOWN
+ * - OG(running) is not set or set to any other output handler
+ * - we have to mess around with php_output_context */
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &in_str, &in_len, &flags)) {
+ RETURN_FALSE;
+ }
+
+ if (!(encoding = php_zlib_output_encoding(TSRMLS_C))) {
+ RETURN_FALSE;
+ }
+
+ if (flags & PHP_OUTPUT_HANDLER_START) {
+ switch (encoding) {
+ case PHP_ZLIB_ENCODING_GZIP:
+ sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC);
+ break;
+ case PHP_ZLIB_ENCODING_DEFLATE:
+ sapi_add_header_ex(ZEND_STRL("Content-Encoding: deflate"), 1, 1 TSRMLS_CC);
+ break;
+ }
+ sapi_add_header_ex(ZEND_STRL("Vary: Accept-Encoding"), 1, 1 TSRMLS_CC);
+ }
+
+ if (!ZLIBG(ob_gzhandler)) {
+ ZLIBG(ob_gzhandler) = php_zlib_output_handler_context_init(TSRMLS_C);
+ }
+
+ TSRMLS_SET_CTX(ctx.tsrm_ls);
+ ctx.op = flags;
+ ctx.in.data = in_str;
+ ctx.in.used = in_len;
+
+ rv = php_zlib_output_handler_ex(ZLIBG(ob_gzhandler), &ctx);
+
+ if (SUCCESS != rv) {
+ if (ctx.out.data && ctx.out.free) {
+ efree(ctx.out.data);
+ }
+ php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_C);
+ RETURN_FALSE;
+ }
+
+ if (ctx.out.data) {
+ RETVAL_STRINGL(ctx.out.data, ctx.out.used, 1);
+ if (ctx.out.free) {
+ efree(ctx.out.data);
+ }
+ } else {
+ RETVAL_EMPTY_STRING();
+ }
+}
+/* }}} */
+
+/* {{{ proto string zlib_get_coding_type(void)
+ Returns the coding type used for output compression */
+static PHP_FUNCTION(zlib_get_coding_type)
+{
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+ switch (ZLIBG(compression_coding)) {
+ case PHP_ZLIB_ENCODING_GZIP:
+ RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1);
+ case PHP_ZLIB_ENCODING_DEFLATE:
+ RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1);
+ default:
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto array gzfile(string filename [, int use_include_path])
+ Read and uncompress entire .gz-file into an array */
+static PHP_FUNCTION(gzfile)
+{
+ char *filename;
+ int filename_len;
+ int flags = REPORT_ERRORS;
+ char buf[8192] = {0};
+ register int i = 0;
+ long use_include_path = 0;
+ php_stream *stream;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &use_include_path)) {
+ return;
+ }
+
+ if (use_include_path) {
+ flags |= USE_PATH;
+ }
+
+ /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */
+ stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC);
+
+ if (!stream) {
+ /* Error reporting is already done by stream code */
+ RETURN_FALSE;
+ }
+
+ /* Initialize return array */
+ array_init(return_value);
+
+ /* Now loop through the file and do the magic quotes thing if needed */
+ memset(buf, 0, sizeof(buf));
+
+ while (php_stream_gets(stream, buf, sizeof(buf) - 1) != NULL) {
+ add_index_string(return_value, i++, buf, 1);
+ }
+ php_stream_close(stream);
+}
+/* }}} */
+
+/* {{{ proto resource gzopen(string filename, string mode [, int use_include_path])
+ Open a .gz-file and return a .gz-file pointer */
+static PHP_FUNCTION(gzopen)
+{
+ char *filename;
+ char *mode;
+ int filename_len, mode_len;
+ int flags = REPORT_ERRORS;
+ php_stream *stream;
+ long use_include_path = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &filename, &filename_len, &mode, &mode_len, &use_include_path) == FAILURE) {
+ return;
+ }
+
+ if (use_include_path) {
+ flags |= USE_PATH;
+ }
+
+ stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, NULL STREAMS_CC TSRMLS_CC);
+
+ if (!stream) {
+ RETURN_FALSE;
+ }
+ php_stream_to_zval(stream, return_value);
+}
+/* }}} */
+
+/* {{{ proto int readgzfile(string filename [, int use_include_path])
+ Output a .gz-file */
+static PHP_FUNCTION(readgzfile)
+{
+ char *filename;
+ int filename_len;
+ int flags = REPORT_ERRORS;
+ php_stream *stream;
+ int size;
+ long use_include_path = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &use_include_path) == FAILURE) {
+ return;
+ }
+
+ if (use_include_path) {
+ flags |= USE_PATH;
+ }
+
+ stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC TSRMLS_CC);
+
+ if (!stream) {
+ RETURN_FALSE;
+ }
+ size = php_stream_passthru(stream);
+ php_stream_close(stream);
+ RETURN_LONG(size);
+}
+/* }}} */
+
+#define PHP_ZLIB_ENCODE_FUNC(name, default_encoding) \
+static PHP_FUNCTION(name) \
+{ \
+ char *in_buf, *out_buf; \
+ int in_len; \
+ size_t out_len; \
+ long level = -1; \
+ long encoding = default_encoding; \
+ if (default_encoding) { \
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &in_buf, &in_len, &level, &encoding)) { \
+ return; \
+ } \
+ } else { \
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &in_buf, &in_len, &encoding, &level)) { \
+ return; \
+ } \
+ } \
+ if (level < -1 || level > 9) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "compression level (%ld) must be within -1..9", level); \
+ RETURN_FALSE; \
+ } \
+ switch (encoding) { \
+ case PHP_ZLIB_ENCODING_RAW: \
+ case PHP_ZLIB_ENCODING_GZIP: \
+ case PHP_ZLIB_ENCODING_DEFLATE: \
+ break; \
+ default: \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE"); \
+ RETURN_FALSE; \
+ } \
+ if (SUCCESS != php_zlib_encode(in_buf, in_len, &out_buf, &out_len, encoding, level TSRMLS_CC)) { \
+ RETURN_FALSE; \
+ } \
+ RETURN_STRINGL(out_buf, out_len, 0); \
+}
+
+#define PHP_ZLIB_DECODE_FUNC(name, encoding) \
+static PHP_FUNCTION(name) \
+{ \
+ char *in_buf, *out_buf; \
+ int in_len; \
+ size_t out_len; \
+ long max_len = 0; \
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &in_buf, &in_len, &max_len)) { \
+ return; \
+ } \
+ if (max_len < 0) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "length (%ld) must be greater or equal zero", max_len); \
+ RETURN_FALSE; \
+ } \
+ if (SUCCESS != php_zlib_decode(in_buf, in_len, &out_buf, &out_len, encoding, max_len TSRMLS_CC)) { \
+ RETURN_FALSE; \
+ } \
+ RETURN_STRINGL(out_buf, out_len, 0); \
+}
+
+/* {{{ proto binary zlib_encode(binary data, int encoding[, int level = -1])
+ Compress data with the specified encoding */
+PHP_ZLIB_ENCODE_FUNC(zlib_encode, 0);
+/* }}} */
+
+/* {{{ proto binary zlib_decode(binary data[, int max_decoded_len])
+ Uncompress any raw/gzip/zlib encoded data */
+PHP_ZLIB_DECODE_FUNC(zlib_decode, PHP_ZLIB_ENCODING_ANY);
+/* }}} */
+
+/* NOTE: The naming of these userland functions was quite unlucky */
+/* {{{ proto binary gzdeflate(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_RAW])
+ Encode data with the raw deflate encoding */
+PHP_ZLIB_ENCODE_FUNC(gzdeflate, PHP_ZLIB_ENCODING_RAW);
+/* }}} */
+
+/* {{{ proto binary gzencode(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_GZIP])
+ Encode data with the gzip encoding */
+PHP_ZLIB_ENCODE_FUNC(gzencode, PHP_ZLIB_ENCODING_GZIP);
+/* }}} */
+
+/* {{{ proto binary gzcompress(binary data[, int level = -1[, int encoding = ZLIB_ENCODING_DEFLATE])
+ Encode data with the zlib encoding */
+PHP_ZLIB_ENCODE_FUNC(gzcompress, PHP_ZLIB_ENCODING_DEFLATE);
+/* }}} */
+
+/* {{{ proto binary gzinflate(binary data[, int max_decoded_len])
+ Decode raw deflate encoded data */
+PHP_ZLIB_DECODE_FUNC(gzinflate, PHP_ZLIB_ENCODING_RAW);
+/* }}} */
+
+/* {{{ proto binary gzdecode(binary data[, int max_decoded_len])
+ Decode gzip encoded data */
+PHP_ZLIB_DECODE_FUNC(gzdecode, PHP_ZLIB_ENCODING_GZIP);
+/* }}} */
+
+/* {{{ proto binary gzuncompress(binary data[, int max_decoded_len])
+ Decode zlib encoded data */
+PHP_ZLIB_DECODE_FUNC(gzuncompress, PHP_ZLIB_ENCODING_DEFLATE);
+/* }}} */
+
+#ifdef COMPILE_DL_ZLIB
+ZEND_GET_MODULE(php_zlib)
+#endif
+
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ob_gzhandler, 0, 0, 2)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_zlib_get_coding_type, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzfile, 0, 0, 1)
+ ZEND_ARG_INFO(0, filename)
+ ZEND_ARG_INFO(0, use_include_path)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzopen, 0, 0, 2)
+ ZEND_ARG_INFO(0, filename)
+ ZEND_ARG_INFO(0, mode)
+ ZEND_ARG_INFO(0, use_include_path)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_readgzfile, 0, 0, 1)
+ ZEND_ARG_INFO(0, filename)
+ ZEND_ARG_INFO(0, use_include_path)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zlib_encode, 0, 0, 2)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, encoding)
+ ZEND_ARG_INFO(0, level)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zlib_decode, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, max_decoded_len)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzdeflate, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, level)
+ ZEND_ARG_INFO(0, encoding)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzencode, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, level)
+ ZEND_ARG_INFO(0, encoding)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzcompress, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, level)
+ ZEND_ARG_INFO(0, encoding)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzinflate, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, max_decoded_len)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzdecode, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, max_decoded_len)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzuncompress, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, max_decoded_len)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzputs, 0, 0, 2)
+ ZEND_ARG_INFO(0, fp)
+ ZEND_ARG_INFO(0, str)
+ ZEND_ARG_INFO(0, length)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_gzpassthru, 0)
+ ZEND_ARG_INFO(0, fp)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzseek, 0, 0, 2)
+ ZEND_ARG_INFO(0, fp)
+ ZEND_ARG_INFO(0, offset)
+ ZEND_ARG_INFO(0, whence)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_gzread, 0)
+ ZEND_ARG_INFO(0, fp)
+ ZEND_ARG_INFO(0, length)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzgetss, 0, 0, 1)
+ ZEND_ARG_INFO(0, fp)
+ ZEND_ARG_INFO(0, length)
+ ZEND_ARG_INFO(0, allowable_tags)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gzgets, 0, 0, 1)
+ ZEND_ARG_INFO(0, fp)
+ ZEND_ARG_INFO(0, length)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+/* {{{ php_zlib_functions[] */
+static const zend_function_entry php_zlib_functions[] = {
+ PHP_FE(readgzfile, arginfo_readgzfile)
+ PHP_FALIAS(gzrewind, rewind, arginfo_gzpassthru)
+ PHP_FALIAS(gzclose, fclose, arginfo_gzpassthru)
+ PHP_FALIAS(gzeof, feof, arginfo_gzpassthru)
+ PHP_FALIAS(gzgetc, fgetc, arginfo_gzpassthru)
+ PHP_FALIAS(gzgets, fgets, arginfo_gzgets)
+ PHP_FALIAS(gzgetss, fgetss, arginfo_gzgetss)
+ PHP_FALIAS(gzread, fread, arginfo_gzread)
+ PHP_FE(gzopen, arginfo_gzopen)
+ PHP_FALIAS(gzpassthru, fpassthru, arginfo_gzpassthru)
+ PHP_FALIAS(gzseek, fseek, arginfo_gzseek)
+ PHP_FALIAS(gztell, ftell, arginfo_gzpassthru)
+ PHP_FALIAS(gzwrite, fwrite, arginfo_gzputs)
+ PHP_FALIAS(gzputs, fwrite, arginfo_gzputs)
+ PHP_FE(gzfile, arginfo_gzfile)
+ PHP_FE(gzcompress, arginfo_gzcompress)
+ PHP_FE(gzuncompress, arginfo_gzuncompress)
+ PHP_FE(gzdeflate, arginfo_gzdeflate)
+ PHP_FE(gzinflate, arginfo_gzinflate)
+ PHP_FE(gzencode, arginfo_gzencode)
+ PHP_FE(gzdecode, arginfo_gzdecode)
+ PHP_FE(zlib_encode, arginfo_zlib_encode)
+ PHP_FE(zlib_decode, arginfo_zlib_decode)
+ PHP_FE(zlib_get_coding_type, arginfo_zlib_get_coding_type)
+ PHP_FE(ob_gzhandler, arginfo_ob_gzhandler)
+ PHP_FE_END
+};
+/* }}} */
+
+/* {{{ OnUpdate_zlib_output_compression */
+static PHP_INI_MH(OnUpdate_zlib_output_compression)
+{
+ int status, int_value;
+ char *ini_value;
+
+ if (new_value == NULL) {
+ return FAILURE;
+ }
+
+ if (!strncasecmp(new_value, "off", sizeof("off"))) {
+ new_value = "0";
+ new_value_length = sizeof("0");
+ } else if (!strncasecmp(new_value, "on", sizeof("on"))) {
+ new_value = "1";
+ new_value_length = sizeof("1");
+ }
+
+ int_value = zend_atoi(new_value, new_value_length);
+ ini_value = zend_ini_string("output_handler", sizeof("output_handler"), 0);
+
+ if (ini_value && *ini_value && int_value) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_CORE_ERROR, "Cannot use both zlib.output_compression and output_handler together!!");
+ return FAILURE;
+ }
+ if (stage == PHP_INI_STAGE_RUNTIME) {
+ status = php_output_get_status(TSRMLS_C);
+ if (status & PHP_OUTPUT_SENT) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_compression - headers already sent");
+ return FAILURE;
+ }
+ }
+
+ status = OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+
+ ZLIBG(output_compression) = ZLIBG(output_compression_default);
+ if (stage == PHP_INI_STAGE_RUNTIME && int_value) {
+ if (!php_output_handler_started(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC)) {
+ php_zlib_output_compression_start(TSRMLS_C);
+ }
+ }
+
+ return status;
+}
+/* }}} */
+
+/* {{{ OnUpdate_zlib_output_handler */
+static PHP_INI_MH(OnUpdate_zlib_output_handler)
+{
+ if (stage == PHP_INI_STAGE_RUNTIME && (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT)) {
+ php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "Cannot change zlib.output_handler - headers already sent");
+ return FAILURE;
+ }
+
+ return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ INI */
+PHP_INI_BEGIN()
+ STD_PHP_INI_BOOLEAN("zlib.output_compression", "0", PHP_INI_ALL, OnUpdate_zlib_output_compression, output_compression_default, zend_zlib_globals, zlib_globals)
+ STD_PHP_INI_ENTRY("zlib.output_compression_level", "-1", PHP_INI_ALL, OnUpdateLong, output_compression_level, zend_zlib_globals, zlib_globals)
+ STD_PHP_INI_ENTRY("zlib.output_handler", "", PHP_INI_ALL, OnUpdate_zlib_output_handler, output_handler, zend_zlib_globals, zlib_globals)
+PHP_INI_END()
+
+/* }}} */
+
+/* {{{ PHP_MINIT_FUNCTION */
+static PHP_MINIT_FUNCTION(zlib)
+{
+ php_register_url_stream_wrapper("compress.zlib", &php_stream_gzip_wrapper TSRMLS_CC);
+ php_stream_filter_register_factory("zlib.*", &php_zlib_filter_factory TSRMLS_CC);
+
+ php_output_handler_alias_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_handler_init TSRMLS_CC);
+ php_output_handler_conflict_register(ZEND_STRL("ob_gzhandler"), php_zlib_output_conflict_check TSRMLS_CC);
+ php_output_handler_conflict_register(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), php_zlib_output_conflict_check TSRMLS_CC);
+
+ REGISTER_LONG_CONSTANT("FORCE_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("FORCE_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT);
+
+ REGISTER_LONG_CONSTANT("ZLIB_ENCODING_RAW", PHP_ZLIB_ENCODING_RAW, CONST_CS|CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("ZLIB_ENCODING_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("ZLIB_ENCODING_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT);
+ REGISTER_INI_ENTRIES();
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_MSHUTDOWN_FUNCTION */
+static PHP_MSHUTDOWN_FUNCTION(zlib)
+{
+ php_unregister_url_stream_wrapper("zlib" TSRMLS_CC);
+ php_stream_filter_unregister_factory("zlib.*" TSRMLS_CC);
+
+ UNREGISTER_INI_ENTRIES();
+
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_RINIT_FUNCTION */
+static PHP_RINIT_FUNCTION(zlib)
+{
+ ZLIBG(compression_coding) = 0;
+ if (!ZLIBG(handler_registered)) {
+ ZLIBG(output_compression) = ZLIBG(output_compression_default);
+ php_zlib_output_compression_start(TSRMLS_C);
+ }
+
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_RSHUTDOWN_FUNCTION */
+static PHP_RSHUTDOWN_FUNCTION(zlib)
+{
+ php_zlib_cleanup_ob_gzhandler_mess(TSRMLS_C);
+ ZLIBG(handler_registered) = 0;
+
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_MINFO_FUNCTION */
+static PHP_MINFO_FUNCTION(zlib)
+{
+ php_info_print_table_start();
+ php_info_print_table_header(2, "ZLib Support", "enabled");
+ php_info_print_table_row(2, "Stream Wrapper", "compress.zlib://");
+ php_info_print_table_row(2, "Stream Filter", "zlib.inflate, zlib.deflate");
+ 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();
+
+ DISPLAY_INI_ENTRIES();
+}
+/* }}} */
+
+/* {{{ ZEND_MODULE_GLOBALS_CTOR */
+static ZEND_MODULE_GLOBALS_CTOR_D(zlib)
+{
+ zlib_globals->ob_gzhandler = NULL;
+ zlib_globals->handler_registered = 0;
+}
+/* }}} */
+
+/* {{{ php_zlib_module_entry */
+zend_module_entry php_zlib_module_entry = {
+ STANDARD_MODULE_HEADER,
+ "zlib",
+ php_zlib_functions,
+ PHP_MINIT(zlib),
+ PHP_MSHUTDOWN(zlib),
+ PHP_RINIT(zlib),
+ PHP_RSHUTDOWN(zlib),
+ PHP_MINFO(zlib),
+ "2.0",
+ PHP_MODULE_GLOBALS(zlib),
+ ZEND_MODULE_GLOBALS_CTOR_N(zlib),
+ NULL,
+ NULL,
+ STANDARD_MODULE_PROPERTIES_EX
+};
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
diff --git a/ext/zlib/zlib.dsp b/ext/zlib/zlib.dsp
new file mode 100644
index 0000000..8986bc6
--- /dev/null
+++ b/ext/zlib/zlib.dsp
@@ -0,0 +1,121 @@
+# Microsoft Developer Studio Project File - Name="zlib" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=zlib - Win32 Release_TS
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "zlib.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "zlib.mak" CFG="zlib - Win32 Release_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "zlib - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "zlib - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "zlib - Win32 Release_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release_TS"
+# PROP BASE Intermediate_Dir "Release_TS"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TS"
+# PROP Intermediate_Dir "Release_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\..\TSRM" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_ZLIB" /D ZTS=1 /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\includes" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ZLIB_EXPORTS" /D "COMPILE_DL_ZLIB" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_ZLIB=1 /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x406 /d "NDEBUG"
+# ADD RSC /l 0x406 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts.lib zlib.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_zlib.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\..\php_build\zlib\Release" /libpath:"..\..\Release_TS_Inline"
+
+!ELSEIF "$(CFG)" == "zlib - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Debug_TS"
+# PROP BASE Intermediate_Dir "Debug_TS"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Debug_TS"
+# PROP Intermediate_Dir "Debug_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_ZLIB" /D ZTS=1 /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "..\..\..\php_build\includes" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ZLIB_EXPORTS" /D "COMPILE_DL_ZLIB" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_ZLIB=1 /FR /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x406 /d "NDEBUG"
+# ADD RSC /l 0x406 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts_debug.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts_debug.lib zlib.lib /nologo /dll /machine:I386 /out:"..\..\Debug_TS/php_zlib.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\zlib\Debug"
+
+!ENDIF
+
+# Begin Target
+
+# Name "zlib - Win32 Release_TS"
+# Name "zlib - Win32 Debug_TS"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\zlib.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\zlib_fopen_wrapper.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\zlib_filter.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\php_zlib.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c
new file mode 100644
index 0000000..5f276ad
--- /dev/null
+++ b/ext/zlib/zlib_filter.c
@@ -0,0 +1,454 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.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: Sara Golemon (pollita@php.net) |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#include "php.h"
+#include "php_zlib.h"
+
+/* {{{ data structure */
+
+/* Passed as opaque in malloc callbacks */
+typedef struct _php_zlib_filter_data {
+ int persistent;
+ z_stream strm;
+ char *inbuf;
+ size_t inbuf_len;
+ char *outbuf;
+ size_t outbuf_len;
+ zend_bool finished;
+} php_zlib_filter_data;
+
+/* }}} */
+
+/* {{{ Memory management wrappers */
+
+static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size)
+{
+ return (voidpf)safe_pemalloc(items, size, 0, ((php_zlib_filter_data*)opaque)->persistent);
+}
+
+static void php_zlib_free(voidpf opaque, voidpf address)
+{
+ pefree((void*)address, ((php_zlib_filter_data*)opaque)->persistent);
+}
+/* }}} */
+
+/* {{{ zlib.inflate filter implementation */
+
+static php_stream_filter_status_t php_zlib_inflate_filter(
+ php_stream *stream,
+ php_stream_filter *thisfilter,
+ php_stream_bucket_brigade *buckets_in,
+ php_stream_bucket_brigade *buckets_out,
+ size_t *bytes_consumed,
+ int flags
+ TSRMLS_DC)
+{
+ php_zlib_filter_data *data;
+ php_stream_bucket *bucket;
+ size_t consumed = 0, original_out, original_in;
+ int status;
+ php_stream_filter_status_t exit_status = PSFS_FEED_ME;
+ z_stream *streamp;
+
+ if (!thisfilter || !thisfilter->abstract) {
+ /* Should never happen */
+ return PSFS_ERR_FATAL;
+ }
+
+ data = (php_zlib_filter_data *)(thisfilter->abstract);
+ streamp = &(data->strm);
+ original_in = data->strm.total_in;
+ original_out = data->strm.total_out;
+
+ while (buckets_in->head) {
+ size_t bin = 0, desired;
+
+ bucket = buckets_in->head;
+
+ bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC);
+
+ while (bin < (unsigned int) bucket->buflen) {
+
+ if (data->finished) {
+ consumed += bucket->buflen;
+ break;
+ }
+
+ desired = bucket->buflen - bin;
+ if (desired > data->inbuf_len) {
+ desired = data->inbuf_len;
+ }
+ memcpy(data->strm.next_in, bucket->buf + bin, desired);
+ data->strm.avail_in = desired;
+
+ status = inflate(&(data->strm), flags & PSFS_FLAG_FLUSH_CLOSE ? Z_FINISH : Z_SYNC_FLUSH);
+ if (status == Z_STREAM_END) {
+ inflateEnd(&(data->strm));
+ data->finished = '\1';
+ } else if (status != Z_OK) {
+ /* Something bad happened */
+ php_stream_bucket_delref(bucket TSRMLS_CC);
+ /* reset these because despite the error the filter may be used again */
+ data->strm.next_in = data->inbuf;
+ data->strm.avail_in = 0;
+ return PSFS_ERR_FATAL;
+ }
+ desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */
+ data->strm.next_in = data->inbuf;
+ data->strm.avail_in = 0;
+ bin += desired;
+
+ if (data->strm.avail_out < data->outbuf_len) {
+ php_stream_bucket *out_bucket;
+ size_t bucketlen = data->outbuf_len - data->strm.avail_out;
+ out_bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC);
+ php_stream_bucket_append(buckets_out, out_bucket TSRMLS_CC);
+ data->strm.avail_out = data->outbuf_len;
+ data->strm.next_out = data->outbuf;
+ exit_status = PSFS_PASS_ON;
+ } else if (status == Z_STREAM_END && data->strm.avail_out >= data->outbuf_len) {
+ /* no more data to decompress, and nothing was spat out */
+ php_stream_bucket_delref(bucket TSRMLS_CC);
+ return PSFS_PASS_ON;
+ }
+
+ }
+ consumed += bucket->buflen;
+ php_stream_bucket_delref(bucket TSRMLS_CC);
+ }
+
+ if (!data->finished && flags & PSFS_FLAG_FLUSH_CLOSE) {
+ /* Spit it out! */
+ status = Z_OK;
+ while (status == Z_OK) {
+ status = inflate(&(data->strm), Z_FINISH);
+ if (data->strm.avail_out < data->outbuf_len) {
+ size_t bucketlen = data->outbuf_len - data->strm.avail_out;
+
+ bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC);
+ php_stream_bucket_append(buckets_out, bucket TSRMLS_CC);
+ data->strm.avail_out = data->outbuf_len;
+ data->strm.next_out = data->outbuf;
+ exit_status = PSFS_PASS_ON;
+ }
+ }
+ }
+
+ if (bytes_consumed) {
+ *bytes_consumed = consumed;
+ }
+
+ return exit_status;
+}
+
+static void php_zlib_inflate_dtor(php_stream_filter *thisfilter TSRMLS_DC)
+{
+ if (thisfilter && thisfilter->abstract) {
+ php_zlib_filter_data *data = thisfilter->abstract;
+ if (!data->finished) {
+ inflateEnd(&(data->strm));
+ }
+ pefree(data->inbuf, data->persistent);
+ pefree(data->outbuf, data->persistent);
+ pefree(data, data->persistent);
+ }
+}
+
+static php_stream_filter_ops php_zlib_inflate_ops = {
+ php_zlib_inflate_filter,
+ php_zlib_inflate_dtor,
+ "zlib.inflate"
+};
+/* }}} */
+
+/* {{{ zlib.inflate filter implementation */
+
+static php_stream_filter_status_t php_zlib_deflate_filter(
+ php_stream *stream,
+ php_stream_filter *thisfilter,
+ php_stream_bucket_brigade *buckets_in,
+ php_stream_bucket_brigade *buckets_out,
+ size_t *bytes_consumed,
+ int flags
+ TSRMLS_DC)
+{
+ php_zlib_filter_data *data;
+ php_stream_bucket *bucket;
+ size_t consumed = 0, original_out, original_in;
+ int status;
+ php_stream_filter_status_t exit_status = PSFS_FEED_ME;
+ z_stream *streamp;
+
+ if (!thisfilter || !thisfilter->abstract) {
+ /* Should never happen */
+ return PSFS_ERR_FATAL;
+ }
+
+ data = (php_zlib_filter_data *)(thisfilter->abstract);
+ streamp = &(data->strm);
+ original_in = data->strm.total_in;
+ original_out = data->strm.total_out;
+
+ while (buckets_in->head) {
+ size_t bin = 0, desired;
+
+ bucket = buckets_in->head;
+
+ bucket = php_stream_bucket_make_writeable(bucket TSRMLS_CC);
+
+ while (bin < (unsigned int) bucket->buflen) {
+ desired = bucket->buflen - bin;
+ if (desired > data->inbuf_len) {
+ desired = data->inbuf_len;
+ }
+ memcpy(data->strm.next_in, bucket->buf + bin, desired);
+ data->strm.avail_in = desired;
+
+ status = deflate(&(data->strm), flags & PSFS_FLAG_FLUSH_CLOSE ? Z_FULL_FLUSH : (flags & PSFS_FLAG_FLUSH_INC ? Z_SYNC_FLUSH : Z_NO_FLUSH));
+ if (status != Z_OK) {
+ /* Something bad happened */
+ php_stream_bucket_delref(bucket TSRMLS_CC);
+ return PSFS_ERR_FATAL;
+ }
+ desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */
+ data->strm.next_in = data->inbuf;
+ data->strm.avail_in = 0;
+ bin += desired;
+
+ if (data->strm.avail_out < data->outbuf_len) {
+ php_stream_bucket *out_bucket;
+ size_t bucketlen = data->outbuf_len - data->strm.avail_out;
+
+ out_bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC);
+ php_stream_bucket_append(buckets_out, out_bucket TSRMLS_CC);
+ data->strm.avail_out = data->outbuf_len;
+ data->strm.next_out = data->outbuf;
+ exit_status = PSFS_PASS_ON;
+ }
+ }
+ consumed += bucket->buflen;
+ php_stream_bucket_delref(bucket TSRMLS_CC);
+ }
+
+ if (flags & PSFS_FLAG_FLUSH_CLOSE) {
+ /* Spit it out! */
+ status = Z_OK;
+ while (status == Z_OK) {
+ status = deflate(&(data->strm), Z_FINISH);
+ if (data->strm.avail_out < data->outbuf_len) {
+ size_t bucketlen = data->outbuf_len - data->strm.avail_out;
+
+ bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC);
+ php_stream_bucket_append(buckets_out, bucket TSRMLS_CC);
+ data->strm.avail_out = data->outbuf_len;
+ data->strm.next_out = data->outbuf;
+ exit_status = PSFS_PASS_ON;
+ }
+ }
+ }
+
+ if (bytes_consumed) {
+ *bytes_consumed = consumed;
+ }
+
+ return exit_status;
+}
+
+static void php_zlib_deflate_dtor(php_stream_filter *thisfilter TSRMLS_DC)
+{
+ if (thisfilter && thisfilter->abstract) {
+ php_zlib_filter_data *data = thisfilter->abstract;
+ deflateEnd(&(data->strm));
+ pefree(data->inbuf, data->persistent);
+ pefree(data->outbuf, data->persistent);
+ pefree(data, data->persistent);
+ }
+}
+
+static php_stream_filter_ops php_zlib_deflate_ops = {
+ php_zlib_deflate_filter,
+ php_zlib_deflate_dtor,
+ "zlib.deflate"
+};
+
+/* }}} */
+
+/* {{{ zlib.* common factory */
+
+static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *filterparams, int persistent TSRMLS_DC)
+{
+ php_stream_filter_ops *fops = NULL;
+ php_zlib_filter_data *data;
+ int status;
+
+ /* Create this filter */
+ data = pecalloc(1, sizeof(php_zlib_filter_data), persistent);
+ if (!data) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes", sizeof(php_zlib_filter_data));
+ return NULL;
+ }
+
+ /* Circular reference */
+ data->strm.opaque = (voidpf) data;
+
+ data->strm.zalloc = (alloc_func) php_zlib_alloc;
+ data->strm.zfree = (free_func) php_zlib_free;
+ data->strm.avail_out = data->outbuf_len = data->inbuf_len = 2048;
+ data->strm.next_in = data->inbuf = (Bytef *) pemalloc(data->inbuf_len, persistent);
+ if (!data->inbuf) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes", data->inbuf_len);
+ pefree(data, persistent);
+ return NULL;
+ }
+ data->strm.avail_in = 0;
+ data->strm.next_out = data->outbuf = (Bytef *) pemalloc(data->outbuf_len, persistent);
+ if (!data->outbuf) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zd bytes", data->outbuf_len);
+ pefree(data->inbuf, persistent);
+ pefree(data, persistent);
+ return NULL;
+ }
+
+ data->strm.data_type = Z_ASCII;
+
+ if (strcasecmp(filtername, "zlib.inflate") == 0) {
+ int windowBits = -MAX_WBITS;
+
+ if (filterparams) {
+ zval **tmpzval;
+
+ if ((Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) &&
+ zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void **) &tmpzval) == SUCCESS) {
+ zval tmp;
+
+ /* log-2 base of history window (9 - 15) */
+ tmp = **tmpzval;
+ zval_copy_ctor(&tmp);
+ convert_to_long(&tmp);
+ if (Z_LVAL(tmp) < -MAX_WBITS || Z_LVAL(tmp) > MAX_WBITS + 32) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter give for window size. (%ld)", Z_LVAL(tmp));
+ } else {
+ windowBits = Z_LVAL(tmp);
+ }
+ }
+ }
+
+ /* RFC 1951 Inflate */
+ data->finished = '\0';
+ status = inflateInit2(&(data->strm), windowBits);
+ fops = &php_zlib_inflate_ops;
+ } else if (strcasecmp(filtername, "zlib.deflate") == 0) {
+ /* RFC 1951 Deflate */
+ int level = Z_DEFAULT_COMPRESSION;
+ int windowBits = -MAX_WBITS;
+ int memLevel = MAX_MEM_LEVEL;
+
+
+ if (filterparams) {
+ zval **tmpzval, tmp;
+
+ /* filterparams can either be a scalar value to indicate compression level (shortcut method)
+ Or can be a hash containing one or more of 'window', 'memory', and/or 'level' members. */
+
+ switch (Z_TYPE_P(filterparams)) {
+ case IS_ARRAY:
+ case IS_OBJECT:
+ if (zend_hash_find(HASH_OF(filterparams), "memory", sizeof("memory"), (void**) &tmpzval) == SUCCESS) {
+ tmp = **tmpzval;
+ zval_copy_ctor(&tmp);
+ convert_to_long(&tmp);
+
+ /* Memory Level (1 - 9) */
+ if (Z_LVAL(tmp) < 1 || Z_LVAL(tmp) > MAX_MEM_LEVEL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter give for memory level. (%ld)", Z_LVAL(tmp));
+ } else {
+ memLevel = Z_LVAL(tmp);
+ }
+ }
+
+ if (zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void**) &tmpzval) == SUCCESS) {
+ tmp = **tmpzval;
+ zval_copy_ctor(&tmp);
+ convert_to_long(&tmp);
+
+ /* log-2 base of history window (9 - 15) */
+ if (Z_LVAL(tmp) < -MAX_WBITS || Z_LVAL(tmp) > MAX_WBITS + 16) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter give for window size. (%ld)", Z_LVAL(tmp));
+ } else {
+ windowBits = Z_LVAL(tmp);
+ }
+ }
+
+ if (zend_hash_find(HASH_OF(filterparams), "level", sizeof("level"), (void**) &tmpzval) == SUCCESS) {
+ tmp = **tmpzval;
+
+ /* Psuedo pass through to catch level validating code */
+ goto factory_setlevel;
+ }
+ break;
+ case IS_STRING:
+ case IS_DOUBLE:
+ case IS_LONG:
+ tmp = *filterparams;
+factory_setlevel:
+ zval_copy_ctor(&tmp);
+ convert_to_long(&tmp);
+
+ /* Set compression level within reason (-1 == default, 0 == none, 1-9 == least to most compression */
+ if (Z_LVAL(tmp) < -1 || Z_LVAL(tmp) > 9) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid compression level specified. (%ld)", Z_LVAL(tmp));
+ } else {
+ level = Z_LVAL(tmp);
+ }
+ break;
+ default:
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid filter parameter, ignored");
+ }
+ }
+ status = deflateInit2(&(data->strm), level, Z_DEFLATED, windowBits, memLevel, 0);
+ fops = &php_zlib_deflate_ops;
+ } else {
+ status = Z_DATA_ERROR;
+ }
+
+ if (status != Z_OK) {
+ /* Unspecified (probably strm) error, let stream-filter error do its own whining */
+ pefree(data->strm.next_in, persistent);
+ pefree(data->strm.next_out, persistent);
+ pefree(data, persistent);
+ return NULL;
+ }
+
+ return php_stream_filter_alloc(fops, data, persistent);
+}
+
+php_stream_filter_factory php_zlib_filter_factory = {
+ php_zlib_filter_create
+};
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c
new file mode 100644
index 0000000..1b00eb8
--- /dev/null
+++ b/ext/zlib/zlib_fopen_wrapper.c
@@ -0,0 +1,187 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.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. |
+ +----------------------------------------------------------------------+
+ | Author: Wez Furlong <wez@thebrainroom.com>, based on work by: |
+ | Hartmut Holzgraefe <hholzgra@php.net> |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+
+#define _GNU_SOURCE
+
+#include "php.h"
+#include "php_zlib.h"
+#include "fopen_wrappers.h"
+
+struct php_gz_stream_data_t {
+ gzFile gz_file;
+ php_stream *stream;
+};
+
+static size_t php_gziop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
+{
+ struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;
+ int read;
+
+ read = gzread(self->gz_file, buf, count);
+
+ if (gzeof(self->gz_file)) {
+ stream->eof = 1;
+ }
+
+ return (read < 0) ? 0 : read;
+}
+
+static size_t php_gziop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
+{
+ struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;
+ int wrote;
+
+ wrote = gzwrite(self->gz_file, (char *) buf, count);
+
+ return (wrote < 0) ? 0 : wrote;
+}
+
+static int php_gziop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC)
+{
+ struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;
+
+ assert(self != NULL);
+
+ if (whence == SEEK_END) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "SEEK_END is not supported");
+ return -1;
+ }
+ *newoffs = gzseek(self->gz_file, offset, whence);
+
+ return (*newoffs < 0) ? -1 : 0;
+}
+
+static int php_gziop_close(php_stream *stream, int close_handle TSRMLS_DC)
+{
+ struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;
+ int ret = EOF;
+
+ if (close_handle) {
+ if (self->gz_file) {
+ ret = gzclose(self->gz_file);
+ self->gz_file = NULL;
+ }
+ if (self->stream) {
+ php_stream_close(self->stream);
+ self->stream = NULL;
+ }
+ }
+ efree(self);
+
+ return ret;
+}
+
+static int php_gziop_flush(php_stream *stream TSRMLS_DC)
+{
+ struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract;
+
+ return gzflush(self->gz_file, Z_SYNC_FLUSH);
+}
+
+php_stream_ops php_stream_gzio_ops = {
+ php_gziop_write, php_gziop_read,
+ php_gziop_close, php_gziop_flush,
+ "ZLIB",
+ php_gziop_seek,
+ NULL, /* cast */
+ NULL, /* stat */
+ NULL /* set_option */
+};
+
+php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mode, int options,
+ char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
+{
+ struct php_gz_stream_data_t *self;
+ php_stream *stream = NULL, *innerstream = NULL;
+
+ /* sanity check the stream: it can be either read-only or write-only */
+ if (strchr(mode, '+')) {
+ if (options & REPORT_ERRORS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot open a zlib stream for reading and writing at the same time!");
+ }
+ return NULL;
+ }
+
+ if (strncasecmp("compress.zlib://", path, 16) == 0) {
+ path += 16;
+ } else if (strncasecmp("zlib:", path, 5) == 0) {
+ path += 5;
+ }
+
+ innerstream = php_stream_open_wrapper_ex(path, mode, STREAM_MUST_SEEK | options | STREAM_WILL_CAST, opened_path, context);
+
+ if (innerstream) {
+ int fd;
+
+ if (SUCCESS == php_stream_cast(innerstream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) {
+ self = emalloc(sizeof(*self));
+ self->stream = innerstream;
+ self->gz_file = gzdopen(dup(fd), mode);
+
+ if (self->gz_file) {
+ stream = php_stream_alloc_rel(&php_stream_gzio_ops, self, 0, mode);
+ if (stream) {
+ stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
+ return stream;
+ }
+
+ gzclose(self->gz_file);
+ }
+
+ efree(self);
+ if (options & REPORT_ERRORS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "gzopen failed");
+ }
+ }
+
+ php_stream_close(innerstream);
+ }
+
+ return NULL;
+}
+
+static php_stream_wrapper_ops gzip_stream_wops = {
+ php_stream_gzopen,
+ NULL, /* close */
+ NULL, /* stat */
+ NULL, /* stat_url */
+ NULL, /* opendir */
+ "ZLIB",
+ NULL, /* unlink */
+ NULL, /* rename */
+ NULL, /* mkdir */
+ NULL /* rmdir */
+};
+
+php_stream_wrapper php_stream_gzip_wrapper = {
+ &gzip_stream_wops,
+ NULL,
+ 0, /* is_url */
+};
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
diff --git a/ext/zlib/zlib_win32_howto.txt b/ext/zlib/zlib_win32_howto.txt
new file mode 100644
index 0000000..a4e01a4
--- /dev/null
+++ b/ext/zlib/zlib_win32_howto.txt
@@ -0,0 +1,16 @@
+Rules for building ZLIB
+-----------------------
+
+The zlib project requires the folowing files:
+
+php_build\zlib\include\zlib.h
+php_build\zlib\include\zconf.h
+php_build\zlib\lib\zlibstat.lib
+
+php_build is a directory at the same level as php5.
+
+Start Visual Studio, load php_modules.dsw, select the ZLIB projects, and build
+it.
+
+
+ \ No newline at end of file