1--TEST--
2Test fileperms() & chmod() functions: usage variation - misc. perms
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip Not on Windows');
7}
8// Skip if being run by root
9$filename = dirname(__FILE__)."/006_root_check.tmp";
10$fp = fopen($filename, 'w');
11fclose($fp);
12if(fileowner($filename) == 0) {
13        unlink ($filename);
14        die('skip cannot be run as root');
15}
16
17unlink($filename);
18
19?>
20--FILE--
21<?php
22/*
23  Prototype: int fileperms ( string $filename );
24  Description: Returns the permissions on the file, or FALSE in case of an error
25
26  Prototype: bool chmod ( string $filename, int $mode );
27  Description: Attempts to change the mode of the file specified by
28               filename to that given in mode
29*/
30
31/* Testing with miscellaneous Permission */
32
33echo "*** Testing fileperms() & chmod() : usage variations ***\n";
34
35$file_name = dirname(__FILE__)."/006_variation2.tmp";
36$file_handle = fopen($file_name, "w");
37fclose($file_handle);
38$dir_name = dirname(__FILE__)."/006_variation2";
39mkdir($dir_name);
40
41echo "\n*** Testing fileperms(), chmod() with miscellaneous permissions ***\n";
42$perms_array = array(
43  /* testing sticky bit */
44  07777,
45  00000,
46  01000,
47  011111,
48  /* negative  values as permission */
49  -0777, // permissions will be given as 2's complement form of -0777
50  -07777, // permissions will be given as 2's complement form of -07777
51
52  /* decimal values as permission  */
53  777, // permissions will be given as octal equivalent value of 777
54  7777, // permissions will be given as octal equivalent value of 7777
55  -7777, // permissions are given as 2's complement of octal equivalent of 7777
56
57  /* hex value as permission */
58  0x777, // permissions will be given as ocatal equivalent value of 0x777
59  0x7777,
60
61  /* strings notation of permission,  wont work properly */
62  "r+w",
63  "r+w+x",
64  "u+rwx",
65  "u+rwx, g+rw, o+wx"
66);
67
68$count = 1;
69foreach($perms_array as $permission) {
70  echo "-- Iteration $count --\n";
71  var_dump( chmod($file_name, $permission) );
72  printf("%o", fileperms($file_name) );
73  echo "\n";
74  clearstatcache();
75
76  var_dump( chmod($dir_name, $permission) );
77  printf("%o", fileperms($dir_name) );
78  echo "\n";
79  clearstatcache();
80  $count++;
81}
82echo "*** Done ***\n";
83?>
84--CLEAN--
85<?php
86chmod(dirname(__FILE__)."/006_variation2.tmp", 0777);
87chmod(dirname(__FILE__)."/006_variation2", 0777);
88unlink(dirname(__FILE__)."/006_variation2.tmp");
89rmdir(dirname(__FILE__)."/006_variation2");
90?>
91--EXPECTF--
92*** Testing fileperms() & chmod() : usage variations ***
93
94*** Testing fileperms(), chmod() with miscellaneous permissions ***
95-- Iteration 1 --
96bool(true)
97107777
98bool(true)
9947777
100-- Iteration 2 --
101bool(true)
102100000
103bool(true)
10440000
105-- Iteration 3 --
106bool(true)
107101000
108bool(true)
10941000
110-- Iteration 4 --
111bool(true)
112101111
113bool(true)
11441111
115-- Iteration 5 --
116bool(true)
117107001
118bool(true)
11947001
120-- Iteration 6 --
121bool(true)
122100001
123bool(true)
12440001
125-- Iteration 7 --
126bool(true)
127101411
128bool(true)
12941411
130-- Iteration 8 --
131bool(true)
132107141
133bool(true)
13447141
135-- Iteration 9 --
136bool(true)
137100637
138bool(true)
13940637
140-- Iteration 10 --
141bool(true)
142103567
143bool(true)
14443567
145-- Iteration 11 --
146bool(true)
147103567
148bool(true)
14943567
150-- Iteration 12 --
151
152Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
153NULL
154103567
155
156Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
157NULL
15843567
159-- Iteration 13 --
160
161Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
162NULL
163103567
164
165Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
166NULL
16743567
168-- Iteration 14 --
169
170Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
171NULL
172103567
173
174Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
175NULL
17643567
177-- Iteration 15 --
178
179Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
180NULL
181103567
182
183Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
184NULL
18543567
186*** Done ***
187