Implement GH-17668: zlib streams should support locking

This commit is contained in:
Niels Dossche 2025-02-09 20:32:52 +01:00
parent 34e1c590cb
commit 6c706c5714
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
2 changed files with 19 additions and 4 deletions

View file

@ -1,13 +1,13 @@
--TEST-- --TEST--
Test function stream_get_meta_data on a zlib stream Test function flock on a zlib stream
--EXTENSIONS-- --EXTENSIONS--
zlib zlib
--FILE-- --FILE--
<?php <?php
$f = __DIR__."/004.txt.gz"; $f = __DIR__."/004.txt.gz";
$h = gzopen($f,'r'); $h = gzopen($f,'r');
var_dump(flock($h, LOCK_SH)); var_dump(flock($h, LOCK_EX));
gzclose($h); gzclose($h);
?> ?>
--EXPECT-- --EXPECT--
bool(false) bool(true)

View file

@ -95,6 +95,21 @@ static int php_gziop_flush(php_stream *stream)
return gzflush(self->gz_file, Z_SYNC_FLUSH); return gzflush(self->gz_file, Z_SYNC_FLUSH);
} }
static int php_gziop_set_option(php_stream *stream, int option, int value, void *ptrparam)
{
struct php_gz_stream_data_t *self = stream->abstract;
switch (option) {
case PHP_STREAM_OPTION_LOCKING:
case PHP_STREAM_OPTION_META_DATA_API:
return self->stream->ops->set_option(self->stream, option, value, ptrparam);
default:
break;
}
return PHP_STREAM_OPTION_RETURN_NOTIMPL;
}
const php_stream_ops php_stream_gzio_ops = { const php_stream_ops php_stream_gzio_ops = {
php_gziop_write, php_gziop_read, php_gziop_write, php_gziop_read,
php_gziop_close, php_gziop_flush, php_gziop_close, php_gziop_flush,
@ -102,7 +117,7 @@ const php_stream_ops php_stream_gzio_ops = {
php_gziop_seek, php_gziop_seek,
NULL, /* cast */ NULL, /* cast */
NULL, /* stat */ NULL, /* stat */
NULL /* set_option */ php_gziop_set_option /* set_option */
}; };
php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options,