1--TEST-- 2Bug #76422 ftruncate fails on files > 2GB 3--SKIPIF-- 4<?php 5if (PHP_INT_SIZE < 8) { 6 die('skip.. only valid for 64-bit'); 7} 8if (disk_free_space(__DIR__) <= 4.1 * 1024 * 1024 * 1024 ) { 9 // Add a bit of extra overhead for other processes, temporary files created while running tests, etc. 10 die('skip.. This test requires over 4GB of free disk space on this disk partition'); 11} 12?> 13--FILE-- 14<?php 15 16$fn = __DIR__ . DIRECTORY_SEPARATOR . "test76422"; 17 18$file_handle = fopen($fn,'cb'); 19 20if (false === $file_handle) { 21 die('Cannot open test file :/'); 22} 23 24/* Check if ftruncate() with 2GB works. If it doesn't, it's likely that large files are 25 * generally not supported (EFBIG). */ 26$truncate_offset = 2 * 1024 * 1024 * 1024; 27$ftruncate_result = ftruncate($file_handle, $truncate_offset); 28if (false === $ftruncate_result) { 29 var_dump(true); 30 fclose($file_handle); 31 unlink($fn); 32 return; 33} 34 35$truncate_offset = 4 * 1024 * 1024 * 1024 + 1; 36$ftruncate_result = ftruncate($file_handle, $truncate_offset); 37 38if (false === $ftruncate_result) { 39 // NOTE: unlink() is deliberately repeated - If this test runs out of disk space attempting to reserve space for this temporary file, 40 // then the--CLEAN-- script can't be run (if we don't delete the file), 41 // because there wouldn't be any free disk space to save a new php file. 42 fclose($file_handle); 43 unlink($fn); 44 die('Truncate has failed :/'); 45} 46 47fclose($file_handle); 48var_dump(filesize($fn) >= $truncate_offset); 49unlink($fn); 50?> 51--CLEAN-- 52<?php 53$fn = __DIR__ . "/test76422"; 54@unlink($fn); 55?> 56--EXPECT-- 57bool(true) 58