1--TEST--
2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link & lstat[dev] value
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip no symlinks on Windows');
7}
8?>
9--FILE--
10<?php
11/* Prototype: bool symlink ( string $target, string $link );
12   Description: creates a symbolic link to the existing target with the specified name link
13
14   Prototype: bool is_link ( string $filename );
15   Description: Tells whether the given file is a symbolic link.
16
17   Prototype: bool link ( string $target, string $link );
18   Description: Create a hard link
19
20   Prototype: int linkinfo ( string $path );
21   Description: Gets information about a link
22*/
23
24/* Variation 9 : Check lstat of soft/hard link created
25                 Check linkinfo() value with lstat['dev']
26*/
27// temp file used
28$file_path = dirname(__FILE__);
29$dirname = $file_path."/symlink_link_linkinfo_is_link_variation9";
30mkdir($dirname);
31$filename = "$dirname/symlink_link_linkinfo_is_link_variation9.tmp";
32// soft link name used
33$soft_link = "$dirname/symlink_link_linkinfo_is_link_softlink_variation9.tmp";
34// hard link name used
35$hard_link = "$dirname/symlink_link_linkinfo_is_link_hardlink_variation9.tmp";
36
37// create the file
38$fp = fopen($filename, "w");
39fclose($fp);
40
41echo "*** Checking lstat() on soft link ***\n";
42// create soft link
43var_dump( symlink($filename, $soft_link) );
44
45// confirming that linkinfo() = lstat['dev'] , this should always match
46$linkinfo = linkinfo($soft_link);
47$s1 = lstat($soft_link);
48echo "linkinfo() returns : $linkinfo\n";
49echo "lstat() returns lstat['dev'] as $s1[0]\n";
50if( $s1[0] == $linkinfo )
51  echo "\nlinkinfo() value matches lstat['dev']\n";
52else
53  echo "\nWarning: linkinfo() value doesnt match lstat['dev']\n";
54// delete link
55unlink($soft_link);
56
57echo "\n*** Checking lstat() on hard link ***\n";
58// create hard link
59var_dump( link($filename, $hard_link) );
60// confirming that linkinfo() = lstat['dev'] , this should always match
61$linkinfo = linkinfo($hard_link);
62$s1 = lstat($hard_link);
63echo "linkinfo() returns : $linkinfo\n";
64echo "lstat() returns lstat['dev'] as $s1[0]\n";
65if( $s1[0] == $linkinfo )
66  echo "\nlinkinfo() value matches lstat['dev']\n";
67else
68  echo "\nWarning: linkinfo() value doesnt match lstat['dev']\n";
69
70// delete link
71unlink($hard_link);
72
73echo "\n*** Checking lstat() on a soft link to directory ***\n";
74// create soft link
75var_dump( symlink($dirname, $soft_link) );
76
77// confirming that linkinfo() = lstat['dev'], this should always match
78$linkinfo = linkinfo($soft_link);
79$s1 = lstat($soft_link);
80echo "linkinfo() returns : $linkinfo\n";
81echo "lstat() returns lstat['dev'] as $s1[0]\n";
82if( $s1[0] == $linkinfo )
83  echo "\nlinkinfo() value matches lstat['dev']\n";
84else
85  echo "\nWarning: linkinfo() value doesnt match lstat['dev']\n";
86
87// delete link
88unlink($soft_link);
89
90echo "Done\n";
91?>
92--CLEAN--
93<?php
94$file_path = dirname(__FILE__);
95$dirname = $file_path."/symlink_link_linkinfo_is_link_variation9";
96$filename = "$dirname/symlink_link_linkinfo_is_link_variation9.tmp";
97unlink($filename);
98rmdir($dirname);
99?>
100--EXPECTF--
101*** Checking lstat() on soft link ***
102bool(true)
103linkinfo() returns : %d
104lstat() returns lstat['dev'] as %d
105
106linkinfo() value matches lstat['dev']
107
108*** Checking lstat() on hard link ***
109bool(true)
110linkinfo() returns : %d
111lstat() returns lstat['dev'] as %d
112
113linkinfo() value matches lstat['dev']
114
115*** Checking lstat() on a soft link to directory ***
116bool(true)
117linkinfo() returns : %d
118lstat() returns lstat['dev'] as %d
119
120linkinfo() value matches lstat['dev']
121Done
122