cvs: php4 /ext/bz2 bz2.c
| From: | Derick Rethans | Date: | Thu, 01 Nov 2001 08:36:06 +0000 |
| Subject: | cvs: php4 /ext/bz2 bz2.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-8042@lists.php.net to get a copy of this message | ||
derick Thu Nov 1 03:36:06 2001 EDT
Modified files:
/php4/ext/bz2 bz2.c
Log:
- Whitespace
Index: php4/ext/bz2/bz2.c diff -u php4/ext/bz2/bz2.c:1.27 php4/ext/bz2/bz2.c:1.28 --- php4/ext/bz2/bz2.c:1.27 Thu Nov 1 03:23:20 2001 +++ php4/ext/bz2/bz2.c Thu Nov 1 03:36:06 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: bz2.c,v 1.27 2001/11/01 08:23:20 jeroen Exp $ */ +/* $Id: bz2.c,v 1.28 2001/11/01 08:36:06 derick Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -109,14 +109,14 @@ **mode; /* The mode to open the stream with */ BZFILE *bz; /* The compressed file stream */ FILE *fp; /* If filepointer is given, its placed in here */ - char *path; + char *path; if (ZEND_NUM_ARGS() != 2 || - zend_get_parameters_ex(2, &file, &mode) == FAILURE) { + zend_get_parameters_ex(2, &file, &mode) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(mode); - + /* If it's not a resource its a string containing the filename to open */ if (Z_TYPE_PP(file) != IS_RESOURCE) { convert_to_string_ex(file); @@ -139,7 +139,7 @@ php_error(E_WARNING, "bzopen(): Unable to open file"); RETURN_FALSE; } - + ZEND_REGISTER_RESOURCE(return_value, bz, le_bz2); } /* }}} */ @@ -148,15 +148,15 @@ Reads len bytes from the BZip2 stream given by bz */ PHP_FUNCTION(bzread) { - zval **bzp, /* BZip2 Resource Pointer */ - **zlen; /* The (optional) length to read */ - BZFILE *bz; /* BZip2 File pointer */ - void *buf; /* Buffer to read data into */ - int len = 1024, /* Length to read, passed to the BZ2_bzread function */ - argc = ZEND_NUM_ARGS(); /* Argument count */ + zval **bzp, /* BZip2 Resource Pointer */ + **zlen; /* The (optional) length to read */ + BZFILE *bz; /* BZip2 File pointer */ + void *buf; /* Buffer to read data into */ + int len = 1024, /* Length to read, passed to the BZ2_bzread function */ + argc = ZEND_NUM_ARGS(); /* Argument count */ if (argc < 1 || argc > 2 || - zend_get_parameters_ex(argc, &bzp, &zlen) == FAILURE) { + zend_get_parameters_ex(argc, &bzp, &zlen) == FAILURE) { WRONG_PARAM_COUNT; } @@ -174,7 +174,7 @@ BZ2_bzread(bz, buf, len); RETVAL_STRINGL(buf, len, 1); - + /* We copied the buffer, so now we can free it */ efree(buf); } @@ -184,16 +184,16 @@ Writes data to the BZip2 stream given by bz */ PHP_FUNCTION(bzwrite) { - zval **bzp, /* Bzip2 Resource Pointer */ - **data, /* The data to write */ - **zlen; /* The (optional) length of the data to write */ - BZFILE *bz; /* BZip2 File pointer */ - int error, /* Error container */ - len, /* Length to read, passed to the BZ2_bzwrite function */ - argc = ZEND_NUM_ARGS(); /* Argument count */ - + zval **bzp, /* Bzip2 Resource Pointer */ + **data, /* The data to write */ + **zlen; /* The (optional) length of the data to write */ + BZFILE *bz; /* BZip2 File pointer */ + int error, /* Error container */ + len, /* Length to read, passed to the BZ2_bzwrite function */ + argc = ZEND_NUM_ARGS(); /* Argument count */ + if (argc < 2 || argc > 3 || - zend_get_parameters_ex(argc, &bzp, &data, &zlen) == FAILURE) { + zend_get_parameters_ex(argc, &bzp, &data, &zlen) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(data); @@ -209,7 +209,7 @@ else { len = Z_STRLEN_PP(data); } - + /* Write the data and return the error */ error = BZ2_bzwrite(bz, (void *) Z_STRVAL_PP(data), len); RETURN_LONG(error); @@ -225,11 +225,11 @@ int error; /* Error container */ if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &bzp) == FAILURE) { + zend_get_parameters_ex(1, &bzp) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(bz, BZFILE *, bzp, -1, "BZip2 File Handle", le_bz2); - + error = BZ2_bzflush(bz); RETURN_LONG(error); } @@ -241,9 +241,9 @@ { zval **bzp=NULL; /* BZip2 Resource Pointer */ BZFILE *bz; /* BZip2 File pointer */ - + if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &bzp) == FAILURE) { + zend_get_parameters_ex(1, &bzp) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(bz, BZFILE *, bzp, -1, "BZip2 File Handle", le_bz2); @@ -279,33 +279,33 @@ Compresses a string into BZip2 encoded data */ PHP_FUNCTION(bzcompress) { - zval **source, /* Source data to compress */ - **zblock_size, /* Optional block size to use */ - **zwork_factor; /* Optional work factor to use */ - char *dest = NULL; /* Destination to place the compressed data into */ - int error, /* Error Container */ - block_size = 4, /* Block size for compression algorithm */ - work_factor = 0; /* Work factor for compression algorithm */ - unsigned int size; /* The size to "realloc" if the initial buffer wasn't big enough */ - + zval **source, /* Source data to compress */ + **zblock_size, /* Optional block size to use */ + **zwork_factor; /* Optional work factor to use */ + char *dest = NULL; /* Destination to place the compressed data into */ + int error, /* Error Container */ + block_size = 4, /* Block size for compression algorithm */ + work_factor = 0; /* Work factor for compression algorithm */ + unsigned int size; /* The size to "realloc" if the initial buffer wasn't big enough */ + if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 3 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &source, &zblock_size, &zwork_factor) == FAILURE) { + zend_get_parameters_ex(ZEND_NUM_ARGS(), &source, &zblock_size, &zwork_factor) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(source); - + /* Allocate the destination buffer. The length of the data + .01 x length * of data + 600 which is the largest size the results of the compression * could possibly be, at least that's what the libbz2 docs say (thanks to * jeremy@nirvani.net for pointing this out). */ dest = emalloc(Z_STRLEN_PP(source) + (0.01 * Z_STRLEN_PP(source)) + 601); - + /* Handle the optional arguments */ if (ZEND_NUM_ARGS() > 1) { convert_to_long_ex(zblock_size); block_size = Z_LVAL_PP(zblock_size); } - + if (ZEND_NUM_ARGS() > 2) { convert_to_long_ex(zwork_factor); work_factor = Z_LVAL_PP(zwork_factor); @@ -328,19 +328,19 @@ Decompresses BZip2 compressed data */ PHP_FUNCTION(bzdecompress) { - zval **source, /* Source data to decompress */ - **zsmall; /* (Optional) user specified small */ + zval **source, /* Source data to decompress */ + **zsmall; /* (Optional) user specified small */ char *dest = NULL; /* Destination buffer */ - int error, /* Error container */ - size, /* Current size to realloc the dest buffer to */ - small = 0; /* The actual small */ - + int error, /* Error container */ + size, /* Current size to realloc the dest buffer to */ + small = 0; /* The actual small */ + if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &source, &zsmall) == FAILURE) { + zend_get_parameters_ex(ZEND_NUM_ARGS(), &source, &zsmall) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(source); - + /* optional small argument handling */ if (ZEND_NUM_ARGS() > 1) { convert_to_long_ex(zsmall); @@ -350,9 +350,10 @@ /* result will be at least the compressed size */ size = Z_STRLEN_PP(source); /* If size is too small, go to a minimum */ - if (size < 1024) size = 1024; - - /* (de)Compression Loop */ + if (size < 1024) + size = 1024; + + /* (de)Compression Loop */ do { /* exponentially increment size. */ size = PHP_BZ_DECOMPRESS_INCREMENT * (float)size; @@ -363,7 +364,7 @@ /* Perform the decompression */ error = BZ2_bzBuffToBuffDecompress(dest, &size, Z_STRVAL_PP(source), Z_STRLEN_PP(source), small, 0); } while (error == BZ_OUTBUFF_FULL); - + if (error != BZ_OK) { efree(dest); php_error(E_WARNING, "bzdecompress failed"); @@ -394,16 +395,16 @@ BZFILE *bz; /* BZip2 File pointer */ const char *errstr; /* Error string */ int errnum; /* Error number */ - + if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &bzp) == FAILURE) { + zend_get_parameters_ex(1, &bzp) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(bz, BZFILE *, bzp, -1, "BZip2 File pointer", le_bz2); - + /* Fetch the error information */ errstr = BZ2_bzerror(bz, &errnum); - + /* Determine what to return */ switch (opt) { case PHP_BZ_ERRNO: @@ -414,10 +415,10 @@ break; case PHP_BZ_ERRBOTH: array_init(return_value); - + add_assoc_long (return_value, "errno", errnum); add_assoc_string(return_value, "errstr", (char*)errstr, 1); - + break; } }
Index: php4/ext/bz2/bz2.c diff -u php4/ext/bz2/bz2.c:1.27 php4/ext/bz2/bz2.c:1.28 --- php4/ext/bz2/bz2.c:1.27 Thu Nov 1 03:23:20 2001 +++ php4/ext/bz2/bz2.c Thu Nov 1 03:36:06 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: bz2.c,v 1.27 2001/11/01 08:23:20 jeroen Exp $ */ +/* $Id: bz2.c,v 1.28 2001/11/01 08:36:06 derick Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -109,14 +109,14 @@ **mode; /* The mode to open the stream with */ BZFILE *bz; /* The compressed file stream */ FILE *fp; /* If filepointer is given, its placed in here */ - char *path; + char *path; if (ZEND_NUM_ARGS() != 2 || - zend_get_parameters_ex(2, &file, &mode) == FAILURE) { + zend_get_parameters_ex(2, &file, &mode) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(mode); - + /* If it's not a resource its a string containing the filename to open */ if (Z_TYPE_PP(file) != IS_RESOURCE) { convert_to_string_ex(file); @@ -139,7 +139,7 @@ php_error(E_WARNING, "bzopen(): Unable to open file"); RETURN_FALSE; } - + ZEND_REGISTER_RESOURCE(return_value, bz, le_bz2); } /* }}} */ @@ -148,15 +148,15 @@ Reads len bytes from the BZip2 stream given by bz */ PHP_FUNCTION(bzread) { - zval **bzp, /* BZip2 Resource Pointer */ - **zlen; /* The (optional) length to read */ - BZFILE *bz; /* BZip2 File pointer */ - void *buf; /* Buffer to read data into */ - int len = 1024, /* Length to read, passed to the BZ2_bzread function */ - argc = ZEND_NUM_ARGS(); /* Argument count */ + zval **bzp, /* BZip2 Resource Pointer */ + **zlen; /* The (optional) length to read */ + BZFILE *bz; /* BZip2 File pointer */ + void *buf; /* Buffer to read data into */ + int len = 1024, /* Length to read, passed to the BZ2_bzread function */ + argc = ZEND_NUM_ARGS(); /* Argument count */ if (argc < 1 || argc > 2 || - zend_get_parameters_ex(argc, &bzp, &zlen) == FAILURE) { + zend_get_parameters_ex(argc, &bzp, &zlen) == FAILURE) { WRONG_PARAM_COUNT; } @@ -174,7 +174,7 @@ BZ2_bzread(bz, buf, len); RETVAL_STRINGL(buf, len, 1); - + /* We copied the buffer, so now we can free it */ efree(buf); } @@ -184,16 +184,16 @@ Writes data to the BZip2 stream given by bz */ PHP_FUNCTION(bzwrite) { - zval **bzp, /* Bzip2 Resource Pointer */ - **data, /* The data to write */ - **zlen; /* The (optional) length of the data to write */ - BZFILE *bz; /* BZip2 File pointer */ - int error, /* Error container */ - len, /* Length to read, passed to the BZ2_bzwrite function */ - argc = ZEND_NUM_ARGS(); /* Argument count */ - + zval **bzp, /* Bzip2 Resource Pointer */ + **data, /* The data to write */ + **zlen; /* The (optional) length of the data to write */ + BZFILE *bz; /* BZip2 File pointer */ + int error, /* Error container */ + len, /* Length to read, passed to the BZ2_bzwrite function */ + argc = ZEND_NUM_ARGS(); /* Argument count */ + if (argc < 2 || argc > 3 || - zend_get_parameters_ex(argc, &bzp, &data, &zlen) == FAILURE) { + zend_get_parameters_ex(argc, &bzp, &data, &zlen) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(data); @@ -209,7 +209,7 @@ else { len = Z_STRLEN_PP(data); } - + /* Write the data and return the error */ error = BZ2_bzwrite(bz, (void *) Z_STRVAL_PP(data), len); RETURN_LONG(error); @@ -225,11 +225,11 @@ int error; /* Error container */ if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &bzp) == FAILURE) { + zend_get_parameters_ex(1, &bzp) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(bz, BZFILE *, bzp, -1, "BZip2 File Handle", le_bz2); - + error = BZ2_bzflush(bz); RETURN_LONG(error); } @@ -241,9 +241,9 @@ { zval **bzp=NULL; /* BZip2 Resource Pointer */ BZFILE *bz; /* BZip2 File pointer */ - + if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &bzp) == FAILURE) { + zend_get_parameters_ex(1, &bzp) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(bz, BZFILE *, bzp, -1, "BZip2 File Handle", le_bz2); @@ -279,33 +279,33 @@ Compresses a string into BZip2 encoded data */ PHP_FUNCTION(bzcompress) { - zval **source, /* Source data to compress */ - **zblock_size, /* Optional block size to use */ - **zwork_factor; /* Optional work factor to use */ - char *dest = NULL; /* Destination to place the compressed data into */ - int error, /* Error Container */ - block_size = 4, /* Block size for compression algorithm */ - work_factor = 0; /* Work factor for compression algorithm */ - unsigned int size; /* The size to "realloc" if the initial buffer wasn't big enough */ - + zval **source, /* Source data to compress */ + **zblock_size, /* Optional block size to use */ + **zwork_factor; /* Optional work factor to use */ + char *dest = NULL; /* Destination to place the compressed data into */ + int error, /* Error Container */ + block_size = 4, /* Block size for compression algorithm */ + work_factor = 0; /* Work factor for compression algorithm */ + unsigned int size; /* The size to "realloc" if the initial buffer wasn't big enough */ + if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 3 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &source, &zblock_size, &zwork_factor) == FAILURE) { + zend_get_parameters_ex(ZEND_NUM_ARGS(), &source, &zblock_size, &zwork_factor) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(source); - + /* Allocate the destination buffer. The length of the data + .01 x length * of data + 600 which is the largest size the results of the compression * could possibly be, at least that's what the libbz2 docs say (thanks to * jeremy@nirvani.net for pointing this out). */ dest = emalloc(Z_STRLEN_PP(source) + (0.01 * Z_STRLEN_PP(source)) + 601); - + /* Handle the optional arguments */ if (ZEND_NUM_ARGS() > 1) { convert_to_long_ex(zblock_size); block_size = Z_LVAL_PP(zblock_size); } - + if (ZEND_NUM_ARGS() > 2) { convert_to_long_ex(zwork_factor); work_factor = Z_LVAL_PP(zwork_factor); @@ -328,19 +328,19 @@ Decompresses BZip2 compressed data */ PHP_FUNCTION(bzdecompress) { - zval **source, /* Source data to decompress */ - **zsmall; /* (Optional) user specified small */ + zval **source, /* Source data to decompress */ + **zsmall; /* (Optional) user specified small */ char *dest = NULL; /* Destination buffer */ - int error, /* Error container */ - size, /* Current size to realloc the dest buffer to */ - small = 0; /* The actual small */ - + int error, /* Error container */ + size, /* Current size to realloc the dest buffer to */ + small = 0; /* The actual small */ + if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &source, &zsmall) == FAILURE) { + zend_get_parameters_ex(ZEND_NUM_ARGS(), &source, &zsmall) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(source); - + /* optional small argument handling */ if (ZEND_NUM_ARGS() > 1) { convert_to_long_ex(zsmall); @@ -350,9 +350,10 @@ /* result will be at least the compressed size */ size = Z_STRLEN_PP(source); /* If size is too small, go to a minimum */ - if (size < 1024) size = 1024; - - /* (de)Compression Loop */ + if (size < 1024) + size = 1024; + + /* (de)Compression Loop */ do { /* exponentially increment size. */ size = PHP_BZ_DECOMPRESS_INCREMENT * (float)size; @@ -363,7 +364,7 @@ /* Perform the decompression */ error = BZ2_bzBuffToBuffDecompress(dest, &size, Z_STRVAL_PP(source), Z_STRLEN_PP(source), small, 0); } while (error == BZ_OUTBUFF_FULL); - + if (error != BZ_OK) { efree(dest); php_error(E_WARNING, "bzdecompress failed"); @@ -394,16 +395,16 @@ BZFILE *bz; /* BZip2 File pointer */ const char *errstr; /* Error string */ int errnum; /* Error number */ - + if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &bzp) == FAILURE) { + zend_get_parameters_ex(1, &bzp) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(bz, BZFILE *, bzp, -1, "BZip2 File pointer", le_bz2); - + /* Fetch the error information */ errstr = BZ2_bzerror(bz, &errnum); - + /* Determine what to return */ switch (opt) { case PHP_BZ_ERRNO: @@ -414,10 +415,10 @@ break; case PHP_BZ_ERRBOTH: array_init(return_value); - + add_assoc_long (return_value, "errno", errnum); add_assoc_string(return_value, "errstr", (char*)errstr, 1); - + break; } }