helly Mon Feb 26 22:32:57 2007 UTC Modified files: /php-src/ext/spl spl.php spl_directory.c Log: - Add SplFileInfo::getLinkTarget - Add SplFileInfo::getRealPath http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl.php?r1=1.77&r2=1.78&diff_format=u Index: php-src/ext/spl/spl.php diff -u php-src/ext/spl/spl.php:1.77 php-src/ext/spl/spl.php:1.78 --- php-src/ext/spl/spl.php:1.77 Sun Dec 31 18:20:03 2006 +++ php-src/ext/spl/spl.php Mon Feb 26 22:32:57 2007 @@ -928,6 +928,14 @@ */ function isLink() {/**/} + /** @return target of link. + */ + function getLinkTarget() {/**/} + + /** @return The resolved path + */ + function getRealPath() {/**/} + /** @return getPathname() */ function __toString() {/**/} http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.119&r2=1.120&diff_format=u Index: php-src/ext/spl/spl_directory.c diff -u php-src/ext/spl/spl_directory.c:1.119 php-src/ext/spl/spl_directory.c:1.120 --- php-src/ext/spl/spl_directory.c:1.119 Tue Feb 20 13:07:53 2007 +++ php-src/ext/spl/spl_directory.c Mon Feb 26 22:32:57 2007 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_directory.c,v 1.119 2007/02/20 13:07:53 helly Exp $ */ +/* $Id: spl_directory.c,v 1.120 2007/02/26 22:32:57 helly Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -43,6 +43,7 @@ #include "ext/standard/basic_functions.h" #include "ext/standard/php_filestat.h" +#include "ext/standard/php_link.h" /* declare the class handlers */ static zend_object_handlers spl_filesystem_object_handlers; @@ -840,6 +841,82 @@ FileInfoFunction(isLink, FS_IS_LINK) /* }}} */ +/* {{{ proto string SplFileInfo::getLinkTarget() U + Return the target of a symbolic link */ +SPL_METHOD(SplFileInfo, getLinkTarget) +{ + spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + UChar *target; + int ret, link_len, target_len; + char *link, buff[MAXPATHLEN]; + + php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC); + + if (intern->file_name_type == IS_UNICODE) { + php_stream_path_encode(NULL, &link, &link_len, intern->file_name.u, intern->file_name_len, REPORT_ERRORS, FG(default_context)); + } else { + link = intern->file_name.s; + } + + ret = readlink(link, buff, MAXPATHLEN-1); + + if (ret == -1) { + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Unable to read link %R, error: %s", intern->file_name_type, intern->file_name, strerror(errno)); + RETVAL_FALSE; + } else { + /* Append NULL to the end of the string */ + buff[ret] = '\0'; + + if (UG(unicode)) { + if (SUCCESS == php_stream_path_decode(NULL, &target, &target_len, buff, ret, REPORT_ERRORS, FG(default_context))) { + RETVAL_UNICODEL(target, target_len, 0); + } else { + RETVAL_STRING(buff, 1); + } + } else { + RETVAL_STRING(buff, 1); + } + } + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); +} +/* }}} */ + +#if (!defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS) +/* {{{ proto string SplFileInfo::getRealPath() U + Return the resolved path */ +SPL_METHOD(SplFileInfo, getRealPath) +{ + spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + UChar *path; + int filename_len, path_len; + char *filename, buff[MAXPATHLEN]; + + php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC); + + if (intern->file_name_type == IS_UNICODE) { + php_stream_path_encode(NULL, &filename, &filename_len, intern->file_name.u, intern->file_name_len, REPORT_ERRORS, FG(default_context)); + } else { + filename = intern->file_name.s; + } + + if (VCWD_REALPATH(filename, buff)) { + if (UG(unicode)) { + if (php_stream_path_decode(NULL, &path, &path_len, buff, strlen(buff), REPORT_ERRORS, FG(default_context)) == SUCCESS) { + RETVAL_UNICODEL(path, path_len, 0); + } else { + RETVAL_STRING(buff, 1); + } + } else { + RETVAL_STRING(buff, 1); + } + } else { + RETVAL_FALSE; + } + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); +} +/* }}} */ +#endif + /* {{{ proto SplFileObject SplFileInfo::openFile([string mode = 'r' [, bool use_include_path [, resource context]]]) U Open the current file */ SPL_METHOD(SplFileInfo, openFile) @@ -1392,6 +1469,8 @@ SPL_ME(SplFileInfo, isFile, NULL, ZEND_ACC_PUBLIC) SPL_ME(SplFileInfo, isDir, NULL, ZEND_ACC_PUBLIC) SPL_ME(SplFileInfo, isLink, NULL, ZEND_ACC_PUBLIC) + SPL_ME(SplFileInfo, getLinkTarget, NULL, ZEND_ACC_PUBLIC) + SPL_ME(SplFileInfo, getRealPath, NULL, ZEND_ACC_PUBLIC) SPL_ME(SplFileInfo, getFileInfo, arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC) SPL_ME(SplFileInfo, getPathInfo, arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC) SPL_ME(SplFileInfo, openFile, arginfo_info_openFile, ZEND_ACC_PUBLIC)
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php