I expected this function to return FALSE or 0 if a symbolic link did not exist (per the documentation above), but that's not what happened. Reading the man page for the Linux kerne's stat call here: http://www.kernel.org/doc/man-pages/online/pages/man2/stat.2.html it says this:
RETURN VALUE - On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
... which is what is happening in my case. I am doing a linkinfo('/path/to/file'); on a missing symlink, and I get back a value of -1. As we know, a value of -1 is not going to evaluate to a FALSE or 0.
My point - be careful with return values for missing symlinks.
linkinfo
(PHP 4, PHP 5)
linkinfo — 获取一个连接的信息
说明
int linkinfo
( string
$path
)
linkinfo() 返回 lstat
系统调用所返回的 UNIX C stat 结构中的 st_dev
字段。本函数用来验证一个连接(由 path
所指向的)是否确实存在(使用 stat.h 中的 S_ISLNK
宏同样的方法)。如果出错则返回 0 或 FALSE。
Example #1 linkinfo() 例子
<?php
echo linkinfo('/vmlinuz'); // 835
?>
参见 symlink(),link() 和 readlink()。
参数
-
path -
Path to the link.
返回值
linkinfo() returns the st_dev field
of the Unix C stat structure returned by the lstat
system call. Returns 0 or FALSE in case of error.
更新日志
| 版本 | 说明 |
|---|---|
| 5.3.0 | This function is now available on Windows platforms (Vista, Server 2008 or greater). |
范例
Example #2 linkinfo() example
<?php
echo linkinfo('/vmlinuz'); // 835
?>
rjb at robertjbrown dot com
21-Feb-2012 01:14
