36#define PHP_BZ_ERRSTR 1
37#define PHP_BZ_ERRBOTH 2
60struct php_bz2_stream_data_t {
69 struct php_bz2_stream_data_t *self = (
struct php_bz2_stream_data_t *)stream->
abstract;
77 just_read = BZ2_bzread(self->bz_file,
buf, to_read);
100 struct php_bz2_stream_data_t *self = (
struct php_bz2_stream_data_t *)stream->
abstract;
104 size_t remain =
count - wrote;
107 just_wrote = BZ2_bzwrite(self->bz_file, (
char*)
buf, to_write);
108 if (just_wrote < 0) {
114 if (just_wrote == 0) {
120 }
while (wrote <
count);
125static int php_bz2iop_close(
php_stream *stream,
int close_handle)
127 struct php_bz2_stream_data_t *self = (
struct php_bz2_stream_data_t *)stream->
abstract;
131 BZ2_bzclose(self->bz_file);
143static int php_bz2iop_flush(
php_stream *stream)
145 struct php_bz2_stream_data_t *self = (
struct php_bz2_stream_data_t *)stream->
abstract;
146 return BZ2_bzflush(self->bz_file);
151 php_bz2iop_write, php_bz2iop_read,
152 php_bz2iop_close, php_bz2iop_flush,
164 struct php_bz2_stream_data_t *self;
168 self->stream = innerstream;
185 char *path_copy =
NULL;
186 BZFILE *bz_file =
NULL;
188 if (
strncasecmp(
"compress.bzip2://", path, 17) == 0) {
191 if (
mode[0] ==
'\0' || (
mode[0] !=
'w' &&
mode[0] !=
'r' &&
mode[1] !=
'\0')) {
198 path_copy = (
char *)path;
209 bz_file = BZ2_bzopen(path_copy,
mode);
211 if (opened_path && bz_file) {
212 *opened_path = zend_string_init(path_copy,
strlen(path_copy), 0);
219 if (bz_file ==
NULL) {
226 bz_file = BZ2_bzdopen((
int)
fd,
mode);
233 if (opened_path && !bz_file &&
mode[0] ==
'w') {
244 BZ2_bzclose(bz_file);
365 size_t stream_mode_len;
370 if (stream_mode_len != 1 && !(stream_mode_len == 2 && memchr(stream->
mode,
'b', 2))) {
373 }
else if (stream_mode_len == 1 && stream->
mode[0] !=
'r' && stream->
mode[0] !=
'w' && stream->
mode[0] !=
'a' && stream->
mode[0] !=
'x') {
381 if (stream->
mode[0] !=
mode[0] && !(stream_mode_len == 2 && stream->
mode[1] !=
mode[0])) {
388 if (stream->
mode[0] !=
mode[0] && !(stream_mode_len == 2 && stream->
mode[1] !=
mode[0])
389 && stream->
mode[0] !=
'a' && !(stream_mode_len == 2 && stream->
mode[1] !=
'a')
390 && stream->
mode[0] !=
'x' && !(stream_mode_len == 2 && stream->
mode[1] !=
'x')) {
402 bz = BZ2_bzdopen((
int)
fd,
mode);
451 unsigned int dest_len;
461 dest_len = (
unsigned int) (source_len + (0.01 * source_len) + 600);
464 dest = zend_string_alloc(dest_len, 0);
468 block_size = zblock_size;
472 work_factor = zwork_factor;
475 error = BZ2_bzBuffToBuffCompress(
ZSTR_VAL(dest), &dest_len, source, source_len, block_size, 0, work_factor);
476 if (
error != BZ_OK) {
477 zend_string_efree(dest);
498 unsigned __int64
size = 0;
500 unsigned long long size = 0;
511 if (BZ2_bzDecompressInit(&bzs, 0, (
int)small) != BZ_OK) {
515 bzs.next_in = source;
516 bzs.avail_in = source_len;
519 dest = zend_string_safe_alloc(source_len, 2, 1, 0);
520 bzs.avail_out = source_len * 2;
523 while ((
error = BZ2_bzDecompress(&bzs)) == BZ_OK && bzs.avail_in > 0) {
525 bzs.avail_out = source_len;
526 size = (bzs.total_out_hi32 * (
unsigned int) -1) + bzs.total_out_lo32;
527#ifndef ZEND_ENABLE_ZVAL_LONG64
533 dest = zend_string_safe_realloc(dest, 1, bzs.avail_out+1, (
size_t)
size, 0);
537 if (
error == BZ_STREAM_END ||
error == BZ_OK) {
538 size = (bzs.total_out_hi32 * (
unsigned int) -1) + bzs.total_out_lo32;
539#ifndef ZEND_ENABLE_ZVAL_LONG64
542 zend_string_efree(dest);
547 dest = zend_string_safe_realloc(dest, 1, (
size_t)
size, 1, 0);
553 zend_string_efree(dest);
557 BZ2_bzDecompressEnd(&bzs);
569 struct php_bz2_stream_data_t *self;
582 self = (
struct php_bz2_stream_data_t *) stream->
abstract;
585 errstr = BZ2_bzerror(self->bz_file, &errnum);
599 add_assoc_string(
return_value,
"errstr", (
char*)errstr);
file(string $filename, int $flags=0, $context=null)
count(Countable|array $value, int $mode=COUNT_NORMAL)
bzcompress(string $data, int $block_size=4, int $work_factor=0)
bzread($bz, int $length=1024)
bzdecompress(string $data, bool $use_less_memory=false)
bzopen($file, string $mode)
const php_stream_filter_factory php_bz2_filter_factory
zend_ffi_ctype_name_buf buf
PHPAPI int php_check_open_basedir(const char *path)
PHPAPI int php_stream_filter_register_factory(const char *filterpattern, const php_stream_filter_factory *factory)
PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern)
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
php_info_print_table_start()
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_MINFO_FUNCTION
#define PHP_STREAM_IS_BZIP2
#define php_stream_bz2open(wrapper, path, mode, options, opened_path)
#define php_stream_bz2open_from_BZFILE(bz, mode, innerstream)
PHP_BZ2_API php_stream * _php_stream_bz2open_from_BZFILE(BZFILE *bz, const char *mode, php_stream *innerstream STREAMS_DC)
PHP_BZ2_API php_stream * _php_stream_bz2open(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC)
const php_stream_ops php_stream_bz2io_ops
PHP_JSON_API size_t int options
#define php_stream_cast(stream, as, ret, show_err)
struct _php_stream_wrapper_ops php_stream_wrapper_ops
struct _php_stream php_stream
struct _php_stream_context php_stream_context
#define php_stream_from_zval(xstr, pzval)
#define PHP_STREAM_FREE_PRESERVE_HANDLE
#define php_stream_alloc_rel(ops, thisptr, persistent, mode)
PHPAPI zend_string * php_stream_read_to_str(php_stream *stream, size_t len)
#define php_stream_to_zval(stream, zval)
#define php_stream_free(stream, close_options)
#define php_stream_close(stream)
#define PHP_STREAM_FREE_CLOSE
#define php_stream_is(stream, anops)
PHPAPI zend_result php_register_url_stream_wrapper(const char *protocol, const php_stream_wrapper *wrapper)
struct _php_stream_ops php_stream_ops
#define php_stream_open_wrapper(path, mode, options, opened)
struct _php_stream_wrapper php_stream_wrapper
PHPAPI zend_result php_unregister_url_stream_wrapper(const char *protocol)
#define INTERNAL_FUNCTION_PARAMETERS
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
ZEND_API const char * zend_zval_value_name(const zval *arg)
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
ZEND_API ZEND_COLD void zend_argument_must_not_be_empty_error(uint32_t arg_num)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format,...)
#define ZEND_GET_MODULE(name)
#define RETURN_NEW_STR(s)
#define CHECK_ZVAL_NULL_PATH(p)
#define strncasecmp(s1, s2, n)
struct _zend_string zend_string
#define STANDARD_MODULE_HEADER
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES
#define EMPTY_SWITCH_DEFAULT_CASE()
#define UNEXPECTED(condition)
#define Z_STRVAL_P(zval_p)
#define Z_STRLEN_P(zval_p)
CWD_API int virtual_filepath_ex(const char *path, char **filepath, verify_path_func verify_path)
#define VCWD_UNLINK(path)