Hello!

Here's a patch that adds posix_access function to the posix extension.
This function will report correct permissions when an ACL system is in use, 
is_writeable, etc do not.

Is it ok to commit to head ?

/Magnus

-- 
"I'm a mean green mother from outer space"
 -- Audrey II, The Little Shop of Horrors
Index: php_posix.h
===================================================================
RCS file: /repository/php-src/ext/posix/php_posix.h,v
retrieving revision 1.14
diff -u -r1.14 php_posix.h
--- php_posix.h 8 Jan 2004 17:32:41 -0000       1.14
+++ php_posix.h 12 Aug 2004 10:36:33 -0000
@@ -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);
Index: posix.c
===================================================================
RCS file: /repository/php-src/ext/posix/posix.c,v
retrieving revision 1.60
diff -u -r1.60 posix.c
--- posix.c     18 Apr 2004 21:49:10 -0000      1.60
+++ posix.c     12 Aug 2004 10:36:33 -0000
@@ -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)
@@ -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) = EPERM;
+               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 Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to