1--TEST--
2chmod() with various paths
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip Windows only chmod test');
7}
8?>
9--FILE--
10<?php
11
12define("PERMISSIONS_MASK", 0777);
13
14$script_directory = __DIR__;
15chdir($script_directory);
16$test_dirname = basename(__FILE__, ".php") . "testdir私はガラスを食べられます";
17mkdir($test_dirname);
18
19$filepath = __FILE__ . ".tmp";
20$filename = basename($filepath);
21$fd = fopen($filepath, "w+");
22fclose($fd);
23
24echo "chmod() on a path containing .. and .\n";
25var_dump(chmod("./$test_dirname/../$filename", 0777));
26var_dump(chmod("./$test_dirname/../$filename", 0755));
27clearstatcache();
28printf("%o\n", fileperms($filepath) & PERMISSIONS_MASK);
29
30echo "\nchmod() on a path containing .. with invalid directories\n";
31var_dump(chmod($filepath, 0777));
32var_dump(chmod("./$test_dirname/bad_dir/../../$filename", 0755));
33clearstatcache();
34printf("%o\n", fileperms($filepath) & PERMISSIONS_MASK);
35
36echo "\nchmod() on a relative path from a different working directory\n";
37chdir($test_dirname);
38var_dump(chmod("../$filename", 0777));
39var_dump(chmod("../$filename", 0755));
40clearstatcache();
41printf("%o\n", fileperms($filepath) & PERMISSIONS_MASK);
42chdir($script_directory);
43
44echo "\nchmod() on a directory with a trailing /\n";
45var_dump(chmod($test_dirname, 0777));
46var_dump(chmod("$test_dirname/", 0775));
47clearstatcache();
48printf("%o\n", fileperms($filepath) & PERMISSIONS_MASK);
49
50chdir($script_directory);
51rmdir($test_dirname);
52unlink($filepath);
53
54?>
55--EXPECT--
56chmod() on a path containing .. and .
57bool(true)
58bool(true)
59666
60
61chmod() on a path containing .. with invalid directories
62bool(true)
63bool(true)
64666
65
66chmod() on a relative path from a different working directory
67bool(true)
68bool(true)
69666
70
71chmod() on a directory with a trailing /
72bool(true)
73bool(true)
74666
75