xref: /PHP-7.2/ext/standard/tests/file/ftruncate.phpt (revision 17ccbeec)
1--TEST--
2ftruncate() tests
3--FILE--
4<?php
5
6$filename = dirname(__FILE__)."/ftruncate.dat";
7
8file_put_contents($filename, "some test data inside");
9
10$fp = fopen($filename, "r");
11var_dump(ftruncate($fp, 10));
12fclose($fp);
13var_dump(file_get_contents($filename));
14
15$fp = fopen($filename, "w");
16var_dump(ftruncate($fp, 10));
17fclose($fp);
18var_dump(file_get_contents($filename));
19
20file_put_contents($filename, "some test data inside");
21
22$fp = fopen($filename, "a");
23var_dump(ftruncate($fp, 10));
24fclose($fp);
25var_dump(file_get_contents($filename));
26
27$fp = fopen($filename, "a");
28var_dump(ftruncate($fp, 0));
29fclose($fp);
30var_dump(file_get_contents($filename));
31
32file_put_contents($filename, "some test data inside");
33
34$fp = fopen($filename, "a");
35var_dump(ftruncate($fp, -1000000000));
36fclose($fp);
37var_dump(file_get_contents($filename));
38
39@unlink($filename);
40echo "Done\n";
41?>
42--EXPECTF--
43bool(false)
44string(21) "some test data inside"
45bool(true)
46string(10) "����������"
47bool(true)
48string(10) "some test "
49bool(true)
50string(0) ""
51
52Warning: ftruncate(): Negative size is not supported in %s on line %d
53bool(false)
54string(21) "some test data inside"
55Done
56