@@ -30,6 +30,18 @@ struct php_gz_stream_data_t {
3030 php_stream * stream ;
3131};
3232
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+
3345static ssize_t php_gziop_read (php_stream * stream , char * buf , size_t count )
3446{
3547 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)
3850 /* XXX this needs to be looped for the case count > UINT_MAX */
3951 read = gzread (self -> gz_file , buf , count );
4052
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+
4158 if (gzeof (self -> gz_file )) {
4259 stream -> eof = 1 ;
4360 }
@@ -50,7 +67,14 @@ static ssize_t php_gziop_write(php_stream *stream, const char *buf, size_t count
5067 struct php_gz_stream_data_t * self = (struct php_gz_stream_data_t * ) stream -> abstract ;
5168
5269 /* 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 ;
5478}
5579
5680static int php_gziop_seek (php_stream * stream , zend_off_t offset , int whence , zend_off_t * newoffs )
0 commit comments