From 003bb8c2b4b7b3e21bfbe3fb7aa7f575898b1a7e Mon Sep 17 00:00:00 2001 From: Markus Fischer Date: Tue, 5 Mar 2002 16:04:04 +0000 Subject: [PATCH] - Introduced posix_errno() (get error number from last error message) and posix_strerror() (convert error number into error string). - Do not output any error message if any of the function fails with FALSE return value. The proper way now is to call posix_errno() and posix_strerror() after encountering an error condition. - Function not support on a system no longer issue a 'not available' error but simply don't exist so we can safely use 'function_exists'. - Fixed protos. - Use new parameter parsing API. - posix_uname() may be aware of 'domainname' (GNU extension) - posix_getgrnam(), posix_getgrgid(): the returned information does no longer contains mixture of string and numbered keys (hash / array) but contains key 'member' with an array of all members in a list (or an empty array). This breaks BC but is the right thing IMHO. --- ext/posix/php_posix.h | 47 ++- ext/posix/posix.c | 683 ++++++++++++++++++++++-------------------- 2 files changed, 407 insertions(+), 323 deletions(-) diff --git a/ext/posix/php_posix.h b/ext/posix/php_posix.h index b2370f43dd..2ebdc06db2 100644 --- a/ext/posix/php_posix.h +++ b/ext/posix/php_posix.h @@ -22,6 +22,10 @@ #ifndef PHP_POSIX_H #define PHP_POSIX_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #if HAVE_POSIX #ifndef DLEXPORT #define DLEXPORT @@ -30,49 +34,84 @@ extern zend_module_entry posix_module_entry; #define posix_module_ptr &posix_module_entry +/* POSIX.1, 3.3 */ PHP_FUNCTION(posix_kill); +/* POSIX.1, 4.1 */ PHP_FUNCTION(posix_getpid); PHP_FUNCTION(posix_getppid); +/* POSIX.1, 4.2 */ PHP_FUNCTION(posix_getuid); PHP_FUNCTION(posix_getgid); PHP_FUNCTION(posix_geteuid); PHP_FUNCTION(posix_getegid); PHP_FUNCTION(posix_setuid); PHP_FUNCTION(posix_setgid); +#ifdef HAVE_SETEUID PHP_FUNCTION(posix_seteuid); +#endif +#ifdef HAVE_SETEGID PHP_FUNCTION(posix_setegid); - +#endif PHP_FUNCTION(posix_getgroups); PHP_FUNCTION(posix_getlogin); +/* POSIX.1, 4.3 */ PHP_FUNCTION(posix_getpgrp); +#ifdef HAVE_SETSID PHP_FUNCTION(posix_setsid); +#endif PHP_FUNCTION(posix_setpgid); +/* Non-Posix functions which are common */ +#ifdef HAVE_GETPGID PHP_FUNCTION(posix_getpgid); +#endif +#ifdef HAVE_GETSID PHP_FUNCTION(posix_getsid); +#endif +/* POSIX.1, 4.4 */ PHP_FUNCTION(posix_uname); PHP_FUNCTION(posix_times); +/* POSIX.1, 4.5 */ +#ifdef HAVE_CTERMID PHP_FUNCTION(posix_ctermid); +#endif PHP_FUNCTION(posix_ttyname); PHP_FUNCTION(posix_isatty); +/* POSIX.1, 5.2 */ PHP_FUNCTION(posix_getcwd); +/* POSIX.1, 5.4 */ +#ifdef HAVE_MKFIFO PHP_FUNCTION(posix_mkfifo); +#endif + +/* POSIX.1, 9.2 */ PHP_FUNCTION(posix_getgrnam); PHP_FUNCTION(posix_getgrgid); PHP_FUNCTION(posix_getpwnam); PHP_FUNCTION(posix_getpwuid); +#ifdef HAVE_GETRLIMIT PHP_FUNCTION(posix_getrlimit); +#endif -typedef struct { - int dummy; -} posix_module; +PHP_FUNCTION(posix_get_last_error); +PHP_FUNCTION(posix_strerror); + +ZEND_BEGIN_MODULE_GLOBALS(posix) + int last_error; +ZEND_END_MODULE_GLOBALS(posix) + +#ifdef ZTS +# define POSIX_G(v) TSRMG(posix_globals_id, zend_posix_globals *, v) +#else +# define POSIX_G(v) (posix_globals.v) +#endif #else diff --git a/ext/posix/posix.c b/ext/posix/posix.c index 013719021d..6c56c7c154 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -15,7 +15,7 @@ | Author: Kristian Koehntopp | +----------------------------------------------------------------------+ */ - + /* $Id$ */ #ifdef HAVE_CONFIG_H @@ -44,7 +44,7 @@ #include #include -#define SAFE_STRING(s) ((s)?(s):"") +ZEND_DECLARE_MODULE_GLOBALS(posix) /* {{{ posix_functions[] */ @@ -60,8 +60,12 @@ function_entry posix_functions[] = { PHP_FE(posix_getuid, NULL) PHP_FE(posix_setuid, NULL) PHP_FE(posix_geteuid, NULL) +#ifdef HAVE_SETEUID PHP_FE(posix_seteuid, NULL) +#endif +#ifdef HAVE_SETEGID PHP_FE(posix_getgid, NULL) +#endif PHP_FE(posix_setgid, NULL) PHP_FE(posix_getegid, NULL) PHP_FE(posix_setegid, NULL) @@ -70,10 +74,14 @@ function_entry posix_functions[] = { /* POSIX.1, 4.3 */ PHP_FE(posix_getpgrp, NULL) +#ifdef HAVE_SETSID PHP_FE(posix_setsid, NULL) +#endif PHP_FE(posix_setpgid, NULL) /* Non-Posix functions which are common */ +#ifdef HAVE_GETPGID PHP_FE(posix_getpgid, NULL) +#endif PHP_FE(posix_getsid, NULL) /* POSIX.1, 4.4 */ @@ -83,7 +91,9 @@ function_entry posix_functions[] = { PHP_FE(posix_times, NULL) /* POSIX.1, 4.7 */ +#ifdef HAVE_CTERMID PHP_FE(posix_ctermid, NULL) +#endif PHP_FE(posix_ttyname, NULL) PHP_FE(posix_isatty, NULL) @@ -91,7 +101,9 @@ function_entry posix_functions[] = { PHP_FE(posix_getcwd, NULL) /* POSIX.1, 5.4 */ +#ifdef HAVE_MKFIFO PHP_FE(posix_mkfifo, NULL) +#endif /* POSIX.1, 9.2 */ PHP_FE(posix_getgrnam, NULL) @@ -99,12 +111,42 @@ function_entry posix_functions[] = { PHP_FE(posix_getpwnam, NULL) PHP_FE(posix_getpwuid, NULL) +#ifdef HAVE_GETRLIMIT PHP_FE(posix_getrlimit, NULL) +#endif + + PHP_FE(posix_get_last_error, NULL) + PHP_FALIAS(posix_errno, posix_get_last_error, NULL) + PHP_FE(posix_strerror, NULL) {NULL, NULL, NULL} }; /* }}} */ +/* {{{ PHP_MINFO_FUNCTION + */ +static PHP_MINFO_FUNCTION(posix) +{ + php_info_print_table_start(); + php_info_print_table_row(2, "Revision", "$Revision$"); + php_info_print_table_end(); +} +/* }}} */ + +static void php_posix_init_globals(zend_posix_globals *posix_globals TSRMLS_DC) +{ + posix_globals->last_error = 0; +} + +/* {{{ PHP_MINIT_FUNCTION(posix) + */ +static PHP_MINIT_FUNCTION(posix) +{ + ZEND_INIT_MODULE_GLOBALS(posix, php_posix_init_globals, NULL); + return SUCCESS; +} +/* }}} */ + static PHP_MINFO_FUNCTION(posix); /* {{{ posix_module_entry @@ -113,7 +155,7 @@ zend_module_entry posix_module_entry = { STANDARD_MODULE_HEADER, "posix", posix_functions, - NULL, + PHP_MINIT(posix), NULL, NULL, NULL, @@ -127,38 +169,18 @@ zend_module_entry posix_module_entry = { ZEND_GET_MODULE(posix) #endif -/* {{{ PHP_MINFO_FUNCTION - */ -static PHP_MINFO_FUNCTION(posix) -{ - php_info_print_table_start(); - php_info_print_table_row(2, "Revision", "$Revision$"); - php_info_print_table_end(); -} -/* }}} */ - -/* {{{ proto int posix_kill(int pid, int sig) +/* {{{ proto bool posix_kill(int pid, int sig) Send a signal to a process (POSIX.1, 3.3.2) */ PHP_FUNCTION(posix_kill) { - pval *pid; - pval *sig; - int result; + long pid, sig; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters(ht, 2, &pid, &sig)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long(pid); - convert_to_long(sig); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &pid, &sig) == FAILURE) + return; - result = kill(Z_LVAL_P(pid), Z_LVAL_P(sig)); - if (result< 0) { - php_error(E_WARNING, "posix_kill(%d, %d) failed with '%s'", - Z_LVAL_P(pid), - Z_LVAL_P(sig), - strerror(errno)); + if (kill(pid, sig) < 0) { + POSIX_G(last_error) = errno; RETURN_FALSE; } @@ -166,181 +188,167 @@ PHP_FUNCTION(posix_kill) } /* }}} */ -/* {{{ proto int posix_getpid(void) +/* {{{ proto int posix_getpid(void) Get the current process id (POSIX.1, 4.1.1) */ PHP_FUNCTION(posix_getpid) { pid_t pid; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) + return; + pid = getpid(); RETURN_LONG(pid); } /* }}} */ -/* {{{ proto int posix_getppid(void) +/* {{{ proto int posix_getppid(void) Get the parent process id (POSIX.1, 4.1.1) */ PHP_FUNCTION(posix_getppid) { pid_t ppid; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) + return; + ppid = getppid(); RETURN_LONG(ppid); } /* }}} */ -/* {{{ proto int posix_getuid(void) +/* {{{ proto int posix_getuid(void) Get the current user id (POSIX.1, 4.2.1) */ PHP_FUNCTION(posix_getuid) { uid_t uid; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) + return; + uid = getuid(); RETURN_LONG(uid); } /* }}} */ -/* {{{ proto int posix_getgid(void) +/* {{{ proto int posix_getgid(void) Get the current group id (POSIX.1, 4.2.1) */ PHP_FUNCTION(posix_getgid) { gid_t gid; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) + return; + gid = getgid(); RETURN_LONG(gid); } /* }}} */ -/* {{{ proto int posix_geteuid(void) +/* {{{ proto int posix_geteuid(void) Get the current effective user id (POSIX.1, 4.2.1) */ PHP_FUNCTION(posix_geteuid) { uid_t uid; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) + return; + uid = geteuid(); RETURN_LONG(uid); } /* }}} */ -/* {{{ proto int posix_getegid(void) +/* {{{ proto int posix_getegid(void) Get the current effective group id (POSIX.1, 4.2.1) */ PHP_FUNCTION(posix_getegid) { gid_t gid; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) + return; + gid = getegid(); RETURN_LONG(gid); -} + } /* }}} */ -/* {{{ proto int posix_setuid(long uid) +/* {{{ proto bool posix_setuid(long uid) Set user id (POSIX.1, 4.2.2) */ PHP_FUNCTION(posix_setuid) { - pval *uid; - int result; + long uid; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters(ht, 1, &uid)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long(uid); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &uid) == FAILURE) + return; - result = setuid(Z_LVAL_P(uid)); - if (result < 0) { - php_error(E_WARNING, "posix_setuid(%d) failed with '%s'. Must be root", - Z_LVAL_P(uid), - strerror(errno)); - RETURN_FALSE; + if (setuid(uid) < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ -/* {{{ proto int posix_setgid(long uid) +/* {{{ proto bool posix_setgid(int uid) Set group id (POSIX.1, 4.2.2) */ PHP_FUNCTION(posix_setgid) { - pval *gid; - int result; + long gid; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters(ht, 1, &gid)==FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &gid) == FAILURE) + return; - convert_to_long(gid); - - result = setgid(Z_LVAL_P(gid)); - if (result < 0) { - php_error(E_WARNING, "posix_setgid(%d) failed with '%s'. Must be root", - Z_LVAL_P(gid), - strerror(errno)); - RETURN_FALSE; + if (setgid(gid) < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ -/* {{{ proto int posix_seteuid(long uid) +/* {{{ proto bool posix_seteuid(long uid) Set effective user id */ +#ifdef HAVE_SETEUID PHP_FUNCTION(posix_seteuid) { -#ifdef HAVE_SETEUID - pval *uid; - int result; + long euid; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters(ht, 1, &uid)==FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &euid) == FAILURE) + return; - convert_to_long(uid); - - result = seteuid(Z_LVAL_P(uid)); - if (result < 0) { - php_error(E_WARNING, "posix_setuid(%d) failed with '%s'.", - Z_LVAL_P(uid), - strerror(errno)); - RETURN_FALSE; + if (seteuid(euid) < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; } RETURN_TRUE; -#else - RETURN_FALSE; -#endif } +#endif /* }}} */ -/* {{{ proto int posix_setegid(long uid) +/* {{{ proto bool posix_setegid(long uid) Set effective group id */ +#ifdef HAVE_SETEGID PHP_FUNCTION(posix_setegid) { -#ifdef HAVE_SETEGID - pval *gid; - int result; + long egid; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters(ht, 1, &gid)==FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &egid) == FAILURE) + return; - convert_to_long(gid); - - result = setegid(Z_LVAL_P(gid)); - if (result < 0) { - php_error(E_WARNING, "posix_setgid(%d) failed with '%s'.", - Z_LVAL_P(gid), - strerror(errno)); - RETURN_FALSE; + if (setegid(egid) < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; } RETURN_TRUE; -#else - RETURN_FALSE; -#endif } +#endif /* }}} */ -/* {{{ proto int posix_getgroups(void) +/* {{{ proto array posix_getgroups(void) Get supplementary group id's (POSIX.1, 4.2.3) */ PHP_FUNCTION(posix_getgroups) { @@ -348,19 +356,22 @@ PHP_FUNCTION(posix_getgroups) int result; int i; - result = getgroups(NGROUPS_MAX, gidlist); - if (result < 0) { - php_error(E_WARNING, "posix_getgroups() failed with '%s'", - strerror(errno)); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) + return; + + if ((result = getgroups(NGROUPS_MAX, gidlist)) < 0) { + POSIX_G(last_error) = errno; RETURN_FALSE; } if (array_init(return_value) == FAILURE) { + // TODO: Should we issue a warning here so we don't have ambiguity + // with the above return value ? RETURN_FALSE; } for (i=0; igr_name, 1); + add_assoc_string(array_group, "passwd", g->gr_passwd, 1); + for (count=0; g->gr_mem[count] != NULL; count++) { + add_next_index_string(array_members, g->gr_mem[count], 1); + } + zend_hash_update(Z_ARRVAL_P(array_group), "members", sizeof("members"), (void*)&array_members, sizeof(zval*), NULL); + add_assoc_long(array_group, "gid", g->gr_gid); + return 1; +} + /* POSIX.1, 5.5.1 unlink() POSIX.1, 5.5.2 rmdir() @@ -690,38 +714,33 @@ PHP_FUNCTION(posix_mkfifo) POSIX.1, 9.x system database access */ -/* {{{ proto array posix_getgrnam(string groupname) +/* {{{ proto array posix_getgrnam(string groupname) Group database access (POSIX.1, 9.2.1) */ PHP_FUNCTION(posix_getgrnam) { - pval *name; - char buffer[10]; - struct group *g; - char **p; - int count; + char *name; + struct group *g; + int name_len; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters(ht, 1, &name)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(name); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) + return; - g = getgrnam(Z_STRVAL_P(name)); - if (!g) { - php_error(E_WARNING, "posix_getgrnam(%s) failed with '%s'", - Z_STRVAL_P(name), - strerror(errno)); + if (NULL == (g = getgrnam(name))) { + POSIX_G(last_error) = errno; RETURN_FALSE; } + if (array_init(return_value) == FAILURE) { + // TODO: Should we issue a warning here so we don't have ambiguity + // with the above return value ? RETURN_FALSE; } - add_assoc_string(return_value, "name", g->gr_name, 1); - add_assoc_long (return_value, "gid", g->gr_gid); - for (count=0, p=g->gr_mem; p[count] != NULL; count++) { - snprintf(buffer, 10, "%d", count); - add_assoc_string(return_value, buffer, p[count], 1); + + if (!php_posix_group_to_array(g, return_value)) { + php_error(E_WARNING, "%s() unable to convert posix group to array", + get_active_function_name(TSRMLS_C)); + RETURN_FALSE; } - add_assoc_long(return_value, "members", count); } /* }}} */ @@ -729,66 +748,73 @@ PHP_FUNCTION(posix_getgrnam) Group database access (POSIX.1, 9.2.1) */ PHP_FUNCTION(posix_getgrgid) { - pval *gid; - char buffer[10]; - struct group *g; - char **p; - int count; + long gid; + struct group *g; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters(ht, 1, &gid)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long(gid); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &gid) == FAILURE) + return; - g = getgrgid(Z_LVAL_P(gid)); - if (!g) { - php_error(E_WARNING, "posix_getgrgid(%d) failed with '%s'", - Z_LVAL_P(gid), - strerror(errno)); + if (NULL == (g = getgrgid(gid))) { + POSIX_G(last_error) = errno; RETURN_FALSE; } + if (array_init(return_value) == FAILURE) { + // TODO: Should we issue a warning here so we don't have ambiguity + // with the above return value ? RETURN_FALSE; } - add_assoc_string(return_value, "name", g->gr_name, 1); - add_assoc_long (return_value, "gid", g->gr_gid); - for (count=0, p=g->gr_mem; p[count] != NULL; count++) { - snprintf(buffer, 10, "%d", count); - add_assoc_string(return_value, buffer, p[count], 1); + + if (!php_posix_group_to_array(g, return_value)) { + php_error(E_WARNING, "%s() unable to convert posix group struct to array", + get_active_function_name(TSRMLS_C)); + RETURN_FALSE; } - add_assoc_long(return_value, "members", count); } /* }}} */ +int php_posix_passwd_to_array(struct passwd *pw, zval *return_value) { + if (NULL == pw) + return 0; + if (NULL == return_value || Z_TYPE_P(return_value) != IS_ARRAY) + return 0; + + add_assoc_string(return_value, "name", pw->pw_name, 1); + add_assoc_string(return_value, "passwd", pw->pw_passwd, 1); + add_assoc_long (return_value, "uid", pw->pw_uid); + add_assoc_long (return_value, "gid", pw->pw_gid); + add_assoc_string(return_value, "gecos", pw->pw_gecos, 1); + add_assoc_string(return_value, "dir", pw->pw_dir, 1); + add_assoc_string(return_value, "shell", pw->pw_shell, 1); + return 1; +} + /* {{{ proto array posix_getpwnam(string groupname) User database access (POSIX.1, 9.2.2) */ PHP_FUNCTION(posix_getpwnam) { - pval *name; struct passwd *pw; + char *name; + int name_len; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters(ht, 1, &name)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(name); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) + return; - pw = getpwnam(Z_STRVAL_P(name)); - if (!pw) { - php_error(E_WARNING, "posix_getpwnam(%s) failed with '%s'", - Z_STRVAL_P(name), - strerror(errno)); + if (NULL == (pw = getpwnam(name))) { + POSIX_G(last_error) = errno; RETURN_FALSE; } + if (array_init(return_value) == FAILURE) { RETURN_FALSE; } - add_assoc_string(return_value, "name", pw->pw_name, 1); - add_assoc_string(return_value, "passwd", pw->pw_passwd, 1); - add_assoc_long (return_value, "uid", pw->pw_uid); - add_assoc_long (return_value, "gid", pw->pw_gid); - add_assoc_string(return_value, "gecos", pw->pw_gecos, 1); - add_assoc_string(return_value, "dir", pw->pw_dir, 1); - add_assoc_string(return_value, "shell", pw->pw_shell, 1); + + if (!php_posix_passwd_to_array(pw, return_value)) { + php_error(E_WARNING, "%s() unable to convert posix passwd struct to array", + get_active_function_name(TSRMLS_C)); + RETURN_FALSE; + } + } /* }}} */ @@ -796,31 +822,26 @@ PHP_FUNCTION(posix_getpwnam) User database access (POSIX.1, 9.2.2) */ PHP_FUNCTION(posix_getpwuid) { - pval *uid; + long uid; struct passwd *pw; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters(ht, 1, &uid)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long(uid); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &uid) == FAILURE) + return; - pw = getpwuid(Z_LVAL_P(uid)); - if (!pw) { - php_error(E_WARNING, "posix_getpwuid(%d) failed with '%s'", - Z_LVAL_P(uid), - strerror(errno)); + if (NULL == (pw = getpwuid(uid))) { + POSIX_G(last_error) = errno; RETURN_FALSE; } + if (array_init(return_value) == FAILURE) { RETURN_FALSE; } - add_assoc_string(return_value, "name", pw->pw_name, 1); - add_assoc_string(return_value, "passwd", pw->pw_passwd, 1); - add_assoc_long (return_value, "uid", pw->pw_uid); - add_assoc_long (return_value, "gid", pw->pw_gid); - add_assoc_string(return_value, "gecos", pw->pw_gecos, 1); - add_assoc_string(return_value, "dir", pw->pw_dir, 1); - add_assoc_string(return_value, "shell", pw->pw_shell, 1); + + if (!php_posix_passwd_to_array(pw, return_value)) { + php_error(E_WARNING, "%s() unable to convert posix passwd struct to array", + get_active_function_name(TSRMLS_C)); + RETURN_FALSE; + } } /* }}} */ @@ -831,7 +852,7 @@ PHP_FUNCTION(posix_getpwuid) /* {{{ posix_addlimit */ -static int posix_addlimit(int limit, char *name, pval *return_value) { +static int posix_addlimit(int limit, char *name, zval *return_value) { int result; struct rlimit rl; char hard[80]; @@ -842,7 +863,7 @@ static int posix_addlimit(int limit, char *name, pval *return_value) { result = getrlimit(limit, &rl); if (result < 0) { - php_error(E_WARNING, "posix_getrlimit failed to getrlimit(RLIMIT_CORE with '%s'", strerror(errno)); + POSIX_G(last_error) = errno; return FAILURE; } @@ -920,15 +941,16 @@ struct limitlist { }; /* }}} */ -#endif /* HAVE_GETRLIMIT */ -/* {{{ proto int posix_getrlimit(void) +/* {{{ proto int posix_getrlimit(void) Get system resource consumption limits (This is not a POSIX function, but a BSDism and a SVR4ism. We compile conditionally) */ PHP_FUNCTION(posix_getrlimit) { -#ifdef HAVE_GETRLIMIT struct limitlist *l = NULL; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) + return; + if (array_init(return_value) == FAILURE) { RETURN_FALSE; } @@ -937,9 +959,32 @@ PHP_FUNCTION(posix_getrlimit) if (posix_addlimit(l->limit, l->name, return_value) == FAILURE) RETURN_FALSE; } -#else - RETURN_FALSE; -#endif +} +/* }}} */ + +#endif /* HAVE_GETRLIMIT */ + +/* {{{ proto int posix_get_last_error(void) + Retrieve the error number set by the last posix function which failed. */ +PHP_FUNCTION(posix_get_last_error) +{ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) + return; + + RETURN_LONG(POSIX_G(last_error)); +} +/* }}} */ + +/* {{{ proto string posix_strerror(int errno) + Retrieve the system error message associated with the given errno. */ +PHP_FUNCTION(posix_strerror) +{ + long error; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &error) == FAILURE) + return; + + RETURN_STRING(strerror(error), 1); } /* }}} */ -- 2.40.0