File: 006_error.phpt

package info (click to toggle)
php5 5.2.6.dfsg.1-1%2Blenny16
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 81,956 kB
  • ctags: 45,717
  • sloc: ansic: 545,818; sh: 18,463; php: 12,555; xml: 4,362; yacc: 2,430; lex: 2,294; makefile: 1,193; tcl: 1,128; awk: 693; cpp: 682; perl: 71; pascal: 24; sql: 22
file content (107 lines) | stat: -rw-r--r-- 2,536 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--TEST--
Test fileperms(), chmod() functions: error conditions
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
    die('skip Not on Windows');
}
// Skip if being run by root
$filename = dirname(__FILE__)."/006_root_check.tmp";
$fp = fopen($filename, 'w');
fclose($fp);
if(fileowner($filename) == 0) {
        unlink ($filename);
        die('skip cannot be run as root');
}

unlink($filename);

?>
--FILE--
<?php
/*
  Prototype: int fileperms ( string $filename )
  Description: Returns the permissions on the file, or FALSE in case of an error

  Prototype: bool chmod ( string $filename, int $mode )
  Description: Attempts to change the mode of the file specified by 
    filename to that given in mode
*/

echo "*** Testing error conditions for fileperms(), chmod() ***\n";

/* With standard files and dirs */
var_dump( chmod("/etc/passwd", 0777) );
printf("%o", fileperms("/etc/passwd") );
echo "\n";
clearstatcache();

var_dump( chmod("/etc", 0777) );
printf("%o", fileperms("/etc") );
echo "\n";
clearstatcache();

/* With non-existing file or dir */
var_dump( chmod("/no/such/file/dir", 0777) );
var_dump( fileperms("/no/such/file/dir") );
echo "\n";

/* With args less than expected */
$fp = fopen(dirname(__FILE__)."/006_error.tmp", "w");
fclose($fp);
var_dump( chmod(dirname(__FILE__)."/006_error.tmp") );
var_dump( chmod("nofile") );
var_dump( chmod() );
var_dump( fileperms() );

/* With args greater than expected */
var_dump( chmod(dirname(__FILE__)."/006_error.tmp", 0755, TRUE) );
var_dump( fileperms(dirname(__FILE__)."/006_error.tmp", 0777) );
var_dump( fileperms("nofile", 0777) );

echo "\n*** Done ***\n";
?>
--CLEAN--
<?php
unlink( dirname(__FILE__)."/006_error.tmp");
?>
--EXPECTF--
*** Testing error conditions for fileperms(), chmod() ***

Warning: chmod(): %s in %s on line %d
bool(false)
100%d44

Warning: chmod(): %s in %s on line %d
bool(false)
40755

Warning: chmod(): No such file or directory in %s on line %d
bool(false)

Warning: fileperms(): stat failed for /no/such/file/dir in %s on line %d
bool(false)


Warning: Wrong parameter count for chmod() in %s on line %d
NULL

Warning: Wrong parameter count for chmod() in %s on line %d
NULL

Warning: Wrong parameter count for chmod() in %s on line %d
NULL

Warning: Wrong parameter count for fileperms() in %s on line %d
NULL

Warning: Wrong parameter count for chmod() in %s on line %d
NULL

Warning: Wrong parameter count for fileperms() in %s on line %d
NULL

Warning: Wrong parameter count for fileperms() in %s on line %d
NULL

*** Done ***