1--TEST--
2Test fopen() function : variation: interesting paths, no use include path
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php
7if(substr(PHP_OS, 0, 3) != "WIN")
8  die("skip Run only on Windows");
9
10if (!is_writable('c:\\fopen_variation10.tmp')) {
11	die('skip. C:\\ not writable.');
12}
13
14?>
15--FILE--
16<?php
17/* Prototype  : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
18 * Description: Open a file or a URL and return a file pointer
19 * Source code: ext/standard/file.c
20 * Alias to functions:
21 */
22
23echo "*** Testing fopen() : variation ***\n";
24
25// fopen with interesting windows paths.
26$testdir = dirname(__FILE__).'/fopen10.tmpDir';
27$rootdir = 'fopen10.tmpdirTwo';
28mkdir($testdir);
29mkdir('c:\\'.$rootdir);
30
31$unixifiedDir = '/'.substr(str_replace('\\','/',$testdir),3);
32
33$paths = array('c:\\',
34               'c:',
35               'c',
36               '\\',
37               '/',
38               'c:'.$rootdir,
39               'c:adir',
40               'c:\\/',
41               'c:\\'.$rootdir.'\\/',
42               'c:\\'.$rootdir.'\\',
43               'c:\\'.$rootdir.'/',
44               $unixifiedDir,
45               '/sortout');
46
47$file = "fopen_variation10.tmp";
48$firstfile = 'c:\\'.$rootdir.'\\'.$file;
49$secondfile = $testdir.'\\'.$file;
50$thirdfile = 'c:\\'.$file;
51
52$h = fopen($firstfile, 'w');
53fwrite($h, "file in $rootdir");
54fclose($h);
55
56$h = fopen($secondfile, 'w');
57fwrite($h, "file in fopen10.tmpDir");
58fclose($h);
59
60$h = fopen($thirdfile, 'w');
61fwrite($h, "file in root");
62fclose($h);
63
64foreach($paths as $path) {
65      echo "\n--$path--\n";
66      $toFind = $path.'\\'.$file;
67         $h = fopen($toFind, 'r');
68         if ($h === false) {
69            echo "file not opened for read\n";
70         }
71         else {
72            fpassthru($h);
73            echo "\n";
74         }
75         fclose($h);
76};
77
78unlink($firstfile);
79unlink($secondfile);
80unlink($thirdfile);
81rmdir($testdir);
82rmdir('c:\\'.$rootdir);
83
84
85?>
86===DONE===
87--EXPECTF--
88*** Testing fopen() : variation ***
89
90--c:\--
91file in root
92
93--c:--
94file in root
95
96--c--
97
98Warning: fopen(c\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d
99file not opened for read
100
101Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
102
103--\--
104
105Warning: fopen(\\fopen_variation10.tmp): failed to open stream: Invalid argument in %s on line %d
106file not opened for read
107
108Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
109
110--/--
111
112Warning: fopen(/\fopen_variation10.tmp): failed to open stream: Invalid argument in %s on line %d
113file not opened for read
114
115Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
116
117--c:fopen10.tmpdirTwo--
118file in fopen10.tmpdirTwo
119
120--c:adir--
121
122Warning: fopen(c:adir\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d
123file not opened for read
124
125Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
126
127--c:\/--
128file in root
129
130--c:\fopen10.tmpdirTwo\/--
131file in fopen10.tmpdirTwo
132
133--c:\fopen10.tmpdirTwo\--
134file in fopen10.tmpdirTwo
135
136--c:\fopen10.tmpdirTwo/--
137file in fopen10.tmpdirTwo
138
139--%s/fopen10.tmpDir--
140file in fopen10.tmpDir
141
142--/sortout--
143
144Warning: fopen(/sortout\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d
145file not opened for read
146
147Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
148===DONE===
149
150