Skip to content

Commit 6c706c5

Browse files
committed
Implement GH-17668: zlib streams should support locking
1 parent 34e1c59 commit 6c706c5

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
--TEST--
2-
Test function stream_get_meta_data on a zlib stream
2+
Test function flock on a zlib stream
33
--EXTENSIONS--
44
zlib
55
--FILE--
66
<?php
77
$f = __DIR__."/004.txt.gz";
88
$h = gzopen($f,'r');
9-
var_dump(flock($h, LOCK_SH));
9+
var_dump(flock($h, LOCK_EX));
1010
gzclose($h);
1111
?>
1212
--EXPECT--
13-
bool(false)
13+
bool(true)

ext/zlib/zlib_fopen_wrapper.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,29 @@ static int php_gziop_flush(php_stream *stream)
9595
return gzflush(self->gz_file, Z_SYNC_FLUSH);
9696
}
9797

98+
static int php_gziop_set_option(php_stream *stream, int option, int value, void *ptrparam)
99+
{
100+
struct php_gz_stream_data_t *self = stream->abstract;
101+
102+
switch (option) {
103+
case PHP_STREAM_OPTION_LOCKING:
104+
case PHP_STREAM_OPTION_META_DATA_API:
105+
return self->stream->ops->set_option(self->stream, option, value, ptrparam);
106+
default:
107+
break;
108+
}
109+
110+
return PHP_STREAM_OPTION_RETURN_NOTIMPL;
111+
}
112+
98113
const php_stream_ops php_stream_gzio_ops = {
99114
php_gziop_write, php_gziop_read,
100115
php_gziop_close, php_gziop_flush,
101116
"ZLIB",
102117
php_gziop_seek,
103118
NULL, /* cast */
104119
NULL, /* stat */
105-
NULL /* set_option */
120+
php_gziop_set_option /* set_option */
106121
};
107122

108123
php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options,

0 commit comments

Comments
 (0)