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:\\')) {
11    die('skip. C:\\ not writable.');
12}
13
14?>
15--FILE--
16<?php
17echo "*** Testing fopen() : variation ***\n";
18
19// fopen with interesting windows paths.
20$testdir = __DIR__.'/fopen10.tmpDir';
21$rootdir = 'fopen10.tmpdirTwo';
22mkdir($testdir);
23mkdir('c:\\'.$rootdir);
24
25$unixifiedDir = '/'.substr(str_replace('\\','/',$testdir),3);
26
27$paths = array('c:\\',
28               'c:',
29               'c',
30               '\\',
31               '/',
32               'c:'.$rootdir,
33               'c:adir',
34               'c:\\/',
35               'c:\\'.$rootdir.'\\/',
36               'c:\\'.$rootdir.'\\',
37               'c:\\'.$rootdir.'/',
38               $unixifiedDir,
39               '/sortout');
40
41$file = "fopen_variation10.tmp";
42$firstfile = 'c:\\'.$rootdir.'\\'.$file;
43$secondfile = $testdir.'\\'.$file;
44$thirdfile = 'c:\\'.$file;
45
46$h = fopen($firstfile, 'w');
47fwrite($h, "file in $rootdir");
48fclose($h);
49
50$h = fopen($secondfile, 'w');
51fwrite($h, "file in fopen10.tmpDir");
52fclose($h);
53
54$h = fopen($thirdfile, 'w');
55fwrite($h, "file in root");
56fclose($h);
57
58foreach($paths as $path) {
59      echo "\n--$path--\n";
60      $toFind = $path.'\\'.$file;
61         $h = fopen($toFind, 'r');
62         if ($h === false) {
63            echo "file not opened for read\n";
64         }
65         else {
66            fpassthru($h);
67            fclose($h);
68            echo "\n";
69         }
70};
71
72unlink($firstfile);
73unlink($secondfile);
74unlink($thirdfile);
75rmdir($testdir);
76rmdir('c:\\'.$rootdir);
77
78
79?>
80--EXPECTF--
81*** Testing fopen() : variation ***
82
83--c:\--
84file in root
85
86--c:--
87file in root
88
89--c--
90
91Warning: fopen(c\fopen_variation10.tmp): Failed to open stream: No such file or directory in %s on line %d
92file not opened for read
93
94--\--
95
96Warning: fopen(\\fopen_variation10.tmp): Failed to open stream: No such file or directory in %s on line %d
97file not opened for read
98
99--/--
100
101Warning: fopen(/\fopen_variation10.tmp): Failed to open stream: No such file or directory in %s on line %d
102file not opened for read
103
104--c:fopen10.tmpdirTwo--
105file in fopen10.tmpdirTwo
106
107--c:adir--
108
109Warning: fopen(c:adir\fopen_variation10.tmp): Failed to open stream: No such file or directory in %s on line %d
110file not opened for read
111
112--c:\/--
113file in root
114
115--c:\fopen10.tmpdirTwo\/--
116file in fopen10.tmpdirTwo
117
118--c:\fopen10.tmpdirTwo\--
119file in fopen10.tmpdirTwo
120
121--c:\fopen10.tmpdirTwo/--
122file in fopen10.tmpdirTwo
123
124--%s/fopen10.tmpDir--
125file in fopen10.tmpDir
126
127--/sortout--
128
129Warning: fopen(/sortout\fopen_variation10.tmp): Failed to open stream: No such file or directory in %s on line %d
130file not opened for read
131