Create post-HADVAs expect files
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / file / fopen_variation19.php
blob58e86b154c16d629daf9ccdc186b0218971213d8
1 <?hh
2 /* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
3 * Description: Open a file or a URL and return a file pointer
4 * Source code: ext/standard/file.c
5 * Alias to functions:
6 */
8 function readFile2($file) {
9 $h = fopen($file, 'r');
10 fpassthru($h);
11 fclose($h);
12 echo "\n";
15 function appendFile($file) {
16 $h = fopen($file, 'a+');
17 fwrite($h, ' again!');
18 fseek($h, 0);
19 fpassthru($h);
20 fclose($h);
21 echo "\n";
24 function writeFile($file) {
25 $h = fopen($file, 'w');
26 fwrite($h, 'Goodbye World');
27 fclose($h);
28 readFile2($file);
30 <<__EntryPoint>> function main(): void {
31 $tmpDir = __SystemLib\hphp_test_tmppath('fopenVar19.Dir');
32 $realFilename = basename(__FILE__).'.real';
33 $sortFilename = basename(__FILE__).'.soft';
34 $hardFilename = basename(__FILE__).'.hard';
35 $linkOfLink = basename(__FILE__).'.soft2';
37 echo "*** Testing fopen() : variation ***\n";
38 // start the test
39 mkdir($tmpDir);
40 $oldDirPath = getcwd();
41 chdir($tmpDir);
43 $h = fopen($realFilename, "w");
44 fwrite($h, "Hello World");
45 fclose($h);
47 symlink($realFilename, $sortFilename);
48 symlink($sortFilename, $linkOfLink);
49 link($realFilename, $hardFilename);
53 echo "*** testing reading of links ***\n";
54 echo "soft link:";
55 readFile2($sortFilename);
56 echo "hard link:";
57 readFile2($hardFilename);
58 echo "link of link:";
59 readFile2($linkOfLink);
61 echo "*** test appending to links ***\n";
62 echo "soft link:";
63 appendFile($sortFilename);
64 echo "hard link:";
65 appendFile($hardFilename);
66 echo "link of link:";
67 appendFile($linkOfLink);
69 echo "*** test overwriting links ***\n";
70 echo "soft link:";
71 writeFile($sortFilename);
72 echo "hard link:";
73 writeFile($hardFilename);
74 echo "link of link:";
75 writeFile($linkOfLink);
77 unlink($linkOfLink);
78 unlink($sortFilename);
79 unlink($hardFilename);
80 unlink($realFilename);
81 chdir($oldDirPath);
82 rmdir($tmpDir);
84 echo "===DONE===\n";