--- /dev/null
+--TEST--\r
+Bug #76422 ftruncate fails on files > 2GB\r
+--SKIPIF--\r
+<?php\r
+if (PHP_INT_SIZE < 8) {\r
+ die('skip.. only valid for 64-bit');\r
+}\r
+?>\r
+--FILE--\r
+<?php\r
+\r
+$fn = dirname(__FILE__) . DIRECTORY_SEPARATOR . "test76422";\r
+\r
+$file_handle = fopen($fn,'cb');\r
+\r
+if (false === $file_handle) {\r
+ die('Cannot open test file :/');\r
+}\r
+\r
+$truncate_offset = 4 * 1024 * 1024 * 1024 + 1;\r
+$ftruncate_result = ftruncate($file_handle, $truncate_offset);\r
+\r
+if (false === $ftruncate_result) {\r
+ die('Truncate has failed :/');\r
+}\r
+\r
+fclose($file_handle);\r
+var_dump(filesize($fn) >= $truncate_offset);\r
+?>\r
+--CLEAN--\r
+<?php\r
+$fn = dirname(__FILE__) . "/test76422";\r
+unlink($fn);\r
+?>\r
+--EXPECT--\r
+bool(true)\r
-- Testing ftruncate(): truncate file to size = current size --
int(1024)
int(0)
-bool(true)
+bool(false)
int(0)
bool(false)
int(1024)
-- Testing ftruncate(): truncate file to size = current size --
int(1024)
int(0)
-bool(true)
+bool(false)
int(0)
bool(false)
int(1024)
-- Testing ftruncate(): truncate file to size = current size --
int(1024)
int(0)
-bool(true)
+bool(false)
int(0)
bool(false)
int(1024)
-- Testing ftruncate(): truncate file to size = current size --
int(1024)
int(0)
-bool(true)
+bool(false)
int(0)
bool(false)
int(1024)
-- Testing ftruncate(): truncate file to size = current size --
int(1024)
int(0)
-bool(true)
+bool(false)
int(0)
bool(false)
int(1024)
-- Testing ftruncate(): truncate file to size = current size --
int(1024)
int(0)
-bool(true)
+bool(false)
int(0)
bool(false)
int(1024)
if (new_size < 0) {
return PHP_STREAM_OPTION_RETURN_ERR;
}
+#ifdef PHP_WIN32
+ HANDLE h = (HANDLE) _get_osfhandle(fd);
+ if (INVALID_HANDLE_VALUE == h) {
+ return PHP_STREAM_OPTION_RETURN_ERR;
+ }
+ LARGE_INTEGER sz;
+#if defined(_WIN64)
+ sz.HighPart = (new_size >> 32);
+ sz.LowPart = (new_size & 0xffffffff);
+#else
+ sz.HighPart = 0;
+ sz.LowPart = new_size;
+#endif
+ if (INVALID_SET_FILE_POINTER == SetFilePointerEx(h, sz, NULL, FILE_BEGIN) && NO_ERROR != GetLastError()) {
+ return PHP_STREAM_OPTION_RETURN_ERR;
+ }
+ if (0 == SetEndOfFile(h)) {
+ 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;
+#endif
}
}