iliaa           Thu Nov 30 00:35:15 2006 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src/ext/posix  posix.c 
  Log:
  Thread safety fixed for *nix systems
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/posix/posix.c?r1=1.70.2.3.2.6&r2=1.70.2.3.2.7&diff_format=u
Index: php-src/ext/posix/posix.c
diff -u php-src/ext/posix/posix.c:1.70.2.3.2.6 
php-src/ext/posix/posix.c:1.70.2.3.2.7
--- php-src/ext/posix/posix.c:1.70.2.3.2.6      Mon Oct  2 07:58:13 2006
+++ php-src/ext/posix/posix.c   Thu Nov 30 00:35:15 2006
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: posix.c,v 1.70.2.3.2.6 2006/10/02 07:58:13 bjori Exp $ */
+/* $Id: posix.c,v 1.70.2.3.2.7 2006/11/30 00:35:15 iliaa Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -147,7 +147,7 @@
 static PHP_MINFO_FUNCTION(posix)
 {
        php_info_print_table_start();
-       php_info_print_table_row(2, "Revision", "$Revision: 1.70.2.3.2.6 $");
+       php_info_print_table_row(2, "Revision", "$Revision: 1.70.2.3.2.7 $");
        php_info_print_table_end();
 }
 /* }}} */
@@ -833,17 +833,33 @@
 PHP_FUNCTION(posix_getgrgid)
 {
        long gid;
+#ifdef HAVE_GETGRGID_R
+       int ret;
+       struct group _g;
+       struct group *retgrptr;
+       int grbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
+       char *grbuf = emalloc(grbuflen);
+#endif
        struct group *g;
        
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &gid) == 
FAILURE) {
                RETURN_FALSE;
        }
-
+#ifdef HAVE_GETGRGID_R
+       ret = getgrgid_r(gid, &_g, grbuf, grbuflen, &retgrptr);
+       if (ret) {
+               POSIX_G(last_error) = ret;
+               efree(grbuf);
+               RETURN_FALSE;
+       }
+       efree(grbuf);
+       g = &_g;
+#else
        if (NULL == (g = getgrgid(gid))) {
                POSIX_G(last_error) = errno;
                RETURN_FALSE;
        }
-
+#endif
        array_init(return_value);
 
        if (!php_posix_group_to_array(g, return_value)) {
@@ -901,17 +917,33 @@
 PHP_FUNCTION(posix_getpwuid)
 {
        long uid;
+#ifdef HAVE_GETPWUID_R
+       struct passwd _pw;
+       struct passwd *retpwptr = NULL;
+       int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+       char *pwbuf = emalloc(pwbuflen);
+       int ret;
+#endif
        struct passwd *pw;
-       
+
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &uid) == 
FAILURE) {
                RETURN_FALSE;
        }
-
+#ifdef HAVE_GETPWUID_R
+       ret = getpwuid_r(uid, &_pw, pwbuf, pwbuflen, &retpwptr);
+       if (ret) {
+               POSIX_G(last_error) = ret;
+               efree(pwbuf);
+               RETURN_FALSE;
+       }
+       efree(pwbuf);
+       pw = &_pw;
+#else
        if (NULL == (pw = getpwuid(uid))) {
                POSIX_G(last_error) = errno;
                RETURN_FALSE;
        }
-
+#endif
        array_init(return_value);
 
        if (!php_posix_passwd_to_array(pw, return_value)) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to