magnus Fri Jan 7 11:05:07 2005 EDT Modified files: /php-src NEWS /php-src/ext/posix php_posix.h posix.c Log: Added new function: posix_access() Feature requests: #29615, #14924 http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1829&r2=1.1830&ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1829 php-src/NEWS:1.1830 --- php-src/NEWS:1.1829 Fri Jan 7 10:05:09 2005 +++ php-src/NEWS Fri Jan 7 11:05:05 2005 @@ -39,6 +39,7 @@ . inet_pton() (Sara) . inet_ntop() (Sara) . fputcsv() (David Sklar) + . posix_access() (Magnus) - Added DomDocument::$recover property for parsing not well-formed XML Documents. (Christian) - Added Cursor support for MySQL 5.0.x in mysqli (Georg) http://cvs.php.net/diff.php/php-src/ext/posix/php_posix.h?r1=1.14&r2=1.15&ty=u Index: php-src/ext/posix/php_posix.h diff -u php-src/ext/posix/php_posix.h:1.14 php-src/ext/posix/php_posix.h:1.15 --- php-src/ext/posix/php_posix.h:1.14 Thu Jan 8 12:32:41 2004 +++ php-src/ext/posix/php_posix.h Fri Jan 7 11:05:06 2005 @@ -17,7 +17,7 @@ */ -/* $Id: php_posix.h,v 1.14 2004/01/08 17:32:41 sniper Exp $ */ +/* $Id: php_posix.h,v 1.15 2005/01/07 16:05:06 magnus Exp $ */ #ifndef PHP_POSIX_H #define PHP_POSIX_H @@ -90,6 +90,9 @@ PHP_FUNCTION(posix_mkfifo); #endif +/* POSIX.1, 5.6 */ +PHP_FUNCTION(posix_access); + /* POSIX.1, 9.2 */ PHP_FUNCTION(posix_getgrnam); PHP_FUNCTION(posix_getgrgid); http://cvs.php.net/diff.php/php-src/ext/posix/posix.c?r1=1.60&r2=1.61&ty=u Index: php-src/ext/posix/posix.c diff -u php-src/ext/posix/posix.c:1.60 php-src/ext/posix/posix.c:1.61 --- php-src/ext/posix/posix.c:1.60 Sun Apr 18 17:49:10 2004 +++ php-src/ext/posix/posix.c Fri Jan 7 11:05:06 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: posix.c,v 1.60 2004/04/18 21:49:10 iliaa Exp $ */ +/* $Id: posix.c,v 1.61 2005/01/07 16:05:06 magnus Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -108,6 +108,8 @@ PHP_FE(posix_mkfifo, NULL) #endif + /* POSIX.1, 5.6 */ + PHP_FE(posix_access, NULL) /* POSIX.1, 9.2 */ PHP_FE(posix_getgrnam, NULL) PHP_FE(posix_getgrgid, NULL) @@ -131,7 +133,7 @@ static PHP_MINFO_FUNCTION(posix) { php_info_print_table_start(); - php_info_print_table_row(2, "Revision", "$Revision: 1.60 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.61 $"); php_info_print_table_end(); } /* }}} */ @@ -146,6 +148,10 @@ static PHP_MINIT_FUNCTION(posix) { ZEND_INIT_MODULE_GLOBALS(posix, php_posix_init_globals, NULL); + REGISTER_LONG_CONSTANT("POSIX_F_OK", F_OK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("POSIX_X_OK", X_OK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("POSIX_W_OK", W_OK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("POSIX_R_OK", R_OK, CONST_CS | CONST_PERSISTENT); return SUCCESS; } /* }}} */ @@ -638,15 +644,46 @@ POSIX.1, 5.5.1 unlink() POSIX.1, 5.5.2 rmdir() POSIX.1, 5.5.3 rename() - POSIX.1, 5.6.x stat(), access(), chmod(), utime() - already supported by PHP (access() not supported, because it is - braindead and dangerous and gives outdated results). + POSIX.1, 5.6.x stat(), chmod(), utime() already supported by PHP. +*/ + +/* {{{ proto bool posix_access(string file [, int mode]) + Determine accessibility of a file (POSIX.1 5.6.3) */ +PHP_FUNCTION(posix_access) +{ + long mode = 0; + int filename_len, ret; + char *filename, *path; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &mode) == FAILURE) + return; + + path = expand_filepath(filename, NULL TSRMLS_CC); + + if (php_check_open_basedir_ex(path, 0 TSRMLS_CC)) { + efree(path); + POSIX_G(last_error) = EACCES; + RETURN_FALSE; + } + + ret = access(path, mode); + efree(path); + + if (ret) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ +/* POSIX.1, 6.x most I/O functions already supported by PHP. POSIX.1, 7.x tty functions, TODO POSIX.1, 8.x interactions with other C language functions - POSIX.1, 9.x system database access - */ + POSIX.1, 9.x system database access +*/ /* {{{ proto array posix_getgrnam(string groupname) Group database access (POSIX.1, 9.2.1) */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php