iliaa Thu Nov 30 00:35:27 2006 UTC
Modified files:
/php-src/ext/posix posix.c
Log:
MFB: Thread safety fixed for *nix systems
http://cvs.php.net/viewvc.cgi/php-src/ext/posix/posix.c?r1=1.80&r2=1.81&diff_format=u
Index: php-src/ext/posix/posix.c
diff -u php-src/ext/posix/posix.c:1.80 php-src/ext/posix/posix.c:1.81
--- php-src/ext/posix/posix.c:1.80 Mon Oct 2 07:54:37 2006
+++ php-src/ext/posix/posix.c Thu Nov 30 00:35:27 2006
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: posix.c,v 1.80 2006/10/02 07:54:37 bjori Exp $ */
+/* $Id: posix.c,v 1.81 2006/11/30 00:35:27 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.80 $");
+ php_info_print_table_row(2, "Revision", "$Revision: 1.81 $");
php_info_print_table_end();
}
/* }}} */
@@ -827,17 +827,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)) {
@@ -895,17 +911,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