1--TEST--
2Test fopen() function : variation: test opening linked files
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php
7if(substr(PHP_OS, 0, 3) == "WIN")
8  die("skip Not for Windows");
9?>
10--FILE--
11<?php
12$tmpDir = 'fopenVar19.Dir';
13$realFilename = __FILE__.'.real';
14$sortFilename = __FILE__.'.soft';
15$hardFilename = __FILE__.'.hard';
16$linkOfLink = __FILE__.'.soft2';
17
18echo "*** Testing fopen() : variation ***\n";
19// start the test
20mkdir($tmpDir);
21chdir($tmpDir);
22
23$h = fopen($realFilename, "w");
24fwrite($h, "Hello World");
25fclose($h);
26
27symlink($realFilename, $sortFilename);
28symlink($sortFilename, $linkOfLink);
29link($realFilename, $hardFilename);
30
31
32
33echo "*** testing reading of links ***\n";
34echo "soft link:";
35readFile2($sortFilename);
36echo "hard link:";
37readFile2($hardFilename);
38echo "link of link:";
39readFile2($linkOfLink);
40
41echo "*** test appending to links ***\n";
42echo "soft link:";
43appendFile($sortFilename);
44echo "hard link:";
45appendFile($hardFilename);
46echo "link of link:";
47appendFile($linkOfLink);
48
49echo "*** test overwriting links ***\n";
50echo "soft link:";
51writeFile($sortFilename);
52echo "hard link:";
53writeFile($hardFilename);
54echo "link of link:";
55writeFile($linkOfLink);
56
57unlink($linkOfLink);
58unlink($sortFilename);
59unlink($hardFilename);
60unlink($realFilename);
61chdir("..");
62rmdir($tmpDir);
63
64function readFile2($file) {
65   $h = fopen($file, 'r');
66   fpassthru($h);
67   fclose($h);
68   echo "\n";
69}
70
71function appendFile($file) {
72   $h = fopen($file, 'a+');
73   fwrite($h, ' again!');
74   fseek($h, 0);
75   fpassthru($h);
76   fclose($h);
77   echo "\n";
78}
79
80function writeFile($file) {
81   $h = fopen($file, 'w');
82   fwrite($h, 'Goodbye World');
83   fclose($h);
84   readFile2($file);
85}
86
87
88?>
89--EXPECT--
90*** Testing fopen() : variation ***
91*** testing reading of links ***
92soft link:Hello World
93hard link:Hello World
94link of link:Hello World
95*** test appending to links ***
96soft link:Hello World again!
97hard link:Hello World again! again!
98link of link:Hello World again! again! again!
99*** test overwriting links ***
100soft link:Goodbye World
101hard link:Goodbye World
102link of link:Goodbye World
103