summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/ftruncate_error.phpt
blob: 83569c47d8b2f23da5f7b4840419c177dae291d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
--TEST--
Test ftruncate() function : error conditions
--FILE--
<?php
/*
 Prototype: bool ftruncate ( resource $handle, int $size );
 Description: truncates a file to a given length
*/

echo "*** Testing ftruncate() : error conditions ***\n";

$filename = __DIR__."/ftruncate_error.tmp";
$file_handle = fopen($filename, "w" );
fwrite($file_handle, "Testing ftruncate error conditions \n");
fflush($file_handle);
echo "\n Initial file size = ".filesize($filename)."\n";

// ftruncate() on a file handle which is already closed/unset
echo "-- Testing ftruncate() with closed/unset file handle --\n";

// ftruncate on close file handle
fclose($file_handle);
try {
    var_dump( ftruncate($file_handle,10) );
} catch (TypeError $e) {
    echo $e->getMessage(), "\n";
}
// check the first size
var_dump( filesize($filename) );

echo "Done\n";
?>
--CLEAN--
<?php
$filename = __DIR__."/ftruncate_error.tmp";
unlink( $filename );
?>
--EXPECT--
*** Testing ftruncate() : error conditions ***

 Initial file size = 36
-- Testing ftruncate() with closed/unset file handle --
ftruncate(): supplied resource is not a valid stream resource
int(36)
Done