--- /dev/null
+--TEST--\r
+Bug #76803 ftruncate changes file pointer\r
+--FILE--\r
+<?php\r
+\r
+$fn = dirname(__FILE__) . DIRECTORY_SEPARATOR . "test76803";\r
+\r
+$f = fopen($fn, "w");\r
+fwrite($f, "Hello");\r
+ftruncate($f, 2);\r
+fwrite($f, "World");\r
+fclose($f);\r
+var_dump(addslashes(file_get_contents($fn)));\r
+\r
+$f = fopen($fn, "w");\r
+fwrite($f, "Hello");\r
+ftruncate($f, 2);\r
+fclose($f);\r
+var_dump(addslashes(file_get_contents($fn)));\r
+\r
+$f = fopen('php://memory', 'w+');\r
+fwrite($f, 'Hello');\r
+ftruncate($f, 2); // in 7.3 changes file pointer to 2\r
+fwrite($f, 'World');\r
+rewind($f);\r
+var_dump(addslashes(stream_get_contents($f)));\r
+fclose($f);\r
+\r
+?>\r
+--CLEAN--\r
+<?php\r
+$fn = dirname(__FILE__) . DIRECTORY_SEPARATOR . "test76803";\r
+unlink($fn);\r
+?>\r
+--EXPECT--\r
+string(13) "He\0\0\0World"\r
+string(2) "He"\r
+string(7) "HeWorld"\r
if (INVALID_HANDLE_VALUE == h) {
return PHP_STREAM_OPTION_RETURN_ERR;
}
+
+ LARGE_INTEGER old_sz;
+ if (!GetFileSizeEx(h, &old_sz)) {
+ return PHP_STREAM_OPTION_RETURN_ERR;
+ }
+
LARGE_INTEGER sz;
#if defined(_WIN64)
sz.HighPart = (new_size >> 32);
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()) {
+ return PHP_STREAM_OPTION_RETURN_ERR;
+ }
return PHP_STREAM_OPTION_RETURN_OK;
#else
return ftruncate(fd, new_size) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;