1--TEST-- 2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link & lstat[dev] value 3--SKIPIF-- 4<?php 5if (PHP_OS_FAMILY === 'Windows') { 6 require_once __DIR__ . '/windows_links/common.inc'; 7 skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__); 8} 9?> 10--FILE-- 11<?php 12/* Variation 9 : Check lstat of soft/hard link created 13 Check linkinfo() value with lstat['dev'] 14*/ 15// temp file used 16$file_path = __DIR__; 17$dirname = $file_path."/symlink_link_linkinfo_is_link_variation9"; 18mkdir($dirname); 19$filename = "$dirname/symlink_link_linkinfo_is_link_variation9.tmp"; 20// soft link name used 21$soft_link = "$dirname/symlink_link_linkinfo_is_link_softlink_variation9.tmp"; 22// hard link name used 23$hard_link = "$dirname/symlink_link_linkinfo_is_link_hardlink_variation9.tmp"; 24 25// create the file 26$fp = fopen($filename, "w"); 27fclose($fp); 28 29echo "*** Checking lstat() on soft link ***\n"; 30// create soft link 31var_dump( symlink($filename, $soft_link) ); 32 33// confirming that linkinfo() = lstat['dev'] , this should always match 34$linkinfo = linkinfo($soft_link); 35$s1 = lstat($soft_link); 36echo "linkinfo() returns integer !== -1: "; 37var_dump(is_int($linkinfo) && $linkinfo !== -1); 38if( $s1[0] == $linkinfo ) 39 echo "\nlinkinfo() value matches lstat['dev']\n"; 40else 41 echo "\nWarning: linkinfo() value doesn't match lstat['dev']\n"; 42// delete link 43unlink($soft_link); 44 45echo "\n*** Checking lstat() on hard link ***\n"; 46// create hard link 47var_dump( link($filename, $hard_link) ); 48// confirming that linkinfo() = lstat['dev'] , this should always match 49$linkinfo = linkinfo($hard_link); 50$s1 = lstat($hard_link); 51echo "linkinfo() returns integer !== -1: "; 52var_dump(is_int($linkinfo) && $linkinfo !== -1); 53if( $s1[0] == $linkinfo ) 54 echo "\nlinkinfo() value matches lstat['dev']\n"; 55else 56 echo "\nWarning: linkinfo() value doesn't match lstat['dev']\n"; 57 58// delete link 59unlink($hard_link); 60 61echo "\n*** Checking lstat() on a soft link to directory ***\n"; 62// create soft link 63var_dump( symlink($dirname, $soft_link) ); 64 65// confirming that linkinfo() = lstat['dev'], this should always match 66$linkinfo = linkinfo($soft_link); 67$s1 = lstat($soft_link); 68echo "linkinfo() returns integer !== -1: "; 69var_dump(is_int($linkinfo) && $linkinfo !== -1); 70if( $s1[0] == $linkinfo ) 71 echo "\nlinkinfo() value matches lstat['dev']\n"; 72else 73 echo "\nWarning: linkinfo() value doesn't match lstat['dev']\n"; 74 75// delete link 76if (PHP_OS_FAMILY === 'Windows') { 77 rmdir($soft_link); 78} else { 79 unlink($soft_link); 80} 81 82echo "Done\n"; 83?> 84--CLEAN-- 85<?php 86$file_path = __DIR__; 87$dirname = $file_path."/symlink_link_linkinfo_is_link_variation9"; 88$filename = "$dirname/symlink_link_linkinfo_is_link_variation9.tmp"; 89unlink($filename); 90rmdir($dirname); 91?> 92--EXPECT-- 93*** Checking lstat() on soft link *** 94bool(true) 95linkinfo() returns integer !== -1: bool(true) 96 97linkinfo() value matches lstat['dev'] 98 99*** Checking lstat() on hard link *** 100bool(true) 101linkinfo() returns integer !== -1: bool(true) 102 103linkinfo() value matches lstat['dev'] 104 105*** Checking lstat() on a soft link to directory *** 106bool(true) 107linkinfo() returns integer !== -1: bool(true) 108 109linkinfo() value matches lstat['dev'] 110Done 111