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/* Prototype  : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
13 * Description: Open a file or a URL and return a file pointer
14 * Source code: ext/standard/file.c
15 * Alias to functions:
16 */
17
18$tmpDir = 'fopenVar19.Dir';
19$realFilename = __FILE__.'.real';
20$sortFilename = __FILE__.'.soft';
21$hardFilename = __FILE__.'.hard';
22$linkOfLink = __FILE__.'.soft2';
23
24echo "*** Testing fopen() : variation ***\n";
25// start the test
26mkdir($tmpDir);
27chdir($tmpDir);
28
29$h = fopen($realFilename, "w");
30fwrite($h, "Hello World");
31fclose($h);
32
33symlink($realFilename, $sortFilename);
34symlink($sortFilename, $linkOfLink);
35link($realFilename, $hardFilename);
36
37
38
39echo "*** testing reading of links ***\n";
40echo "soft link:";
41readFile2($sortFilename);
42echo "hard link:";
43readFile2($hardFilename);
44echo "link of link:";
45readFile2($linkOfLink);
46
47echo "*** test appending to links ***\n";
48echo "soft link:";
49appendFile($sortFilename);
50echo "hard link:";
51appendFile($hardFilename);
52echo "link of link:";
53appendFile($linkOfLink);
54
55echo "*** test overwriting links ***\n";
56echo "soft link:";
57writeFile($sortFilename);
58echo "hard link:";
59writeFile($hardFilename);
60echo "link of link:";
61writeFile($linkOfLink);
62
63unlink($linkOfLink);
64unlink($sortFilename);
65unlink($hardFilename);
66unlink($realFilename);
67chdir("..");
68rmdir($tmpDir);
69
70function readFile2($file) {
71   $h = fopen($file, 'r');
72   fpassthru($h);
73   fclose($h);
74   echo "\n";
75}
76
77function appendFile($file) {
78   $h = fopen($file, 'a+');
79   fwrite($h, ' again!');
80   fseek($h, 0);
81   fpassthru($h);
82   fclose($h);
83   echo "\n";
84}
85
86function writeFile($file) {
87   $h = fopen($file, 'w');
88   fwrite($h, 'Goodbye World');
89   fclose($h);
90   readFile2($file);
91}
92
93
94?>
95===DONE===
96--EXPECT--
97*** Testing fopen() : variation ***
98*** testing reading of links ***
99soft link:Hello World
100hard link:Hello World
101link of link:Hello World
102*** test appending to links ***
103soft link:Hello World again!
104hard link:Hello World again! again!
105link of link:Hello World again! again! again!
106*** test overwriting links ***
107soft link:Goodbye World
108hard link:Goodbye World
109link of link:Goodbye World
110===DONE===
111