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
)リンクに関する情報を取得します。
この関数を使用して
(pathが指している)
リンクが実際に存在するかどうかを、
(stat.h で定義されている S_ISLNK
マクロと同じ方法で) チェックします。
パラメータ
-
path -
リンクへのパス。
返り値
linkinfo()は、lstat
システムコールで返された
Unix C 言語の stat 構造体の st_dev
フィールドを返します。
0 を返し、エラーの場合に
FALSE を返します。
変更履歴
| バージョン | 説明 |
|---|---|
| 5.3.0 | この関数は、Windows プラットフォーム (Vista 以降、あるいは Server 2008 以降) でも動作するようになりました。 |
例
例1 linkinfo() の例
<?php
echo linkinfo('/vmlinuz'); // 835
?>
rjb at robertjbrown dot com
21-Feb-2012 01:14
