1--TEST--
2Test ftruncate() function : error conditions
3--FILE--
4<?php
5echo "*** Testing ftruncate() : error conditions ***\n";
6
7$filename = __DIR__."/ftruncate_error.tmp";
8$file_handle = fopen($filename, "w" );
9fwrite($file_handle, "Testing ftruncate error conditions \n");
10fflush($file_handle);
11echo "\n Initial file size = ".filesize($filename)."\n";
12
13// ftruncate() on a file handle which is already closed/unset
14echo "-- Testing ftruncate() with closed/unset file handle --\n";
15
16// ftruncate on close file handle
17fclose($file_handle);
18try {
19    var_dump( ftruncate($file_handle,10) );
20} catch (TypeError $e) {
21    echo $e->getMessage(), "\n";
22}
23// check the first size
24var_dump( filesize($filename) );
25
26echo "Done\n";
27?>
28--CLEAN--
29<?php
30$filename = __DIR__."/ftruncate_error.tmp";
31unlink( $filename );
32?>
33--EXPECT--
34*** Testing ftruncate() : error conditions ***
35
36 Initial file size = 36
37-- Testing ftruncate() with closed/unset file handle --
38ftruncate(): supplied resource is not a valid stream resource
39int(36)
40Done
41