@@ -30,6 +30,18 @@ struct php_gz_stream_data_t {
30
30
php_stream * stream ;
31
31
};
32
32
33
+ static void php_gziop_report_errors (php_stream * stream , size_t count , const char * verb )
34
+ {
35
+ if (!(stream -> flags & PHP_STREAM_FLAG_SUPPRESS_ERRORS )) {
36
+ struct php_gz_stream_data_t * self = stream -> abstract ;
37
+ int error = 0 ;
38
+ gzerror (self -> gz_file , & error );
39
+ if (error == Z_ERRNO ) {
40
+ php_error_docref (NULL , E_NOTICE , "%s of %zu bytes failed with errno=%d %s" , verb , count , errno , strerror (errno ));
41
+ }
42
+ }
43
+ }
44
+
33
45
static ssize_t php_gziop_read (php_stream * stream , char * buf , size_t count )
34
46
{
35
47
struct php_gz_stream_data_t * self = (struct php_gz_stream_data_t * ) stream -> abstract ;
@@ -38,6 +50,11 @@ static ssize_t php_gziop_read(php_stream *stream, char *buf, size_t count)
38
50
/* XXX this needs to be looped for the case count > UINT_MAX */
39
51
read = gzread (self -> gz_file , buf , count );
40
52
53
+ /* Notify user of error, like the standard file wrapper normally does (e.g. errno=13 on mandatory lock failure). */
54
+ if (UNEXPECTED (read < 0 )) {
55
+ php_gziop_report_errors (stream , count , "Read" );
56
+ }
57
+
41
58
if (gzeof (self -> gz_file )) {
42
59
stream -> eof = 1 ;
43
60
}
@@ -50,7 +67,14 @@ static ssize_t php_gziop_write(php_stream *stream, const char *buf, size_t count
50
67
struct php_gz_stream_data_t * self = (struct php_gz_stream_data_t * ) stream -> abstract ;
51
68
52
69
/* XXX this needs to be looped for the case count > UINT_MAX */
53
- return gzwrite (self -> gz_file , (char * ) buf , count );
70
+ int written = gzwrite (self -> gz_file , (char * ) buf , count );
71
+
72
+ /* Notify user of error, like the standard file wrapper normally does (e.g. errno=13 on mandatory lock failure). */
73
+ if (UNEXPECTED (written < 0 )) {
74
+ php_gziop_report_errors (stream , count , "Write" );
75
+ }
76
+
77
+ return written ;
54
78
}
55
79
56
80
static int php_gziop_seek (php_stream * stream , zend_off_t offset , int whence , zend_off_t * newoffs )
0 commit comments