mirror of
https://github.com/php/php-src.git
synced 2024-11-28 20:34:29 +08:00
Merge branch 'PHP-7.3'
* PHP-7.3: Fix error condition Fixed bug #77081 ftruncate() changes seek pointer in c mode
This commit is contained in:
commit
9c9178af51
24
ext/standard/tests/file/ftruncate_bug77081.phpt
Normal file
24
ext/standard/tests/file/ftruncate_bug77081.phpt
Normal file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
Bug #77081 ftruncate() changes seek pointer in c mode
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . "test77081";
|
||||
|
||||
file_put_contents($filename, 'foo');
|
||||
$stream = fopen($filename, 'c');
|
||||
ftruncate($stream, 0);
|
||||
var_dump(ftell($stream));
|
||||
fwrite($stream, 'bar');
|
||||
fclose($stream);
|
||||
var_dump(file_get_contents($filename));
|
||||
|
||||
?>
|
||||
--CLEAN--
|
||||
<?php
|
||||
$fn = dirname(__FILE__) . DIRECTORY_SEPARATOR . "test77081";
|
||||
unlink($fn);
|
||||
?>
|
||||
--EXPECT--
|
||||
int(0)
|
||||
string(3) "bar"
|
@ -858,12 +858,13 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
|
||||
return PHP_STREAM_OPTION_RETURN_ERR;
|
||||
}
|
||||
|
||||
LARGE_INTEGER old_sz;
|
||||
if (!GetFileSizeEx(h, &old_sz)) {
|
||||
LARGE_INTEGER sz, old_sz;
|
||||
sz.QuadPart = 0;
|
||||
|
||||
if (!SetFilePointerEx(h, sz, &old_sz, FILE_CURRENT)) {
|
||||
return PHP_STREAM_OPTION_RETURN_ERR;
|
||||
}
|
||||
|
||||
LARGE_INTEGER sz;
|
||||
#if defined(_WIN64)
|
||||
sz.HighPart = (new_size >> 32);
|
||||
sz.LowPart = (new_size & 0xffffffff);
|
||||
@ -871,13 +872,13 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
|
||||
sz.HighPart = 0;
|
||||
sz.LowPart = new_size;
|
||||
#endif
|
||||
if (INVALID_SET_FILE_POINTER == SetFilePointerEx(h, sz, NULL, FILE_BEGIN) && NO_ERROR != GetLastError()) {
|
||||
if (!SetFilePointerEx(h, sz, NULL, FILE_BEGIN)) {
|
||||
return PHP_STREAM_OPTION_RETURN_ERR;
|
||||
}
|
||||
if (0 == SetEndOfFile(h)) {
|
||||
return PHP_STREAM_OPTION_RETURN_ERR;
|
||||
}
|
||||
if (INVALID_SET_FILE_POINTER == SetFilePointerEx(h, old_sz, NULL, FILE_BEGIN) && NO_ERROR != GetLastError()) {
|
||||
if (!SetFilePointerEx(h, old_sz, NULL, FILE_BEGIN)) {
|
||||
return PHP_STREAM_OPTION_RETURN_ERR;
|
||||
}
|
||||
return PHP_STREAM_OPTION_RETURN_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user