mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
d59aac58b3
The php_stream_read() and php_stream_write() functions now return an ssize_t value, with negative results indicating failure. Functions like fread() and fwrite() will return false in that case. As a special case, EWOULDBLOCK and EAGAIN on non-blocking streams should not be regarded as error conditions, and be reported as successful zero-length reads/writes instead. The handling of EINTR remains unclear and is internally inconsistent (e.g. some code-paths will automatically retry on EINTR, while some won't). I'm landing this now to make sure the stream wrapper ops API changes make it into 7.4 -- however, if the user-facing changes turn out to be problematic we have the option of clamping negative returns to zero in php_stream_read() and php_stream_write() to restore the old behavior in a relatively non-intrusive manner.
112 lines
2.0 KiB
PHP
112 lines
2.0 KiB
PHP
--TEST--
|
|
bzread() tests with invalid files
|
|
--SKIPIF--
|
|
<?php if (!extension_loaded("bz2")) print "skip"; ?>
|
|
--FILE--
|
|
<?php
|
|
|
|
$fd = bzopen(__DIR__."/004_1.txt.bz2","r");
|
|
var_dump(bzerror($fd));
|
|
var_dump(bzerrstr($fd));
|
|
var_dump(bzerrno($fd));
|
|
|
|
$fd2 = bzopen(__DIR__."/004_2.txt.bz2","r");
|
|
var_dump(bzerror($fd2));
|
|
var_dump(bzerrstr($fd2));
|
|
var_dump(bzerrno($fd2));
|
|
|
|
var_dump(bzread($fd, 10));
|
|
var_dump(bzerror($fd));
|
|
var_dump(bzerrstr($fd));
|
|
var_dump(bzerrno($fd));
|
|
|
|
var_dump(bzread($fd2, 10));
|
|
var_dump(bzerror($fd2));
|
|
var_dump(bzerrstr($fd2));
|
|
var_dump(bzerrno($fd2));
|
|
|
|
var_dump(bzread($fd));
|
|
var_dump(bzerror($fd));
|
|
var_dump(bzerrstr($fd));
|
|
var_dump(bzerrno($fd));
|
|
|
|
var_dump(bzread($fd2));
|
|
var_dump(bzerror($fd2));
|
|
var_dump(bzerrstr($fd2));
|
|
var_dump(bzerrno($fd2));
|
|
|
|
bzclose($fd2);
|
|
var_dump(bzread($fd2));
|
|
var_dump(bzerror($fd2));
|
|
var_dump(bzerrstr($fd2));
|
|
var_dump(bzerrno($fd2));
|
|
|
|
echo "Done\n";
|
|
?>
|
|
--EXPECTF--
|
|
array(2) {
|
|
["errno"]=>
|
|
int(0)
|
|
["errstr"]=>
|
|
string(2) "OK"
|
|
}
|
|
string(2) "OK"
|
|
int(0)
|
|
array(2) {
|
|
["errno"]=>
|
|
int(0)
|
|
["errstr"]=>
|
|
string(2) "OK"
|
|
}
|
|
string(2) "OK"
|
|
int(0)
|
|
bool(false)
|
|
array(2) {
|
|
["errno"]=>
|
|
int(-5)
|
|
["errstr"]=>
|
|
string(16) "DATA_ERROR_MAGIC"
|
|
}
|
|
string(16) "DATA_ERROR_MAGIC"
|
|
int(-5)
|
|
bool(false)
|
|
array(2) {
|
|
["errno"]=>
|
|
int(-4)
|
|
["errstr"]=>
|
|
string(10) "DATA_ERROR"
|
|
}
|
|
string(10) "DATA_ERROR"
|
|
int(-4)
|
|
bool(false)
|
|
array(2) {
|
|
["errno"]=>
|
|
int(-5)
|
|
["errstr"]=>
|
|
string(16) "DATA_ERROR_MAGIC"
|
|
}
|
|
string(16) "DATA_ERROR_MAGIC"
|
|
int(-5)
|
|
bool(false)
|
|
array(2) {
|
|
["errno"]=>
|
|
int(-4)
|
|
["errstr"]=>
|
|
string(10) "DATA_ERROR"
|
|
}
|
|
string(10) "DATA_ERROR"
|
|
int(-4)
|
|
|
|
Warning: bzread(): supplied resource is not a valid stream resource in %s on line %d
|
|
bool(false)
|
|
|
|
Warning: bzerror(): supplied resource is not a valid stream resource in %s on line %d
|
|
bool(false)
|
|
|
|
Warning: bzerrstr(): supplied resource is not a valid stream resource in %s on line %d
|
|
bool(false)
|
|
|
|
Warning: bzerrno(): supplied resource is not a valid stream resource in %s on line %d
|
|
bool(false)
|
|
Done
|