Re: cvs: php4 /ext/bz2 bz2.c php_bz2.h

From: Date: Sat, 06 Apr 2002 11:24:35 +0000
Subject: Re: cvs: php4 /ext/bz2 bz2.c php_bz2.h
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10922@lists.php.net to get a copy of this message
Why don't we stick to case sensitivity. Do we really want to allow BZ2:// ? No biggy though. Andi At 15:24 04/04/2002 +0000, Wez Furlong wrote:
wez             Thu Apr  4 10:24:38 2002 EDT
Modified files:
    /php4/ext/bz2       bz2.c php_bz2.h
Log: Fix #16428 problems. Renamed the bz2 wrapper to bzip2:// # Thanks for the test case Jani! Index: php4/ext/bz2/bz2.c diff -u php4/ext/bz2/bz2.c:1.44 php4/ext/bz2/bz2.c:1.45
--- php4/ext/bz2/bz2.c:1.44     Sun Mar 24 13:04:47 2002
+++ php4/ext/bz2/bz2.c Thu Apr 4 10:24:37 2002 @@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
*/ -/* $Id: bz2.c,v 1.44 2002/03/24 18:04:47 wez Exp $ */ +/* $Id: bz2.c,v 1.45 2002/04/04 15:24:37 wez Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -30,6 +30,7 @@ /* PHP Includes */ #include "ext/standard/file.h" #include "ext/standard/info.h" +#include "ext/standard/php_string.h" /* for fileno() */ #include <stdio.h> @@ -44,7 +45,7 @@ function_entry bz2_functions[] = {
        PHP_FE(bzopen,       NULL)
-       PHP_NAMED_FE(bzread,    PHP_FN(fread),      NULL)
+       PHP_FE(bzread,       NULL)
        PHP_NAMED_FE(bzwrite,   PHP_FN(fwrite),         NULL)
        PHP_NAMED_FE(bzflush,   PHP_FN(fflush),     NULL)
        PHP_NAMED_FE(bzclose,   PHP_FN(fclose),     NULL)
@@ -130,8 +131,9 @@ php_stream_ops php_stream_bz2io_ops = {
        php_bz2iop_write, php_bz2iop_read,
        php_bz2iop_close, php_bz2iop_flush,
+       "BZip2",
        NULL, NULL,
-       NULL, "BZip2"
+       NULL, NULL
}; /* {{{ Bzip2 stream openers */ @@ -158,18 +160,18 @@ STREAMS_DC TSRMLS_DC) {
        php_stream *retstream = NULL, *stream = NULL;
-       char *path_copy;
-       BZFILE *bz_file;
+       char *path_copy = NULL;
+       BZFILE *bz_file = NULL;
-       if (strncasecmp("bz2://", path, 6) == 0)
-               path += 6;
+       if (strncasecmp("bzip2://", path, 8) == 0)
+               path += 8;
#ifdef VIRTUAL_DIR
        virtual_filepath(path, &path_copy TSRMLS_CC);
#else
        path_copy = estrdup(path);
#endif - +
        /* try and open it directly first */
        bz_file = BZ2_bzopen(path_copy, mode);
@@ -222,7 +224,7 @@ PHP_MINIT_FUNCTION(bz2) {
        if(PG(allow_url_fopen))
-               php_register_url_stream_wrapper("bz2", &php_stream_bzip2_wrapper TSRMLS_CC);
+               php_register_url_stream_wrapper("bzip2", &php_stream_bzip2_wrapper TSRMLS_CC);
        return SUCCESS;
} @@ -230,7 +232,7 @@ PHP_MSHUTDOWN_FUNCTION(bz2) {
        if (PG(allow_url_fopen))
-               php_unregister_url_stream_wrapper("bz2" TSRMLS_CC);
+               php_unregister_url_stream_wrapper("bzip2" TSRMLS_CC);
        return SUCCESS;
} @@ -243,6 +245,38 @@
        php_info_print_table_end();
} +/* {{{ proto string bzread(int bz[, int length]) + Reads up to length bytes from a BZip2 stream, or 1024 bytes if length is not specified */ +PHP_FUNCTION(bzread) +{
+       zval *bz;
+       int len = 1024;
+       php_stream *stream;
+
+       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &bz, &len)) {
+               RETURN_FALSE;
+       }
+
+       ZEND_FETCH_RESOURCE(stream, php_stream *, &bz, -1, "File-Handle", php_file_le_stream());
+
+       if (len < 0) {
+               zend_error(E_WARNING, "%s(): length may not be negative", get_active_function_name(TSRMLS_C));
+               RETURN_FALSE;
+       }
+
+       Z_STRVAL_P(return_value) = emalloc(len + 1);
+       Z_STRLEN_P(return_value) = php_stream_read(stream, Z_STRVAL_P(return_value), len);
+       Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0;
+
+       if (PG(magic_quotes_runtime)) {
+               Z_STRVAL_P(return_value) = php_addslashes(Z_STRVAL_P(return_value),
+                               Z_STRLEN_P(return_value), &Z_STRLEN_P(return_value), 1 TSRMLS_CC);
+       }
+       Z_TYPE_P(return_value) = IS_STRING;
+ +} +/* }}} */ + /* {{{ proto resource bzopen(string|int file|fp, string mode)
    Opens a new BZip2 stream */
PHP_FUNCTION(bzopen) @@ -251,7 +285,6 @@
                **mode;   /* The mode to open the stream with */
        BZFILE   *bz;     /* The compressed file stream */
        php_stream *stream = NULL;
-       char    *path;
        if (ZEND_NUM_ARGS() != 2 ||
            zend_get_parameters_ex(2, &file, &mode) == FAILURE) {
@@ -263,7 +296,7 @@
        if (Z_TYPE_PP(file) != IS_RESOURCE) {
                convert_to_string_ex(file);
                stream = php_stream_bz2open(NULL,
-                                                                       path,
+ Z_STRVAL_PP(file),
Z_STRVAL_PP(mode), ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL); Index: php4/ext/bz2/php_bz2.h diff -u php4/ext/bz2/php_bz2.h:1.9 php4/ext/bz2/php_bz2.h:1.10 --- php4/ext/bz2/php_bz2.h:1.9 Sun Mar 24 13:04:48 2002
+++ php4/ext/bz2/php_bz2.h      Thu Apr  4 10:24:38 2002
@@ -37,6 +37,7 @@ PHP_MSHUTDOWN_FUNCTION(bz2); PHP_MINFO_FUNCTION(bz2); PHP_FUNCTION(bzopen); +PHP_FUNCTION(bzread); PHP_FUNCTION(bzerrno); PHP_FUNCTION(bzerrstr); PHP_FUNCTION(bzerror); @@ -51,7 +52,7 @@ PHPAPI php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz, char *mode, php_stream *innerstream STREAMS_DC TSRMLS_DC); #define php_stream_bz2open_from_BZFILE(bz, mode, innerstream) _php_stream_bz2open_from_BZFILE((bz), (mode), (innerstream) STREAMS_CC TSRMLS_CC) -#define php_stream_bz2open(path, mode, options, opened_path, wrappercontext) _php_stream_bz2open((path), (mode), (options), (opened_path), (wrappercontext) STREAMS_CC TSRMLS_CC) +#define php_stream_bz2open(wrapper, path, mode, options, opened_path) _php_stream_bz2open((wrapper), (path), (mode), (options), (opened_path) STREAMS_CC TSRMLS_CC) php_stream_ops php_stream_bz2io_ops;
 #define PHP_STREAM_IS_BZIP2    &php_stream_bz2io_ops
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.cvs (#10922) next »