diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/posix | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/posix')
108 files changed, 5902 insertions, 0 deletions
diff --git a/ext/posix/CREDITS b/ext/posix/CREDITS new file mode 100644 index 0000000..34b1a47 --- /dev/null +++ b/ext/posix/CREDITS @@ -0,0 +1,2 @@ +Posix +Kristian Koehntopp diff --git a/ext/posix/config.m4 b/ext/posix/config.m4 new file mode 100644 index 0000000..83ead2e --- /dev/null +++ b/ext/posix/config.m4 @@ -0,0 +1,50 @@ +dnl +dnl $Id$ +dnl + +PHP_ARG_ENABLE(posix,whether to enable POSIX-like functions, +[ --disable-posix Disable POSIX-like functions], yes) + +if test "$PHP_POSIX" = "yes"; then + AC_DEFINE(HAVE_POSIX, 1, [whether to include POSIX-like functions]) + PHP_NEW_EXTENSION(posix, posix.c, $ext_shared) + + AC_CHECK_HEADERS(sys/mkdev.h) + + AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo mknod getrlimit getlogin getgroups makedev initgroups getpwuid_r getgrgid_r) + + AC_MSG_CHECKING([for working ttyname_r() implementation]) + AC_TRY_RUN([ +#include <unistd.h> + +int main(int argc, char *argv[]) +{ + char buf[64]; + + return ttyname_r(0, buf, 64) ? 1 : 0; +} + ],[ + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_TTYNAME_R, 1, [Whether you have a working ttyname_r]) + ],[ + AC_MSG_RESULT([no, posix_ttyname() will be thread-unsafe]) + ], [ + AC_MSG_RESULT([no, cannot detect working ttyname_r() when cross compiling. posix_ttyname() will be thread-unsafe]) + ]) + + AC_CACHE_CHECK([for utsname.domainname], ac_cv_have_utsname_domainname, [ + AC_TRY_COMPILE([ + #define _GNU_SOURCE + #include <sys/utsname.h> + ],[ + return sizeof(((struct utsname *)0)->domainname); + ],[ + ac_cv_have_utsname_domainname=yes + ],[ + ac_cv_have_utsname_domainname=no + ]) + ]) + if test "$ac_cv_have_utsname_domainname" = yes; then + AC_DEFINE(HAVE_UTSNAME_DOMAINNAME, 1, [Wether struct utsname has domainname]) + fi +fi diff --git a/ext/posix/package.xml b/ext/posix/package.xml new file mode 100644 index 0000000..231c5be --- /dev/null +++ b/ext/posix/package.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!DOCTYPE package SYSTEM "../pear/package.dtd"> +<package> + <name>pcntl</name> + <summary>Process control functions</summary> + <maintainers> + <maintainer> + <user>???</user> + <name>Jason Greene</name> + <email>jason@inetgurus.net</email> + <role>lead</role> + </maintainer> + </maintainers> + <description> +Process Control support in PHP implements the Unix style +of process creation, program execution, signal handling +and process termination. Process Control should not be +enabled within a webserver environment and unexpected +results may happen if any Process Control functions +are used within a webserver environment. + </description> + <license>PHP</license> + <release> + <state>beta</state> + <version>5.0.0rc1</version> + <date>2004-03-19</date> + <notes> +package.xml added to support installation using pear installer + </notes> + <filelist> + <file role="doc" name="CREDITS"/> + <file role="doc" name="README"/> + <file role="src" name="config.m4"/> + <file role="src" name="pcntl.c"/> + <file role="src" name="php_pcntl.h"/> + <file role="src" name="php_signal.c"/> + <file role="src" name="php_signal.h"/> + <file role="test" name="test-pcntl.php"/> + <file role="test" name="tests/001.phpt"/> + </filelist> + <deps> + <dep type="php" rel="ge" version="5" /> + <!-- doesn't work yet <dep type="os" rel="has" name="unix"/> --> + </deps> + </release> +</package> +<!-- +vim:et:ts=1:sw=1 +--> diff --git a/ext/posix/php_posix.h b/ext/posix/php_posix.h new file mode 100644 index 0000000..2c07349 --- /dev/null +++ b/ext/posix/php_posix.h @@ -0,0 +1,138 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Kristian Koehntopp <kris@koehntopp.de> | + +----------------------------------------------------------------------+ + */ + + +/* $Id$ */ + +#ifndef PHP_POSIX_H +#define PHP_POSIX_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#if HAVE_POSIX +#ifndef DLEXPORT +#define DLEXPORT +#endif + +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 +#ifdef HAVE_GETGROUPS +PHP_FUNCTION(posix_getgroups); +#endif +#ifdef HAVE_GETLOGIN +PHP_FUNCTION(posix_getlogin); +#endif + +/* 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 +#ifdef HAVE_MKNOD +PHP_FUNCTION(posix_mknod); +#endif + +/* POSIX.1, 5.6 */ +PHP_FUNCTION(posix_access); + +/* 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 + +#ifdef HAVE_INITGROUPS +PHP_FUNCTION(posix_initgroups); +#endif + +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 + +#define posix_module_ptr NULL + +#endif + +#define phpext_posix_ptr posix_module_ptr + +#endif /* PHP_POSIX_H */ diff --git a/ext/posix/posix.c b/ext/posix/posix.c new file mode 100644 index 0000000..cdf1e2e --- /dev/null +++ b/ext/posix/posix.c @@ -0,0 +1,1380 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Kristian Koehntopp <kris@koehntopp.de> | + +----------------------------------------------------------------------+ + */ + +/* $Id: 32db6705f5b617967a546be3114e178a4138c1ca $ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" +#include <unistd.h> +#include "ext/standard/info.h" +#include "ext/standard/php_string.h" +#include "php_posix.h" + + +#if HAVE_POSIX + +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif + +#include <sys/resource.h> + +#if defined(_GNU_SOURCE) && !defined(__USE_GNU) +# define __USE_GNU +#endif + +#include <sys/utsname.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <signal.h> +#include <sys/times.h> +#include <errno.h> +#include <grp.h> +#include <pwd.h> +#if HAVE_SYS_MKDEV_H +# include <sys/mkdev.h> +#endif + +ZEND_DECLARE_MODULE_GLOBALS(posix) +static PHP_MINFO_FUNCTION(posix); + +/* {{{ arginfo */ +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_kill, 0, 0, 2) + ZEND_ARG_INFO(0, pid) + ZEND_ARG_INFO(0, sig) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_posix_getpid, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_posix_getppid, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_posix_getuid, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_setuid, 0, 0, 1) + ZEND_ARG_INFO(0, uid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_posix_geteuid, 0) +ZEND_END_ARG_INFO() + +#ifdef HAVE_SETEUID +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_seteuid, 0, 0, 1) + ZEND_ARG_INFO(0, uid) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_INFO(arginfo_posix_getgid, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_setgid, 0, 0, 1) + ZEND_ARG_INFO(0, gid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_posix_getegid, 0) +ZEND_END_ARG_INFO() + +#ifdef HAVE_SETEGID +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_setegid, 0, 0, 1) + ZEND_ARG_INFO(0, gid) +ZEND_END_ARG_INFO() +#endif + +#ifdef HAVE_GETGROUPS +ZEND_BEGIN_ARG_INFO(arginfo_posix_getgroups, 0) +ZEND_END_ARG_INFO() +#endif + +#ifdef HAVE_GETLOGIN +ZEND_BEGIN_ARG_INFO(arginfo_posix_getlogin, 0) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_INFO(arginfo_posix_getpgrp, 0) +ZEND_END_ARG_INFO() + +#ifdef HAVE_SETSID +ZEND_BEGIN_ARG_INFO(arginfo_posix_setsid, 0) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_setpgid, 0, 0, 2) + ZEND_ARG_INFO(0, pid) + ZEND_ARG_INFO(0, pgid) +ZEND_END_ARG_INFO() + +#ifdef HAVE_GETPGID +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_getpgid, 0, 0, 1) + ZEND_ARG_INFO(0, pid) +ZEND_END_ARG_INFO() +#endif + +#ifdef HAVE_GETSID +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_getsid, 0, 0, 1) + ZEND_ARG_INFO(0, pid) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_INFO(arginfo_posix_uname, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_posix_times, 0) +ZEND_END_ARG_INFO() + +#ifdef HAVE_CTERMID +ZEND_BEGIN_ARG_INFO(arginfo_posix_ctermid, 0) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_ttyname, 0, 0, 1) + ZEND_ARG_INFO(0, fd) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_isatty, 0, 0, 1) + ZEND_ARG_INFO(0, fd) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_posix_getcwd, 0) +ZEND_END_ARG_INFO() + +#ifdef HAVE_MKFIFO +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_mkfifo, 0, 0, 2) + ZEND_ARG_INFO(0, pathname) + ZEND_ARG_INFO(0, mode) +ZEND_END_ARG_INFO() +#endif + +#ifdef HAVE_MKNOD +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_mknod, 0, 0, 2) + ZEND_ARG_INFO(0, pathname) + ZEND_ARG_INFO(0, mode) + ZEND_ARG_INFO(0, major) + ZEND_ARG_INFO(0, minor) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_access, 0, 0, 1) + ZEND_ARG_INFO(0, file) + ZEND_ARG_INFO(0, mode) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_getgrnam, 0, 0, 1) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_getgrgid, 0, 0, 1) + ZEND_ARG_INFO(0, gid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_getpwnam, 0, 0, 1) + ZEND_ARG_INFO(0, username) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_getpwuid, 0, 0, 1) + ZEND_ARG_INFO(0, uid) +ZEND_END_ARG_INFO() + +#ifdef HAVE_GETRLIMIT +ZEND_BEGIN_ARG_INFO(arginfo_posix_getrlimit, 0) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_INFO(arginfo_posix_get_last_error, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_strerror, 0, 0, 1) + ZEND_ARG_INFO(0, errno) +ZEND_END_ARG_INFO() + +#ifdef HAVE_INITGROUPS +ZEND_BEGIN_ARG_INFO_EX(arginfo_posix_initgroups, 0, 0, 2) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, base_group_id) +ZEND_END_ARG_INFO() +#endif +/* }}} */ + +/* {{{ posix_functions[] + */ +const zend_function_entry posix_functions[] = { + /* POSIX.1, 3.3 */ + PHP_FE(posix_kill, arginfo_posix_kill) + + /* POSIX.1, 4.1 */ + PHP_FE(posix_getpid, arginfo_posix_getpid) + PHP_FE(posix_getppid, arginfo_posix_getppid) + + /* POSIX.1, 4.2 */ + PHP_FE(posix_getuid, arginfo_posix_getuid) + PHP_FE(posix_setuid, arginfo_posix_setuid) + PHP_FE(posix_geteuid, arginfo_posix_geteuid) +#ifdef HAVE_SETEUID + PHP_FE(posix_seteuid, arginfo_posix_seteuid) +#endif + PHP_FE(posix_getgid, arginfo_posix_getgid) + PHP_FE(posix_setgid, arginfo_posix_setgid) + PHP_FE(posix_getegid, arginfo_posix_getegid) +#ifdef HAVE_SETEGID + PHP_FE(posix_setegid, arginfo_posix_setegid) +#endif +#ifdef HAVE_GETGROUPS + PHP_FE(posix_getgroups, arginfo_posix_getgroups) +#endif +#ifdef HAVE_GETLOGIN + PHP_FE(posix_getlogin, arginfo_posix_getlogin) +#endif + + /* POSIX.1, 4.3 */ + PHP_FE(posix_getpgrp, arginfo_posix_getpgrp) +#ifdef HAVE_SETSID + PHP_FE(posix_setsid, arginfo_posix_setsid) +#endif + PHP_FE(posix_setpgid, arginfo_posix_setpgid) + /* Non-Posix functions which are common */ +#ifdef HAVE_GETPGID + PHP_FE(posix_getpgid, arginfo_posix_getpgid) +#endif /* HAVE_GETPGID */ +#ifdef HAVE_GETSID + PHP_FE(posix_getsid, arginfo_posix_getsid) +#endif /* HAVE_GETSID */ + + /* POSIX.1, 4.4 */ + PHP_FE(posix_uname, arginfo_posix_uname) + + /* POSIX.1, 4.5 */ + PHP_FE(posix_times, arginfo_posix_times) + + /* POSIX.1, 4.7 */ +#ifdef HAVE_CTERMID + PHP_FE(posix_ctermid, arginfo_posix_ctermid) +#endif + PHP_FE(posix_ttyname, arginfo_posix_ttyname) + PHP_FE(posix_isatty, arginfo_posix_isatty) + + /* POSIX.1, 5.2 */ + PHP_FE(posix_getcwd, arginfo_posix_getcwd) + + /* POSIX.1, 5.4 */ +#ifdef HAVE_MKFIFO + PHP_FE(posix_mkfifo, arginfo_posix_mkfifo) +#endif +#ifdef HAVE_MKNOD + PHP_FE(posix_mknod, arginfo_posix_mknod) +#endif + + /* POSIX.1, 5.6 */ + PHP_FE(posix_access, arginfo_posix_access) + /* POSIX.1, 9.2 */ + PHP_FE(posix_getgrnam, arginfo_posix_getgrnam) + PHP_FE(posix_getgrgid, arginfo_posix_getgrgid) + PHP_FE(posix_getpwnam, arginfo_posix_getpwnam) + PHP_FE(posix_getpwuid, arginfo_posix_getpwuid) + +#ifdef HAVE_GETRLIMIT + PHP_FE(posix_getrlimit, arginfo_posix_getrlimit) +#endif + + PHP_FE(posix_get_last_error, arginfo_posix_get_last_error) + PHP_FALIAS(posix_errno, posix_get_last_error, arginfo_posix_get_last_error) + PHP_FE(posix_strerror, arginfo_posix_strerror) +#ifdef HAVE_INITGROUPS + PHP_FE(posix_initgroups, arginfo_posix_initgroups) +#endif + + PHP_FE_END +}; +/* }}} */ + +/* {{{ PHP_MINFO_FUNCTION + */ +static PHP_MINFO_FUNCTION(posix) +{ + php_info_print_table_start(); + php_info_print_table_row(2, "Revision", "$Id: 32db6705f5b617967a546be3114e178a4138c1ca $"); + php_info_print_table_end(); +} +/* }}} */ + +static PHP_GINIT_FUNCTION(posix) /* {{{ */ +{ + posix_globals->last_error = 0; +} +/* }}} */ + +/* {{{ PHP_MINIT_FUNCTION(posix) + */ +static PHP_MINIT_FUNCTION(posix) +{ + 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); +#ifdef S_IFREG + REGISTER_LONG_CONSTANT("POSIX_S_IFREG", S_IFREG, CONST_CS | CONST_PERSISTENT); +#endif +#ifdef S_IFCHR + REGISTER_LONG_CONSTANT("POSIX_S_IFCHR", S_IFCHR, CONST_CS | CONST_PERSISTENT); +#endif +#ifdef S_IFBLK + REGISTER_LONG_CONSTANT("POSIX_S_IFBLK", S_IFBLK, CONST_CS | CONST_PERSISTENT); +#endif +#ifdef S_IFIFO + REGISTER_LONG_CONSTANT("POSIX_S_IFIFO", S_IFIFO, CONST_CS | CONST_PERSISTENT); +#endif +#ifdef S_IFSOCK + REGISTER_LONG_CONSTANT("POSIX_S_IFSOCK", S_IFSOCK, CONST_CS | CONST_PERSISTENT); +#endif + + return SUCCESS; +} +/* }}} */ + +/* {{{ posix_module_entry + */ +zend_module_entry posix_module_entry = { + STANDARD_MODULE_HEADER, + "posix", + posix_functions, + PHP_MINIT(posix), + NULL, + NULL, + NULL, + PHP_MINFO(posix), + NO_VERSION_YET, + PHP_MODULE_GLOBALS(posix), + PHP_GINIT(posix), + NULL, + NULL, + STANDARD_MODULE_PROPERTIES_EX +}; +/* }}} */ + +#ifdef COMPILE_DL_POSIX +ZEND_GET_MODULE(posix) +#endif + +#define PHP_POSIX_NO_ARGS if (zend_parse_parameters_none() == FAILURE) return; + +#define PHP_POSIX_RETURN_LONG_FUNC(func_name) \ + PHP_POSIX_NO_ARGS \ + RETURN_LONG(func_name()); + +#define PHP_POSIX_SINGLE_ARG_FUNC(func_name) \ + long val; \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) RETURN_FALSE; \ + if (func_name(val) < 0) { \ + POSIX_G(last_error) = errno; \ + RETURN_FALSE; \ + } \ + RETURN_TRUE; + +/* {{{ proto bool posix_kill(int pid, int sig) + Send a signal to a process (POSIX.1, 3.3.2) */ + +PHP_FUNCTION(posix_kill) +{ + long pid, sig; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &pid, &sig) == FAILURE) { + RETURN_FALSE; + } + + if (kill(pid, sig) < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto int posix_getpid(void) + Get the current process id (POSIX.1, 4.1.1) */ +PHP_FUNCTION(posix_getpid) +{ + PHP_POSIX_RETURN_LONG_FUNC(getpid); +} +/* }}} */ + +/* {{{ proto int posix_getppid(void) + Get the parent process id (POSIX.1, 4.1.1) */ +PHP_FUNCTION(posix_getppid) +{ + PHP_POSIX_RETURN_LONG_FUNC(getppid); +} +/* }}} */ + +/* {{{ proto int posix_getuid(void) + Get the current user id (POSIX.1, 4.2.1) */ +PHP_FUNCTION(posix_getuid) +{ + PHP_POSIX_RETURN_LONG_FUNC(getuid); +} +/* }}} */ + +/* {{{ proto int posix_getgid(void) + Get the current group id (POSIX.1, 4.2.1) */ +PHP_FUNCTION(posix_getgid) +{ + PHP_POSIX_RETURN_LONG_FUNC(getgid); +} +/* }}} */ + +/* {{{ proto int posix_geteuid(void) + Get the current effective user id (POSIX.1, 4.2.1) */ +PHP_FUNCTION(posix_geteuid) +{ + PHP_POSIX_RETURN_LONG_FUNC(geteuid); +} +/* }}} */ + +/* {{{ proto int posix_getegid(void) + Get the current effective group id (POSIX.1, 4.2.1) */ +PHP_FUNCTION(posix_getegid) +{ + PHP_POSIX_RETURN_LONG_FUNC(getegid); +} +/* }}} */ + +/* {{{ proto bool posix_setuid(long uid) + Set user id (POSIX.1, 4.2.2) */ +PHP_FUNCTION(posix_setuid) +{ + PHP_POSIX_SINGLE_ARG_FUNC(setuid); +} +/* }}} */ + +/* {{{ proto bool posix_setgid(int uid) + Set group id (POSIX.1, 4.2.2) */ +PHP_FUNCTION(posix_setgid) +{ + PHP_POSIX_SINGLE_ARG_FUNC(setgid); +} +/* }}} */ + +/* {{{ proto bool posix_seteuid(long uid) + Set effective user id */ +#ifdef HAVE_SETEUID +PHP_FUNCTION(posix_seteuid) +{ + PHP_POSIX_SINGLE_ARG_FUNC(seteuid); +} +#endif +/* }}} */ + +/* {{{ proto bool posix_setegid(long uid) + Set effective group id */ +#ifdef HAVE_SETEGID +PHP_FUNCTION(posix_setegid) +{ + PHP_POSIX_SINGLE_ARG_FUNC(setegid); +} +#endif +/* }}} */ + +/* {{{ proto array posix_getgroups(void) + Get supplementary group id's (POSIX.1, 4.2.3) */ +#ifdef HAVE_GETGROUPS +PHP_FUNCTION(posix_getgroups) +{ + gid_t gidlist[NGROUPS_MAX]; + int result; + int i; + + PHP_POSIX_NO_ARGS; + + if ((result = getgroups(NGROUPS_MAX, gidlist)) < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + array_init(return_value); + + for (i=0; i<result; i++) { + add_next_index_long(return_value, gidlist[i]); + } +} +#endif +/* }}} */ + +/* {{{ proto string posix_getlogin(void) + Get user name (POSIX.1, 4.2.4) */ +#ifdef HAVE_GETLOGIN +PHP_FUNCTION(posix_getlogin) +{ + char *p; + + PHP_POSIX_NO_ARGS; + + if (NULL == (p = getlogin())) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + RETURN_STRING(p, 1); +} +#endif +/* }}} */ + +/* {{{ proto int posix_getpgrp(void) + Get current process group id (POSIX.1, 4.3.1) */ +PHP_FUNCTION(posix_getpgrp) +{ + PHP_POSIX_RETURN_LONG_FUNC(getpgrp); +} +/* }}} */ + +/* {{{ proto int posix_setsid(void) + Create session and set process group id (POSIX.1, 4.3.2) */ +#ifdef HAVE_SETSID +PHP_FUNCTION(posix_setsid) +{ + PHP_POSIX_RETURN_LONG_FUNC(setsid); +} +#endif +/* }}} */ + +/* {{{ proto bool posix_setpgid(int pid, int pgid) + Set process group id for job control (POSIX.1, 4.3.3) */ +PHP_FUNCTION(posix_setpgid) +{ + long pid, pgid; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &pid, &pgid) == FAILURE) { + RETURN_FALSE; + } + + if (setpgid(pid, pgid) < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto int posix_getpgid(void) + Get the process group id of the specified process (This is not a POSIX function, but a SVR4ism, so we compile conditionally) */ +#ifdef HAVE_GETPGID +PHP_FUNCTION(posix_getpgid) +{ + long val; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) { + RETURN_FALSE; + } + + if ((val = getpgid(val)) < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + RETURN_LONG(val); +} +#endif +/* }}} */ + +/* {{{ proto int posix_getsid(void) + Get process group id of session leader (This is not a POSIX function, but a SVR4ism, so be compile conditionally) */ +#ifdef HAVE_GETSID +PHP_FUNCTION(posix_getsid) +{ + long val; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) { + RETURN_FALSE; + } + + if ((val = getsid(val)) < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + RETURN_LONG(val); +} +#endif +/* }}} */ + +/* {{{ proto array posix_uname(void) + Get system name (POSIX.1, 4.4.1) */ +PHP_FUNCTION(posix_uname) +{ + struct utsname u; + + PHP_POSIX_NO_ARGS; + + if (uname(&u) < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + array_init(return_value); + + add_assoc_string(return_value, "sysname", u.sysname, 1); + add_assoc_string(return_value, "nodename", u.nodename, 1); + add_assoc_string(return_value, "release", u.release, 1); + add_assoc_string(return_value, "version", u.version, 1); + add_assoc_string(return_value, "machine", u.machine, 1); + +#if defined(_GNU_SOURCE) && !defined(DARWIN) && defined(HAVE_UTSNAME_DOMAINNAME) + add_assoc_string(return_value, "domainname", u.domainname, 1); +#endif +} +/* }}} */ + +/* POSIX.1, 4.5.1 time() - Get System Time + already covered by PHP + */ + +/* {{{ proto array posix_times(void) + Get process times (POSIX.1, 4.5.2) */ +PHP_FUNCTION(posix_times) +{ + struct tms t; + clock_t ticks; + + PHP_POSIX_NO_ARGS; + + if ((ticks = times(&t)) == -1) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + array_init(return_value); + + add_assoc_long(return_value, "ticks", ticks); /* clock ticks */ + add_assoc_long(return_value, "utime", t.tms_utime); /* user time */ + add_assoc_long(return_value, "stime", t.tms_stime); /* system time */ + add_assoc_long(return_value, "cutime", t.tms_cutime); /* user time of children */ + add_assoc_long(return_value, "cstime", t.tms_cstime); /* system time of children */ +} +/* }}} */ + +/* POSIX.1, 4.6.1 getenv() - Environment Access + already covered by PHP +*/ + +/* {{{ proto string posix_ctermid(void) + Generate terminal path name (POSIX.1, 4.7.1) */ +#ifdef HAVE_CTERMID +PHP_FUNCTION(posix_ctermid) +{ + char buffer[L_ctermid]; + + PHP_POSIX_NO_ARGS; + + if (NULL == ctermid(buffer)) { + /* Found no documentation how the defined behaviour is when this + * function fails + */ + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + RETURN_STRING(buffer, 1); +} +#endif +/* }}} */ + +/* Checks if the provides resource is a stream and if it provides a file descriptor */ +static int php_posix_stream_get_fd(zval *zfp, int *fd TSRMLS_DC) /* {{{ */ +{ + php_stream *stream; + + php_stream_from_zval_no_verify(stream, &zfp); + + if (stream == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "expects argument 1 to be a valid stream resource"); + return 0; + } + if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT) == SUCCESS) { + php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT, (void*)fd, 0); + } else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) { + php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)fd, 0); + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not use stream of type '%s'", + stream->ops->label); + return 0; + } + return 1; +} +/* }}} */ + +/* {{{ proto string posix_ttyname(int fd) + Determine terminal device name (POSIX.1, 4.7.2) */ +PHP_FUNCTION(posix_ttyname) +{ + zval **z_fd; + char *p; + int fd; +#if defined(ZTS) && defined(HAVE_TTYNAME_R) && defined(_SC_TTY_NAME_MAX) + long buflen; +#endif + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &z_fd) == FAILURE) { + RETURN_FALSE; + } + + switch (Z_TYPE_PP(z_fd)) { + case IS_RESOURCE: + if (!php_posix_stream_get_fd(*z_fd, &fd TSRMLS_CC)) { + RETURN_FALSE; + } + break; + default: + convert_to_long_ex(z_fd); + fd = Z_LVAL_PP(z_fd); + } +#if defined(ZTS) && defined(HAVE_TTYNAME_R) && defined(_SC_TTY_NAME_MAX) + buflen = sysconf(_SC_TTY_NAME_MAX); + if (buflen < 1) { + RETURN_FALSE; + } + p = emalloc(buflen); + + if (ttyname_r(fd, p, buflen)) { + POSIX_G(last_error) = errno; + efree(p); + RETURN_FALSE; + } + RETURN_STRING(p, 0); +#else + if (NULL == (p = ttyname(fd))) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } +#endif + RETURN_STRING(p, 1); +} +/* }}} */ + +/* {{{ proto bool posix_isatty(int fd) + Determine if filedesc is a tty (POSIX.1, 4.7.1) */ +PHP_FUNCTION(posix_isatty) +{ + zval **z_fd; + int fd; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &z_fd) == FAILURE) { + RETURN_FALSE; + } + + switch (Z_TYPE_PP(z_fd)) { + case IS_RESOURCE: + if (!php_posix_stream_get_fd(*z_fd, &fd TSRMLS_CC)) { + RETURN_FALSE; + } + break; + default: + convert_to_long_ex(z_fd); + fd = Z_LVAL_PP(z_fd); + } + + if (isatty(fd)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* + POSIX.1, 4.8.1 sysconf() - TODO + POSIX.1, 5.7.1 pathconf(), fpathconf() - TODO + + POSIX.1, 5.1.2 opendir(), readdir(), rewinddir(), closedir() + POSIX.1, 5.2.1 chdir() + already supported by PHP + */ + +/* {{{ proto string posix_getcwd(void) + Get working directory pathname (POSIX.1, 5.2.2) */ +PHP_FUNCTION(posix_getcwd) +{ + char buffer[MAXPATHLEN]; + char *p; + + PHP_POSIX_NO_ARGS; + + p = VCWD_GETCWD(buffer, MAXPATHLEN); + if (!p) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + RETURN_STRING(buffer, 1); +} +/* }}} */ + +/* + POSIX.1, 5.3.x open(), creat(), umask() + POSIX.1, 5.4.1 link() + already supported by PHP. + */ + +/* {{{ proto bool posix_mkfifo(string pathname, int mode) + Make a FIFO special file (POSIX.1, 5.4.2) */ +#ifdef HAVE_MKFIFO +PHP_FUNCTION(posix_mkfifo) +{ + char *path; + int path_len; + long mode; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pl", &path, &path_len, &mode) == FAILURE) { + RETURN_FALSE; + } + + if (php_check_open_basedir_ex(path, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + + result = mkfifo(path, mode); + if (result < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + RETURN_TRUE; +} +#endif +/* }}} */ + +/* {{{ proto bool posix_mknod(string pathname, int mode [, int major [, int minor]]) + Make a special or ordinary file (POSIX.1) */ +#ifdef HAVE_MKNOD +PHP_FUNCTION(posix_mknod) +{ + char *path; + int path_len; + long mode; + long major = 0, minor = 0; + int result; + dev_t php_dev; + + php_dev = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pl|ll", &path, &path_len, + &mode, &major, &minor) == FAILURE) { + RETURN_FALSE; + } + + if (php_check_open_basedir_ex(path, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + + if ((mode & S_IFCHR) || (mode & S_IFBLK)) { + if (ZEND_NUM_ARGS() == 2) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "For S_IFCHR and S_IFBLK you need to pass a major device kernel identifier"); + RETURN_FALSE; + } + if (major == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "Expects argument 3 to be non-zero for POSIX_S_IFCHR and POSIX_S_IFBLK"); + RETURN_FALSE; + } else { +#if defined(HAVE_MAKEDEV) || defined(makedev) + php_dev = makedev(major, minor); +#else + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create a block or character device, creating a normal file instead"); +#endif + } + } + + result = mknod(path, mode, php_dev); + if (result < 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + RETURN_TRUE; +} +#endif +/* }}} */ + +/* Takes a pointer to posix group and a pointer to an already initialized ZVAL + * array container and fills the array with the posix group member data. */ +int php_posix_group_to_array(struct group *g, zval *array_group) /* {{{ */ +{ + zval *array_members; + int count; + + if (NULL == g) + return 0; + + if (array_group == NULL || Z_TYPE_P(array_group) != IS_ARRAY) + return 0; + + MAKE_STD_ZVAL(array_members); + array_init(array_members); + + add_assoc_string(array_group, "name", g->gr_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() + POSIX.1, 5.5.3 rename() + 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, "p|l", &filename, &filename_len, &mode) == FAILURE) { + RETURN_FALSE; + } + + path = expand_filepath(filename, NULL TSRMLS_CC); + if (!path) { + POSIX_G(last_error) = EIO; + RETURN_FALSE; + } + + 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 +*/ + +/* {{{ proto array posix_getgrnam(string groupname) + Group database access (POSIX.1, 9.2.1) */ +PHP_FUNCTION(posix_getgrnam) +{ + char *name; + struct group *g; + int name_len; +#if defined(ZTS) && defined(HAVE_GETGRNAM_R) && defined(_SC_GETGR_R_SIZE_MAX) + struct group gbuf; + long buflen; + char *buf; +#endif + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + RETURN_FALSE; + } + +#if defined(ZTS) && defined(HAVE_GETGRNAM_R) && defined(_SC_GETGR_R_SIZE_MAX) + buflen = sysconf(_SC_GETGR_R_SIZE_MAX); + if (buflen < 1) { + RETURN_FALSE; + } + buf = emalloc(buflen); + g = &gbuf; + + if (getgrnam_r(name, g, buf, buflen, &g) || g == NULL) { + POSIX_G(last_error) = errno; + efree(buf); + RETURN_FALSE; + } +#else + if (NULL == (g = getgrnam(name))) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } +#endif + array_init(return_value); + + if (!php_posix_group_to_array(g, return_value)) { + zval_dtor(return_value); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to convert posix group to array"); + RETVAL_FALSE; + } +#if defined(ZTS) && defined(HAVE_GETGRNAM_R) && defined(_SC_GETGR_R_SIZE_MAX) + efree(buf); +#endif +} +/* }}} */ + +/* {{{ proto array posix_getgrgid(long gid) + Group database access (POSIX.1, 9.2.1) */ +PHP_FUNCTION(posix_getgrgid) +{ + long gid; +#if defined(ZTS) && defined(HAVE_GETGRGID_R) && defined(_SC_GETGR_R_SIZE_MAX) + int ret; + struct group _g; + struct group *retgrptr = NULL; + long grbuflen; + char *grbuf; +#endif + struct group *g; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &gid) == FAILURE) { + RETURN_FALSE; + } +#if defined(ZTS) && defined(HAVE_GETGRGID_R) && defined(_SC_GETGR_R_SIZE_MAX) + + grbuflen = sysconf(_SC_GETGR_R_SIZE_MAX); + if (grbuflen < 1) { + RETURN_FALSE; + } + + grbuf = emalloc(grbuflen); + + ret = getgrgid_r(gid, &_g, grbuf, grbuflen, &retgrptr); + if (ret || retgrptr == NULL) { + POSIX_G(last_error) = ret; + efree(grbuf); + RETURN_FALSE; + } + 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)) { + zval_dtor(return_value); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to convert posix group struct to array"); + RETVAL_FALSE; + } +#if defined(ZTS) && defined(HAVE_GETGRGID_R) && defined(_SC_GETGR_R_SIZE_MAX) + efree(grbuf); +#endif +} +/* }}} */ + +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) +{ + struct passwd *pw; + char *name; + int name_len; +#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R) + struct passwd pwbuf; + long buflen; + char *buf; +#endif + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + RETURN_FALSE; + } + +#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R) + buflen = sysconf(_SC_GETPW_R_SIZE_MAX); + if (buflen < 1) { + RETURN_FALSE; + } + buf = emalloc(buflen); + pw = &pwbuf; + + if (getpwnam_r(name, pw, buf, buflen, &pw) || pw == NULL) { + efree(buf); + POSIX_G(last_error) = errno; + RETURN_FALSE; + } +#else + if (NULL == (pw = getpwnam(name))) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } +#endif + array_init(return_value); + + if (!php_posix_passwd_to_array(pw, return_value)) { + zval_dtor(return_value); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to convert posix passwd struct to array"); + RETVAL_FALSE; + } +#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R) + efree(buf); +#endif +} +/* }}} */ + +/* {{{ proto array posix_getpwuid(long uid) + User database access (POSIX.1, 9.2.2) */ +PHP_FUNCTION(posix_getpwuid) +{ + long uid; +#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWUID_R) + struct passwd _pw; + struct passwd *retpwptr = NULL; + long pwbuflen; + char *pwbuf; + int ret; +#endif + struct passwd *pw; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &uid) == FAILURE) { + RETURN_FALSE; + } +#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWUID_R) + pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX); + if (pwbuflen < 1) { + RETURN_FALSE; + } + pwbuf = emalloc(pwbuflen); + + ret = getpwuid_r(uid, &_pw, pwbuf, pwbuflen, &retpwptr); + if (ret || retpwptr == NULL) { + POSIX_G(last_error) = ret; + efree(pwbuf); + RETURN_FALSE; + } + 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)) { + zval_dtor(return_value); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to convert posix passwd struct to array"); + RETVAL_FALSE; + } +#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWUID_R) + efree(pwbuf); +#endif +} +/* }}} */ + + +#ifdef HAVE_GETRLIMIT + +#define UNLIMITED_STRING "unlimited" + +/* {{{ posix_addlimit + */ +static int posix_addlimit(int limit, char *name, zval *return_value TSRMLS_DC) { + int result; + struct rlimit rl; + char hard[80]; + char soft[80]; + + snprintf(hard, 80, "hard %s", name); + snprintf(soft, 80, "soft %s", name); + + result = getrlimit(limit, &rl); + if (result < 0) { + POSIX_G(last_error) = errno; + return FAILURE; + } + + if (rl.rlim_cur == RLIM_INFINITY) { + add_assoc_stringl(return_value, soft, UNLIMITED_STRING, sizeof(UNLIMITED_STRING)-1, 1); + } else { + add_assoc_long(return_value, soft, rl.rlim_cur); + } + + if (rl.rlim_max == RLIM_INFINITY) { + add_assoc_stringl(return_value, hard, UNLIMITED_STRING, sizeof(UNLIMITED_STRING)-1, 1); + } else { + add_assoc_long(return_value, hard, rl.rlim_max); + } + + return SUCCESS; +} +/* }}} */ + +/* {{{ limits[] + */ +struct limitlist { + int limit; + char *name; +} limits[] = { +#ifdef RLIMIT_CORE + { RLIMIT_CORE, "core" }, +#endif + +#ifdef RLIMIT_DATA + { RLIMIT_DATA, "data" }, +#endif + +#ifdef RLIMIT_STACK + { RLIMIT_STACK, "stack" }, +#endif + +#ifdef RLIMIT_VMEM + { RLIMIT_VMEM, "virtualmem" }, +#endif + +#ifdef RLIMIT_AS + { RLIMIT_AS, "totalmem" }, +#endif + +#ifdef RLIMIT_RSS + { RLIMIT_RSS, "rss" }, +#endif + +#ifdef RLIMIT_NPROC + { RLIMIT_NPROC, "maxproc" }, +#endif + +#ifdef RLIMIT_MEMLOCK + { RLIMIT_MEMLOCK, "memlock" }, +#endif + +#ifdef RLIMIT_CPU + { RLIMIT_CPU, "cpu" }, +#endif + +#ifdef RLIMIT_FSIZE + { RLIMIT_FSIZE, "filesize" }, +#endif + +#ifdef RLIMIT_NOFILE + { RLIMIT_NOFILE, "openfiles" }, +#endif + +#ifdef RLIMIT_OFILE + { RLIMIT_OFILE, "openfiles" }, +#endif + + { 0, NULL } +}; +/* }}} */ + + +/* {{{ proto array 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) +{ + struct limitlist *l = NULL; + + PHP_POSIX_NO_ARGS; + + array_init(return_value); + + for (l=limits; l->name; l++) { + if (posix_addlimit(l->limit, l->name, return_value TSRMLS_CC) == FAILURE) { + zval_dtor(return_value); + RETURN_FALSE; + } + } +} +/* }}} */ + +#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) +{ + PHP_POSIX_NO_ARGS; + + 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_FALSE; + } + + RETURN_STRING(strerror(error), 1); +} +/* }}} */ + +#endif + +#ifdef HAVE_INITGROUPS +/* {{{ proto bool posix_initgroups(string name, int base_group_id) + Calculate the group access list for the user specified in name. */ +PHP_FUNCTION(posix_initgroups) +{ + long basegid; + char *name; + int name_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &name, &name_len, &basegid) == FAILURE) { + RETURN_FALSE; + } + + if (name_len == 0) { + RETURN_FALSE; + } + + RETURN_BOOL(!initgroups((const char *)name, basegid)); +} +/* }}} */ +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/ext/posix/tests/001.phpt b/ext/posix/tests/001.phpt new file mode 100644 index 0000000..e6c629c --- /dev/null +++ b/ext/posix/tests/001.phpt @@ -0,0 +1,12 @@ +--TEST-- +posix_access() with bogus paths +--SKIPIF-- +<?php if (!extension_loaded('posix')) echo 'skip'; ?> +--FILE-- +<?php + +var_dump(posix_access(str_repeat('bogus path', 1042))); + +?> +--EXPECT-- +bool(false) diff --git a/ext/posix/tests/posix_access.phpt b/ext/posix/tests/posix_access.phpt new file mode 100644 index 0000000..47b5e15 --- /dev/null +++ b/ext/posix/tests/posix_access.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test posix_access() function test +--DESCRIPTION-- +checks for existence, read-access, write-access, execute-access +--CREDITS-- +Moritz Neuhaeuser, info@xcompile.net +PHP Testfest Berlin 2009-05-10 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +if (posix_geteuid() == 0) { + die('SKIP Cannot run test as root.'); +} +if (PHP_VERSION_ID < 503099) { + die('SKIP Safe mode is no longer available.'); +} +?> +--FILE-- +<?php +$filename = dirname(__FILE__) . '/foo.test'; +$fp = fopen($filename,"w"); +fwrite($fp,"foo"); +fclose($fp); + +chmod ($filename, 0000); +var_dump(posix_access($filename, POSIX_F_OK)); + +chmod ($filename, 0400); +var_dump(posix_access($filename, POSIX_R_OK)); + +chmod ($filename, 0600); +var_dump(posix_access($filename, POSIX_W_OK)); + +chmod ($filename, 0700); +var_dump(posix_access($filename, POSIX_X_OK)); +?> +===DONE=== +--CLEAN-- +<?php +$filename = dirname(__FILE__) . '/foo.test'; +chmod ($filename, 0700); +unlink($filename); +?> +--EXPECTF-- +Deprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in %s on line %d +bool(true) +bool(true) +bool(true) +bool(true) +===DONE=== diff --git a/ext/posix/tests/posix_access_error_modes.phpt b/ext/posix/tests/posix_access_error_modes.phpt new file mode 100644 index 0000000..fb04e34 --- /dev/null +++ b/ext/posix/tests/posix_access_error_modes.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test posix_access() function test error conditions +--DESCRIPTION-- +checks if posix_access() failes for wrong permissions +--CREDITS-- +Moritz Neuhaeuser, info@xcompile.net +PHP Testfest Berlin 2009-05-10 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +if (posix_geteuid() == 0) { + die('SKIP Cannot run test as root.'); +} +if (PHP_VERSION_ID < 503099) { + die('SKIP Safe mode is no longer available.'); +} +?> +--FILE-- +<?php +$filename = dirname(__FILE__) . '/foo.test'; +var_dump(posix_access($filename, POSIX_F_OK)); +$fp = fopen($filename,"w"); +fwrite($fp,"foo"); +fclose($fp); + +chmod ($filename, 0000); +var_dump(posix_access($filename, POSIX_R_OK)); +var_dump(posix_access($filename, POSIX_W_OK)); +var_dump(posix_access($filename, POSIX_X_OK)); +?> +===DONE=== +--CLEAN-- +<?php +$filename = dirname(__FILE__) . '/foo.test'; +chmod ($filename, 0700); +unlink($filename); +?> +--EXPECTF-- +WDeprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line %d +bool(false) +bool(false) +bool(false) +bool(false) +===DONE=== diff --git a/ext/posix/tests/posix_access_error_wrongparams.phpt b/ext/posix/tests/posix_access_error_wrongparams.phpt new file mode 100644 index 0000000..35556a1 --- /dev/null +++ b/ext/posix/tests/posix_access_error_wrongparams.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test posix_access() function : parameter validation +--DESCRIPTION-- +cases: no params, wrong param1, wrong param2, null directory, wrong directory, +--CREDITS-- +Moritz Neuhaeuser, info@xcompile.net +PHP Testfest Berlin 2009-05-10 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +if (posix_geteuid() == 0) { + die('SKIP Cannot run test as root.'); +} +if (PHP_VERSION_ID < 503099) { + die('SKIP Safe mode is no longer available.'); +} +?> +--FILE-- +<?php + +var_dump( posix_access() ); +var_dump( posix_access(array()) ); +var_dump( posix_access('foo',array()) ); +var_dump( posix_access(null) ); + +var_dump(posix_access('./foobar')); +?> +===DONE=== +--EXPECTF-- +Deprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0 + +Warning: posix_access() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +Warning: posix_access() expects parameter 1 to be string, array given in %s on line %d +bool(false) + +Warning: posix_access() expects parameter 2 to be long, array given in %s on line %d +bool(false) +bool(false) +bool(false) +===DONE=== diff --git a/ext/posix/tests/posix_access_safemode.phpt b/ext/posix/tests/posix_access_safemode.phpt new file mode 100644 index 0000000..b726b4f --- /dev/null +++ b/ext/posix/tests/posix_access_safemode.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test posix_access() with safe_mode enabled. +--CREDITS-- +Till Klampaeckel, till@php.net +TestFest Berlin 2009 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +if (posix_geteuid() == 0) { + die('SKIP Cannot run test as root.'); +} +if (PHP_VERSION_ID < 503099) { + die('SKIP Safe mode is no longer available.'); +} +--FILE-- +<?php +var_dump(posix_access('/tmp', POSIX_W_OK)); +?> +===DONE=== +--EXPECTF-- +Deprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in %s on line %d +bool(false) +===DONE=== diff --git a/ext/posix/tests/posix_ctermid.phpt b/ext/posix/tests/posix_ctermid.phpt new file mode 100644 index 0000000..f77da00 --- /dev/null +++ b/ext/posix/tests/posix_ctermid.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test posix_ctermid() +--DESCRIPTION-- +Gets path name of controlling terminal. +Source code: ext/posix/posix.c +--CREDITS-- +Falko Menge, mail at falko-menge dot de +PHP Testfest Berlin 2009-05-10 +--SKIPIF-- +<?php + if (!extension_loaded('posix')) { + die('SKIP - POSIX extension not available'); + } + // needed because of #ifdef HAVE_CTERMID in posix.c + if (!function_exists('posix_ctermid')) { + die('SKIP - Fuction posix_ctermid() not available'); + } +?> +--FILE-- +<?php + var_dump(posix_ctermid()); +?> +===DONE=== +--EXPECTF-- +string(%d) "%s" +===DONE=== diff --git a/ext/posix/tests/posix_ctermid_basic.phpt b/ext/posix/tests/posix_ctermid_basic.phpt new file mode 100644 index 0000000..d1d4694 --- /dev/null +++ b/ext/posix/tests/posix_ctermid_basic.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test function posix_ctermid() by calling it with its expected arguments +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php + +var_dump( posix_ctermid() ); + +?> +--EXPECTF-- +string(%d) %s diff --git a/ext/posix/tests/posix_ctermid_error.phpt b/ext/posix/tests/posix_ctermid_error.phpt new file mode 100644 index 0000000..a177f54 --- /dev/null +++ b/ext/posix/tests/posix_ctermid_error.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test function posix_ctermid() by calling it more than or less than its expected arguments +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + +var_dump( posix_ctermid( 'foo' ) ); + +?> +--EXPECTF-- +Warning: posix_ctermid() expects exactly 0 parameters, 1 given in %s on line %d +NULL diff --git a/ext/posix/tests/posix_errno_basic.phpt b/ext/posix/tests/posix_errno_basic.phpt new file mode 100644 index 0000000..cd94a97 --- /dev/null +++ b/ext/posix/tests/posix_errno_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test function posix_errno() by calling it with its expected arguments +--CREDITS-- +Morten Amundsen mor10am@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php + +echo "*** Test by calling method or function with its expected arguments ***\n"; + +// test without any error +var_dump(posix_errno()); + +?> +--EXPECTF-- +*** Test by calling method or function with its expected arguments *** +int(0) diff --git a/ext/posix/tests/posix_errno_error.phpt b/ext/posix/tests/posix_errno_error.phpt new file mode 100644 index 0000000..0a77fb0 --- /dev/null +++ b/ext/posix/tests/posix_errno_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test function posix_errno() by calling it with its expected arguments +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Morten Amundsen mor10am@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + +echo "*** Test by calling method or function with more than expected arguments ***\n"; + +// test without any error +var_dump(posix_errno('bar')); + +?> +--EXPECTF-- +*** Test by calling method or function with more than expected arguments *** + +Warning: posix_errno() expects exactly 0 parameters, 1 given in %s on line %d +NULL diff --git a/ext/posix/tests/posix_errno_variation1.phpt b/ext/posix/tests/posix_errno_variation1.phpt new file mode 100644 index 0000000..b57b7c0 --- /dev/null +++ b/ext/posix/tests/posix_errno_variation1.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test function posix_errno() by calling it with with permission error +--CREDITS-- +Morten Amundsen mor10am@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_getuid()==0) print "skip - Cannot run test as root."; +?> +--FILE-- +<?php + +echo "*** Test by calling function with permission error ***\n"; + +posix_setuid(0); +var_dump(posix_errno()); + +?> +--EXPECTF-- +*** Test by calling function with permission error *** +int(1) diff --git a/ext/posix/tests/posix_errno_variation2.phpt b/ext/posix/tests/posix_errno_variation2.phpt new file mode 100644 index 0000000..ad3aa31 --- /dev/null +++ b/ext/posix/tests/posix_errno_variation2.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test function posix_errno() by calling it with its expected arguments +--CREDITS-- +Morten Amundsen mor10am@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(!extension_loaded("pcntl")) print "skip - PCNTL extension required"; +?> +--FILE-- +<?php + +echo "*** Test by calling function with pid error ***\n"; + +$pid = 10000; + +do { + $pid += 1; + $result = shell_exec("ps -p " . $pid); +} while (strstr($pid, $result)); + +posix_kill($pid, SIGKILL); +var_dump(posix_errno()); + +?> +--EXPECTF-- +*** Test by calling function with pid error *** +int(3) diff --git a/ext/posix/tests/posix_get_last_error_error.phpt b/ext/posix/tests/posix_get_last_error_error.phpt new file mode 100644 index 0000000..6cf2161 --- /dev/null +++ b/ext/posix/tests/posix_get_last_error_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test posix_get_last_error() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto int posix_get_last_error(void) + * Description: Retrieve the error number set by the last posix function which failed. + * Source code: ext/posix/posix.c + * Alias to functions: posix_errno + */ + +echo "*** Testing posix_get_last_error() : error conditions ***\n"; + +// One argument +echo "\n-- Testing posix_get_last_error() function with one argument --\n"; +$extra_arg = 10; +var_dump( posix_get_last_error($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_get_last_error() : error conditions *** + +-- Testing posix_get_last_error() function with one argument -- + +Warning: posix_get_last_error() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/posix/tests/posix_getcwd.phpt b/ext/posix/tests/posix_getcwd.phpt new file mode 100644 index 0000000..75c8d57 --- /dev/null +++ b/ext/posix/tests/posix_getcwd.phpt @@ -0,0 +1,19 @@ +--TEST-- +posix_getcwd(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_getcwd')) die('skip posix_getcwd() not found'); +?> +--FILE-- +<?php + +var_dump(posix_getcwd()); +var_dump(posix_getcwd(1)); + +?> +--EXPECTF-- +string(%d) "%s" + +Warning: posix_getcwd() expects exactly 0 parameters, 1 given in %s on line %d +NULL diff --git a/ext/posix/tests/posix_getcwd_basic.phpt b/ext/posix/tests/posix_getcwd_basic.phpt new file mode 100644 index 0000000..2477c37 --- /dev/null +++ b/ext/posix/tests/posix_getcwd_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +posix_getcwd(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_getcwd')) die('skip posix_getcwd() not found'); +?> +--FILE-- +<?php +echo "Basic test of POSIX posix_getcwd function\n"; +var_dump(posix_getcwd()); +var_dump(posix_getcwd(1)); + +?> +===DONE=== +--EXPECTF-- +Basic test of POSIX posix_getcwd function +string(%d) "%s" + +Warning: posix_getcwd() expects exactly 0 parameters, 1 given in %s on line %d +NULL +===DONE=== diff --git a/ext/posix/tests/posix_getegid_basic.phpt b/ext/posix/tests/posix_getegid_basic.phpt new file mode 100644 index 0000000..d0016f4 --- /dev/null +++ b/ext/posix/tests/posix_getegid_basic.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test function posix_getegid() by calling it with its expected arguments +--CREDITS-- +Michelangelo van Dam dragonbe@gmail.com +#PHPTestFest Dutch PHP Conference 2012 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +var_dump(posix_getegid()); +?> +--EXPECTF-- +int(%d) diff --git a/ext/posix/tests/posix_geteuid_basic.phpt b/ext/posix/tests/posix_geteuid_basic.phpt new file mode 100644 index 0000000..76e9028 --- /dev/null +++ b/ext/posix/tests/posix_geteuid_basic.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test function posix_geteuid() by calling it with its expected arguments +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +var_dump(posix_geteuid()); +?> +--EXPECTF-- +int(%d) diff --git a/ext/posix/tests/posix_geteuid_error1.phpt b/ext/posix/tests/posix_geteuid_error1.phpt new file mode 100644 index 0000000..ac4e0d5 --- /dev/null +++ b/ext/posix/tests/posix_geteuid_error1.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test function posix_geteuid() by calling it more than or less than its expected arguments +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php +echo "*** Test by calling method or function with incorrect numbers of arguments ***\n"; + +$extra_args = array( 12312, 2 => '1234', 'string' => 'string' ); + +var_dump( posix_geteuid( $extra_args )); +foreach ( $extra_args as $arg ) +{ + var_dump(posix_geteuid( $arg )); +} + +?> +--EXPECTF-- +*** Test by calling method or function with incorrect numbers of arguments *** + +Warning: posix_geteuid() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: posix_geteuid() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: posix_geteuid() expects exactly 0 parameters, 1 given in %s on line %d +NULL + +Warning: posix_geteuid() expects exactly 0 parameters, 1 given in %s on line %d +NULL diff --git a/ext/posix/tests/posix_getgid_error.phpt b/ext/posix/tests/posix_getgid_error.phpt new file mode 100644 index 0000000..bcd7a2f --- /dev/null +++ b/ext/posix/tests/posix_getgid_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test posix_getgid() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto int posix_getgid(void) + * Description: Get the current group id (POSIX.1, 4.2.1) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getgid() : error conditions ***\n"; + +// One argument +echo "\n-- Testing posix_getgid() function with one argument --\n"; +$extra_arg = 10; +var_dump( posix_getgid($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getgid() : error conditions *** + +-- Testing posix_getgid() function with one argument -- + +Warning: posix_getgid() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/posix/tests/posix_getgrgid.phpt b/ext/posix/tests/posix_getgrgid.phpt new file mode 100644 index 0000000..0209d09 --- /dev/null +++ b/ext/posix/tests/posix_getgrgid.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test posix_getgrgid(). +--CREDITS-- +Till Klampaeckel, till@php.net +TestFest Berlin 2009 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +?> +--FILE-- +<?php +$grp = posix_getgrgid(0); +if (!isset($grp['name'])) { + die('Array index "name" does not exist.'); +} +if (!isset($grp['passwd'])) { + die('Array index "passwd" does not exist.'); +} +if (!isset($grp['members'])) { + die('Array index "members" does not exist.'); +} elseif (!is_array($grp['members'])) { + die('Array index "members" must be an array.'); +} else { + if (count($grp['members']) > 0) { + foreach ($grp['members'] as $idx => $username) { + if (!is_int($idx)) { + die('Index in members Array is not an int.'); + } + if (!is_string($username)) { + die('Username in members Array is not of type string.'); + } + } + } +} +if (!isset($grp['gid'])) { + die('Array index "gid" does not exist.'); +} +var_dump($grp['gid']); +?> +===DONE=== +--EXPECT-- +int(0) +===DONE=== diff --git a/ext/posix/tests/posix_getgrgid_basic.phpt b/ext/posix/tests/posix_getgrgid_basic.phpt new file mode 100644 index 0000000..fdcdf35 --- /dev/null +++ b/ext/posix/tests/posix_getgrgid_basic.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test posix_getgrgid() function : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of POSIX getgid and getgrid fucntions\n"; + + $gid = posix_getgid(); + $groupinfo = posix_getgrgid($gid); + + print_r($groupinfo); + +?> +===DONE=== +--EXPECTF-- +Basic test of POSIX getgid and getgrid fucntions +Array +( + [name] => %s + [passwd] => %a + [members] => Array +%a + + [gid] => %d +) +===DONE=== + diff --git a/ext/posix/tests/posix_getgrgid_error.phpt b/ext/posix/tests/posix_getgrgid_error.phpt new file mode 100644 index 0000000..7fcc892 --- /dev/null +++ b/ext/posix/tests/posix_getgrgid_error.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test posix_getgrgid() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto array posix_getgrgid(long gid) + * Description: Group database access (POSIX.1, 9.2.1) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getgrgid() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing posix_getgrgid() function with Zero arguments --\n"; +var_dump( posix_getgrgid() ); + +//Test posix_getgrgid with one more than the expected number of arguments +echo "\n-- Testing posix_getgrgid() function with more than expected no. of arguments --\n"; + +$extra_arg = 10; +$gid = 0; +var_dump( posix_getgrgid($gid, $extra_arg) ); + +echo "\n-- Testing posix_getgrgid() function with a negative group id --\n"; +$gid = -999; +var_dump( posix_getgrgid($gid)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getgrgid() : error conditions *** + +-- Testing posix_getgrgid() function with Zero arguments -- + +Warning: posix_getgrgid() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing posix_getgrgid() function with more than expected no. of arguments -- + +Warning: posix_getgrgid() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) + +-- Testing posix_getgrgid() function with a negative group id -- +bool(false) +Done diff --git a/ext/posix/tests/posix_getgrgid_macosx.phpt b/ext/posix/tests/posix_getgrgid_macosx.phpt new file mode 100644 index 0000000..f9e6cc1 --- /dev/null +++ b/ext/posix/tests/posix_getgrgid_macosx.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test return values of posix_getgrgid() on MacOSX. +--CREDITS-- +Till Klampaeckel, till@php.net +TestFest Berlin 2009 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +if (strtolower(PHP_OS) != 'darwin') { + die('SKIP This test requires MacOSX/Darwin.'); +} +?> +--FILE-- +<?php +$grp = posix_getgrgid(-1); +var_dump($grp['name']); +?> +===DONE=== +--EXPECT-- +string(7) "nogroup" +===DONE=== diff --git a/ext/posix/tests/posix_getgrgid_variation.phpt b/ext/posix/tests/posix_getgrgid_variation.phpt new file mode 100644 index 0000000..5cce391 --- /dev/null +++ b/ext/posix/tests/posix_getgrgid_variation.phpt @@ -0,0 +1,185 @@ +--TEST-- +Test posix_getgrgid() function : usage variations - parameter types +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto array posix_getgrgid(long gid) + * Description: Group database access (POSIX.1, 9.2.1) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getgrgid() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, + + // object data + new stdclass(), +); + +// loop through each element of the array for gid + +foreach($values as $value) { + echo "\nArg value $value \n"; + $result = posix_getgrgid($value); + if ((is_array($result) && (count($result) == 4)) + || + ($result === false)) { + echo "valid output\n"; + } else { + var_dump($result); + } +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getgrgid() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +Arg value 10.5 +valid output + +Arg value -10.5 +valid output + +Arg value 101234567000 +valid output + +Arg value 1.07654321E-9 +valid output + +Arg value 0.5 +valid output + +Notice: Array to string conversion in %sposix_getgrgid_variation.php on line %d + +Arg value Array + +Warning: posix_getgrgid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getgrgid_variation.php on line %d + +Arg value Array + +Warning: posix_getgrgid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getgrgid_variation.php on line %d + +Arg value Array + +Warning: posix_getgrgid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getgrgid_variation.php on line %d + +Arg value Array + +Warning: posix_getgrgid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getgrgid_variation.php on line %d + +Arg value Array + +Warning: posix_getgrgid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Arg value +valid output + +Arg value +valid output + +Arg value 1 +valid output + +Arg value +valid output + +Arg value 1 +valid output + +Arg value +valid output + +Arg value + +Warning: posix_getgrgid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value + +Warning: posix_getgrgid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value string + +Warning: posix_getgrgid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value string + +Warning: posix_getgrgid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value +valid output + +Arg value +valid output + +Catchable fatal error: Object of class stdClass could not be converted to string in %s on line %d diff --git a/ext/posix/tests/posix_getgrgid_wrongparams.phpt b/ext/posix/tests/posix_getgrgid_wrongparams.phpt new file mode 100644 index 0000000..d1ff77d --- /dev/null +++ b/ext/posix/tests/posix_getgrgid_wrongparams.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test parameters on posix_getgrgid(). +--CREDITS-- +Till Klampaeckel, till@php.net +TestFest Berlin 2009 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +if (strtolower(PHP_OS) == 'darwin') { + die('SKIP This test doesn\'t run on MacOSX/Darwin.'); +} +--FILE-- +<?php +$gid = PHP_INT_MAX; // obscene high gid +var_dump(posix_getgrgid($gid)); +var_dump(posix_getgrgid(-1)); +var_dump(posix_getgrgid()); +?> +===DONE=== +--EXPECTF-- +bool(false) +bool(false) + +Warning: posix_getgrgid() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/posix/tests/posix_getgrnam.phpt b/ext/posix/tests/posix_getgrnam.phpt new file mode 100644 index 0000000..854db4a --- /dev/null +++ b/ext/posix/tests/posix_getgrnam.phpt @@ -0,0 +1,19 @@ +--TEST-- +posix_getgrnam(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_getgrnam')) die('skip posix_getgrnam() not found'); +?> +--FILE-- +<?php + +var_dump(posix_getgrnam(NULL)); +var_dump(posix_getgrnam(1)); +var_dump(posix_getgrnam('')); + +?> +--EXPECT-- +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_getgrnam_basic.phpt b/ext/posix/tests/posix_getgrnam_basic.phpt new file mode 100644 index 0000000..fd5bf23 --- /dev/null +++ b/ext/posix/tests/posix_getgrnam_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +posix_getgrnam(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_getgrnam')) die('skip posix_getgrnam() not found'); +?> +--FILE-- +<?php +echo "Basic test of POSIX posix_getgrnam function\n"; + +var_dump(posix_getgrnam(NULL)); +var_dump(posix_getgrnam(1)); +var_dump(posix_getgrnam('')); + +?> +===DONE=== +--EXPECT-- +Basic test of POSIX posix_getgrnam function +bool(false) +bool(false) +bool(false) +===DONE===
\ No newline at end of file diff --git a/ext/posix/tests/posix_getgroups_basic.phpt b/ext/posix/tests/posix_getgroups_basic.phpt new file mode 100644 index 0000000..f062468 --- /dev/null +++ b/ext/posix/tests/posix_getgroups_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test posix_getgroups() function : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of POSIX getgroups\n"; + + $groups = posix_getgroups(); + + if (!is_array($groups)) { + echo "TEST FAILED - array result expected\n"; + } else { + echo "TEST PASSED\n"; + } + +?> +===DONE=== +--EXPECT-- +Basic test of POSIX getgroups +TEST PASSED +===DONE===
\ No newline at end of file diff --git a/ext/posix/tests/posix_getpgid_basic.phpt b/ext/posix/tests/posix_getpgid_basic.phpt new file mode 100644 index 0000000..3195387 --- /dev/null +++ b/ext/posix/tests/posix_getpgid_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test posix_getpgid() function : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of posix_getpgid function\n"; + + $pid = posix_getpid(); + $pgid = posix_getpgid($pid); + + var_dump($pgid); + +?> +===DONE==== +--EXPECTF-- +Basic test of posix_getpgid function +int(%d) +===DONE==== + +
\ No newline at end of file diff --git a/ext/posix/tests/posix_getpgid_error.phpt b/ext/posix/tests/posix_getpgid_error.phpt new file mode 100644 index 0000000..b15a3c3 --- /dev/null +++ b/ext/posix/tests/posix_getpgid_error.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test posix_getpgid() function : error conditions +--SKIPIF-- +<?php +if((!extension_loaded("posix")) || (!function_exists("posix_getpgid"))) { + print "skip - POSIX extension not loaded or posix_getpgid() does not exist"; +} +?> +--FILE-- +<?php +/* Prototype : proto int posix_getpgid(void) + * Description: Get the process group id of the specified process (This is not a POSIX function, but a SVR4ism, so we compile conditionally) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getpgid() : error conditions ***\n"; + +echo "\n-- Testing posix_getpgid() function no arguments --\n"; +var_dump( posix_getpgid() ); + +echo "\n-- Testing posix_getpgid() with one extra argument --\n"; +$pid = 10; +$extra_arg = 20; +var_dump( posix_getpgid($pid, $extra_arg) ); + +echo "\n-- Testing posix_getpgid() with negative pid --\n"; +$pid = -99; +var_dump( posix_getpgid($pid) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getpgid() : error conditions *** + +-- Testing posix_getpgid() function no arguments -- + +Warning: posix_getpgid() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing posix_getpgid() with one extra argument -- + +Warning: posix_getpgid() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) + +-- Testing posix_getpgid() with negative pid -- +bool(false) +Done diff --git a/ext/posix/tests/posix_getpgid_variation.phpt b/ext/posix/tests/posix_getpgid_variation.phpt new file mode 100644 index 0000000..b9c92b5 --- /dev/null +++ b/ext/posix/tests/posix_getpgid_variation.phpt @@ -0,0 +1,185 @@ +--TEST-- +Test posix_getpgid() function : variation +--SKIPIF-- +<?php +if((!extension_loaded("posix")) || (!function_exists("posix_getpgid"))) { + print "skip - POSIX extension not loaded or posix_getpgid() does not exist"; +} +?> +--FILE-- +<?php +/* Prototype : proto int posix_getpgid(void) + * Description: Get the process group id of the specified process (This is not a POSIX function, but a SVR4ism, so we compile conditionally) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getpgid() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, + + // object data + new stdclass(), +); + +// loop through each element of the array for gid + +foreach($values as $value) { + echo "\nArg value $value \n"; + $result = posix_getpgid($value); + if (is_int($result) || $result === false) { + echo "valid output\n"; + } else { + var_dump($result); + } +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getpgid() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +Arg value 10.5 +valid output + +Arg value -10.5 +valid output + +Arg value 101234567000 +valid output + +Arg value 1.07654321E-9 +valid output + +Arg value 0.5 +valid output + +Notice: Array to string conversion in %sposix_getpgid_variation.php on line %d + +Arg value Array + +Warning: posix_getpgid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getpgid_variation.php on line %d + +Arg value Array + +Warning: posix_getpgid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getpgid_variation.php on line %d + +Arg value Array + +Warning: posix_getpgid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getpgid_variation.php on line %d + +Arg value Array + +Warning: posix_getpgid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getpgid_variation.php on line %d + +Arg value Array + +Warning: posix_getpgid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Arg value +valid output + +Arg value +valid output + +Arg value 1 +valid output + +Arg value +valid output + +Arg value 1 +valid output + +Arg value +valid output + +Arg value + +Warning: posix_getpgid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value + +Warning: posix_getpgid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value string + +Warning: posix_getpgid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value string + +Warning: posix_getpgid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value +valid output + +Arg value +valid output + +Catchable fatal error: Object of class stdClass could not be converted to string in %s on line %d diff --git a/ext/posix/tests/posix_getpgrp_basic.phpt b/ext/posix/tests/posix_getpgrp_basic.phpt new file mode 100644 index 0000000..a737019 --- /dev/null +++ b/ext/posix/tests/posix_getpgrp_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test posix_getpgrp() function : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of POSIX getpgrp function\n"; + + $pgrp = posix_getpgrp(); + + var_dump($pgrp); + +?> +===DONE==== +--EXPECTF-- +Basic test of POSIX getpgrp function +int(%d) +===DONE==== +
\ No newline at end of file diff --git a/ext/posix/tests/posix_getpgrp_error.phpt b/ext/posix/tests/posix_getpgrp_error.phpt new file mode 100644 index 0000000..97f47ce --- /dev/null +++ b/ext/posix/tests/posix_getpgrp_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test posix_getpgrp() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto int posix_getpgrp(void) + * Description: Get current process group id (POSIX.1, 4.3.1) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getpgrp() : error conditions ***\n"; + +// One argument +echo "\n-- Testing posix_getpgrp() function with one argument --\n"; +$extra_arg = 10; +var_dump( posix_getpgrp($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getpgrp() : error conditions *** + +-- Testing posix_getpgrp() function with one argument -- + +Warning: posix_getpgrp() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/posix/tests/posix_getpid_basic.phpt b/ext/posix/tests/posix_getpid_basic.phpt new file mode 100644 index 0000000..a144441 --- /dev/null +++ b/ext/posix/tests/posix_getpid_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test posix_getpid() function : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of POSIX getpid function\n"; + + $pid = posix_getpid(); + + var_dump($pid); + +?> +===DONE==== +--EXPECTF-- +Basic test of POSIX getpid function +int(%d) +===DONE==== +
\ No newline at end of file diff --git a/ext/posix/tests/posix_getpid_error.phpt b/ext/posix/tests/posix_getpid_error.phpt new file mode 100644 index 0000000..721bf66 --- /dev/null +++ b/ext/posix/tests/posix_getpid_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test posix_getpid() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto int posix_getpid(void) + * Description: Get the current process id (POSIX.1, 4.1.1) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getpid() : error conditions ***\n"; + +// One argument +echo "\n-- Testing posix_getpid() function with one argument --\n"; +$extra_arg = 10; +var_dump( posix_getpid($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getpid() : error conditions *** + +-- Testing posix_getpid() function with one argument -- + +Warning: posix_getpid() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/posix/tests/posix_getppid_basic.phpt b/ext/posix/tests/posix_getppid_basic.phpt new file mode 100644 index 0000000..2da591c --- /dev/null +++ b/ext/posix/tests/posix_getppid_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test posix_getppid() function : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of POSIX getppid function\n"; + + $ppid = posix_getppid(); + + var_dump($ppid); + +?> +===DONE==== +--EXPECTF-- +Basic test of POSIX getppid function +int(%d) +===DONE==== +
\ No newline at end of file diff --git a/ext/posix/tests/posix_getppid_error.phpt b/ext/posix/tests/posix_getppid_error.phpt new file mode 100644 index 0000000..366c1ed --- /dev/null +++ b/ext/posix/tests/posix_getppid_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test posix_getppid() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto int posix_getppid(void) + * Description: Get the parent process id (POSIX.1, 4.1.1) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getppid() : error conditions ***\n"; + +// One argument +echo "\n-- Testing posix_getppid() function with one argument --\n"; +$extra_arg = 10; +var_dump( posix_getppid($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getppid() : error conditions *** + +-- Testing posix_getppid() function with one argument -- + +Warning: posix_getppid() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/posix/tests/posix_getpwnam.phpt b/ext/posix/tests/posix_getpwnam.phpt new file mode 100644 index 0000000..b5de1e4 --- /dev/null +++ b/ext/posix/tests/posix_getpwnam.phpt @@ -0,0 +1,19 @@ +--TEST-- +posix_getpwnam(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_getpwnam')) die('skip posix_getpwnam() not found'); +?> +--FILE-- +<?php + +var_dump(posix_getpwnam(1)); +var_dump(posix_getpwnam('')); +var_dump(posix_getpwnam(NULL)); + +?> +--EXPECT-- +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_getpwnam_basic.phpt b/ext/posix/tests/posix_getpwnam_basic.phpt new file mode 100644 index 0000000..d675d6c --- /dev/null +++ b/ext/posix/tests/posix_getpwnam_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +posix_getpwnam(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_getpwnam')) die('skip posix_getpwnam() not found'); +?> +--FILE-- +<?php +echo "Basic test of POSIX posix_getpwnam function\n"; + +var_dump(posix_getpwnam(1)); +var_dump(posix_getpwnam('')); +var_dump(posix_getpwnam(NULL)); + +?> +===DONE==== +--EXPECT-- +Basic test of POSIX posix_getpwnam function +bool(false) +bool(false) +bool(false) +===DONE==== diff --git a/ext/posix/tests/posix_getpwuid_basic.phpt b/ext/posix/tests/posix_getpwuid_basic.phpt new file mode 100644 index 0000000..1bcd59d --- /dev/null +++ b/ext/posix/tests/posix_getpwuid_basic.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test posix_getpwuid() function : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of POSIX getpwuid\n"; + + + $pwuid = posix_getpwuid(posix_getuid()); + + print_r($pwuid); + +?> +===DONE==== +--EXPECTREGEX-- +Basic test of POSIX getpwuid +Array +\( + \[name\] => [^\r\n]+ + \[passwd\] => [^\r\n]+ + \[uid\] => [0-9]+ + \[gid\] => [0-9]+ + \[gecos\] => [^\r\n]* + \[dir\] => [^\r\n]+ + \[shell\] => [^\r\n]+ +\) +===DONE====
\ No newline at end of file diff --git a/ext/posix/tests/posix_getpwuid_error.phpt b/ext/posix/tests/posix_getpwuid_error.phpt new file mode 100644 index 0000000..4920e4e --- /dev/null +++ b/ext/posix/tests/posix_getpwuid_error.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test posix_getpwuid() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto array posix_getpwuid(long uid) + * Description: User database access (POSIX.1, 9.2.2) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getpwuid() : error conditions ***\n"; + +echo "\n-- Testing posix_getpwuid() function with Zero arguments --\n"; +var_dump( posix_getpwuid() ); + +echo "\n-- Testing posix_getpwuid() function with more than expected no. of arguments --\n"; +$uid = posix_getuid(); +$extra_arg = 10; +var_dump( posix_getpwuid($uid, $extra_arg) ); + +echo "\n-- Testing posix_getpwuid() function negative uid --\n"; +$uid = -99; +var_dump( posix_getpwuid($uid) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getpwuid() : error conditions *** + +-- Testing posix_getpwuid() function with Zero arguments -- + +Warning: posix_getpwuid() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing posix_getpwuid() function with more than expected no. of arguments -- + +Warning: posix_getpwuid() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) + +-- Testing posix_getpwuid() function negative uid -- +bool(false) +Done diff --git a/ext/posix/tests/posix_getpwuid_variation.phpt b/ext/posix/tests/posix_getpwuid_variation.phpt new file mode 100644 index 0000000..8b66f7f --- /dev/null +++ b/ext/posix/tests/posix_getpwuid_variation.phpt @@ -0,0 +1,185 @@ +--TEST-- +Test posix_getpwuid() function : usage variations - parameter types +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto array posix_getpwuid(long uid) + * Description: User database access (POSIX.1, 9.2.2) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getpwuid() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, + + // object data + new stdclass(), +); + +// loop through each element of the array for uid + +foreach($values as $value) { + echo "\nArg value $value \n"; + $result = posix_getpwuid($value); + if ((is_array($result) && (count($result) == 7)) + || + ($result === false)) { + echo "valid output\n"; + } else { + var_dump($result); + } +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getpwuid() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +Arg value 10.5 +valid output + +Arg value -10.5 +valid output + +Arg value 101234567000 +valid output + +Arg value 1.07654321E-9 +valid output + +Arg value 0.5 +valid output + +Notice: Array to string conversion in %sposix_getpwuid_variation.php on line %d + +Arg value Array + +Warning: posix_getpwuid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getpwuid_variation.php on line %d + +Arg value Array + +Warning: posix_getpwuid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getpwuid_variation.php on line %d + +Arg value Array + +Warning: posix_getpwuid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getpwuid_variation.php on line %d + +Arg value Array + +Warning: posix_getpwuid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Notice: Array to string conversion in %sposix_getpwuid_variation.php on line %d + +Arg value Array + +Warning: posix_getpwuid() expects parameter 1 to be long, array given in %s on line %d +valid output + +Arg value +valid output + +Arg value +valid output + +Arg value 1 +valid output + +Arg value +valid output + +Arg value 1 +valid output + +Arg value +valid output + +Arg value + +Warning: posix_getpwuid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value + +Warning: posix_getpwuid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value string + +Warning: posix_getpwuid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value string + +Warning: posix_getpwuid() expects parameter 1 to be long, string given in %s on line %d +valid output + +Arg value +valid output + +Arg value +valid output + +Catchable fatal error: Object of class stdClass could not be converted to string in %s on line %d diff --git a/ext/posix/tests/posix_getrlimit.phpt b/ext/posix/tests/posix_getrlimit.phpt new file mode 100644 index 0000000..61da64a --- /dev/null +++ b/ext/posix/tests/posix_getrlimit.phpt @@ -0,0 +1,17 @@ +--TEST-- +posix_getrlimit(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_getrlimit')) die('skip posix_getrlimit() not found'); +?> +--FILE-- +<?php + +var_dump(posix_getrlimit()); + +?> +--EXPECTF-- +array(%d) { +%a +} diff --git a/ext/posix/tests/posix_getrlimit_basic.phpt b/ext/posix/tests/posix_getrlimit_basic.phpt new file mode 100644 index 0000000..7fdd0e7 --- /dev/null +++ b/ext/posix/tests/posix_getrlimit_basic.phpt @@ -0,0 +1,20 @@ +--TEST-- +posix_getrlimit(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_getrlimit')) die('skip posix_getrlimit() not found'); +?> +--FILE-- +<?php +echo "Basic test of POSIX posix_getrlimit function\n"; +var_dump(posix_getrlimit()); + +?> +===DONE==== +--EXPECTF-- +Basic test of POSIX posix_getrlimit function +array(%d) { +%a +} +===DONE====
\ No newline at end of file diff --git a/ext/posix/tests/posix_getsid.phpt b/ext/posix/tests/posix_getsid.phpt new file mode 100644 index 0000000..62ed3c9 --- /dev/null +++ b/ext/posix/tests/posix_getsid.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test posix_getsid() function test +--DESCRIPTION-- +Get the current session id of a process pid (POSIX.1, 4.2.1) +Source code: ext/posix/posix.c +--CREDITS-- +Moritz Neuhaeuser, info@xcompile.net +PHP Testfest Berlin 2009-05-10 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "SKIP - POSIX extension not loaded"; +?> +--FILE-- +<?php +echo "*** Testing posix_getsid() : function test ***\n"; + +$pid = posix_getpid(); +echo "\n-- Testing posix_getsid() function with current process pid --\n"; +var_dump( is_long(posix_getsid($pid)) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing posix_getsid() : function test *** + +-- Testing posix_getsid() function with current process pid -- +bool(true) +===DONE=== diff --git a/ext/posix/tests/posix_getsid_basic.phpt b/ext/posix/tests/posix_getsid_basic.phpt new file mode 100644 index 0000000..a53e1df --- /dev/null +++ b/ext/posix/tests/posix_getsid_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test posix_getsid() function : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of posix_getsid function\n"; + + $pid = posix_getpid(); + $sid = posix_getsid($pid); + + var_dump($sid); + +?> +===DONE==== +--EXPECTF-- +Basic test of posix_getsid function +int(%d) +===DONE==== +
\ No newline at end of file diff --git a/ext/posix/tests/posix_getsid_error.phpt b/ext/posix/tests/posix_getsid_error.phpt new file mode 100644 index 0000000..445bc5a --- /dev/null +++ b/ext/posix/tests/posix_getsid_error.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test posix_getsid() function : error conditions +--DESCRIPTION-- +cases: no params, wrong param, wrong param range +--CREDITS-- +Moritz Neuhaeuser, info@xcompile.net +PHP Testfest Berlin 2009-05-10 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) { + die("SKIP - POSIX extension not loaded"); + } +?> +--FILE-- +<?php +var_dump( posix_getsid() ); +var_dump( posix_getsid(array()) ); +var_dump( posix_getsid(-1) ); +?> +===DONE=== +--EXPECTF-- +Warning: posix_getsid() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +Warning: posix_getsid() expects parameter 1 to be long, array given in %s on line %d +bool(false) +bool(false) +===DONE=== diff --git a/ext/posix/tests/posix_getuid_error.phpt b/ext/posix/tests/posix_getuid_error.phpt new file mode 100644 index 0000000..e759e68 --- /dev/null +++ b/ext/posix/tests/posix_getuid_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test posix_getuid() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto int posix_getuid(void) + * Description: Get the current user id (POSIX.1, 4.2.1) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_getuid() : error conditions ***\n"; + +// One argument +echo "\n-- Testing posix_getuid() function with one argument --\n"; +$extra_arg = 10;; +var_dump( posix_getuid($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_getuid() : error conditions *** + +-- Testing posix_getuid() function with one argument -- + +Warning: posix_getuid() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/posix/tests/posix_initgroups.phpt b/ext/posix/tests/posix_initgroups.phpt new file mode 100644 index 0000000..60121e8 --- /dev/null +++ b/ext/posix/tests/posix_initgroups.phpt @@ -0,0 +1,18 @@ +--TEST-- +posix_initgroups(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_initgroups')) die('skip posix_initgroups() not found'); +?> +--FILE-- +<?php + +var_dump(posix_initgroups('foo', 'bar')); +var_dump(posix_initgroups(NULL, NULL)); + +?> +--EXPECTF-- +Warning: posix_initgroups() expects parameter 2 to be long, string given in %s on line %d +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_initgroups_basic.phpt b/ext/posix/tests/posix_initgroups_basic.phpt new file mode 100644 index 0000000..4a50059 --- /dev/null +++ b/ext/posix/tests/posix_initgroups_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +posix_initgroups(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_initgroups')) die('skip posix_initgroups() not found'); +?> +--FILE-- +<?php +echo "Basic test of POSIX posix_initgroups function\n"; +var_dump(posix_initgroups('foo', 'bar')); +var_dump(posix_initgroups(NULL, NULL)); + +?> +===DONE==== +--EXPECTF-- +Basic test of POSIX posix_initgroups function + +Warning: posix_initgroups() expects parameter 2 to be long, string given in %s on line %d +bool(false) +bool(false) +===DONE==== diff --git a/ext/posix/tests/posix_isatty.phpt b/ext/posix/tests/posix_isatty.phpt new file mode 100644 index 0000000..0b40dd1 --- /dev/null +++ b/ext/posix/tests/posix_isatty.phpt @@ -0,0 +1,15 @@ +--TEST-- +posix_isatty(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_isatty')) die('skip posix_isatty() not found'); +?> +--FILE-- +<?php + +var_dump(posix_isatty(0)); + +?> +--EXPECTF-- +bool(%s) diff --git a/ext/posix/tests/posix_kill_basic.phpt b/ext/posix/tests/posix_kill_basic.phpt new file mode 100644 index 0000000..c995031 --- /dev/null +++ b/ext/posix/tests/posix_kill_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test posix_kill(), posix_get_last_error and posix_strerror() functions : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of POSIX getpgid(), kill(), get_last_error() and strerror() functions\n"; + + // Don't rely on PCNTL extension being around + $SIGKILL = 9; + + // TODO Once we have PS open working beef up this test to create a process and kill it + // for now start at a low pid and find first pid which does not exist. + $pid = 999; + do { + $pid += 1; + $result = shell_exec("ps -p " . $pid); + } while (stripos($result, (string)$pid) != FALSE); + + echo "Kill pid=" . $pid . "\n"; + var_dump(posix_kill($pid,$SIGKILL)); + + $errno = posix_get_last_error(); + + var_dump($errno); + var_dump(posix_strerror($errno)); + +?> +===DONE==== +--EXPECTF-- +Basic test of POSIX getpgid(), kill(), get_last_error() and strerror() functions +Kill pid=%d +bool(false) +int(%d) +string(%d) %sNo such process%s +===DONE==== +
\ No newline at end of file diff --git a/ext/posix/tests/posix_kill_error.phpt b/ext/posix/tests/posix_kill_error.phpt new file mode 100644 index 0000000..082b21d --- /dev/null +++ b/ext/posix/tests/posix_kill_error.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test posix_kill() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto bool posix_kill(int pid, int sig) + * Description: Send a signal to a process (POSIX.1, 3.3.2) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + + +echo "*** Testing posix_kill() : error conditions ***\n"; + + +echo "\n-- Testing posix_kill() function with more than expected no. of arguments --\n"; +$pid = posix_getpid(); +$sig = 9; +$extra_arg = 10; +var_dump( posix_kill($pid, $sig, $extra_arg) ); + +echo "\n-- Testing posix_kill() function with less than expected no. of arguments --\n"; +$pid = posix_getpid(); +var_dump( posix_kill($pid) ); + +echo "\n-- Testing posix_kill() function with invalid signal --\n"; +$pid = posix_getpid(); +$sig = 999; +var_dump( posix_kill($pid, 999) ); + +echo "\n-- Testing posix_kill() function with negative pid --\n"; +$pid = -999; +$sig = 9; +var_dump( posix_kill($pid, 999) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_kill() : error conditions *** + +-- Testing posix_kill() function with more than expected no. of arguments -- + +Warning: posix_kill() expects exactly 2 parameters, 3 given in %s on line %d +bool(false) + +-- Testing posix_kill() function with less than expected no. of arguments -- + +Warning: posix_kill() expects exactly 2 parameters, 1 given in %s on line %d +bool(false) + +-- Testing posix_kill() function with invalid signal -- +bool(false) + +-- Testing posix_kill() function with negative pid -- +bool(false) +Done diff --git a/ext/posix/tests/posix_kill_variation1.phpt b/ext/posix/tests/posix_kill_variation1.phpt new file mode 100644 index 0000000..230977a --- /dev/null +++ b/ext/posix/tests/posix_kill_variation1.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test posix_kill() function : usage variations - first parameter type +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto bool posix_kill(int pid, int sig) + * Description: Send a signal to a process (POSIX.1, 3.3.2) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_kill() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$sig = -999; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, + + // object data + new stdclass(), +); + +// loop through each element of the array for pid + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( posix_kill($value, $sig) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_kill() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Notice: Array to string conversion in %sposix_kill_variation1.php on line %d + +Arg value Array + +Warning: posix_kill() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Notice: Array to string conversion in %sposix_kill_variation1.php on line %d + +Arg value Array + +Warning: posix_kill() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Notice: Array to string conversion in %sposix_kill_variation1.php on line %d + +Arg value Array + +Warning: posix_kill() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Notice: Array to string conversion in %sposix_kill_variation1.php on line %d + +Arg value Array + +Warning: posix_kill() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Notice: Array to string conversion in %sposix_kill_variation1.php on line %d + +Arg value Array + +Warning: posix_kill() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value + +Warning: posix_kill() expects parameter 1 to be long, string given in %s on line %d +bool(false) + +Arg value + +Warning: posix_kill() expects parameter 1 to be long, string given in %s on line %d +bool(false) + +Arg value string + +Warning: posix_kill() expects parameter 1 to be long, string given in %s on line %d +bool(false) + +Arg value string + +Warning: posix_kill() expects parameter 1 to be long, string given in %s on line %d +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Catchable fatal error: Object of class stdClass could not be converted to string in %s on line %d diff --git a/ext/posix/tests/posix_kill_variation2.phpt b/ext/posix/tests/posix_kill_variation2.phpt new file mode 100644 index 0000000..c03ead9 --- /dev/null +++ b/ext/posix/tests/posix_kill_variation2.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test posix_kill() function : usage variations - second parameter type +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto bool posix_kill(int pid, int sig) + * Description: Send a signal to a process (POSIX.1, 3.3.2) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_kill() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pid = -999; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, + + // object data + new stdclass(), +); + +// loop through each element of the array for sig + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( posix_kill($pid, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_kill() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Notice: Array to string conversion in %sposix_kill_variation2.php on line %d + +Arg value Array + +Warning: posix_kill() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +Notice: Array to string conversion in %sposix_kill_variation2.php on line %d + +Arg value Array + +Warning: posix_kill() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +Notice: Array to string conversion in %sposix_kill_variation2.php on line %d + +Arg value Array + +Warning: posix_kill() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +Notice: Array to string conversion in %sposix_kill_variation2.php on line %d + +Arg value Array + +Warning: posix_kill() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +Notice: Array to string conversion in %sposix_kill_variation2.php on line %d + +Arg value Array + +Warning: posix_kill() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value + +Warning: posix_kill() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +Arg value + +Warning: posix_kill() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +Arg value string + +Warning: posix_kill() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +Arg value string + +Warning: posix_kill() expects parameter 2 to be long, string given in %s on line %d +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Catchable fatal error: Object of class stdClass could not be converted to string in %s on line %d diff --git a/ext/posix/tests/posix_mkfifo_safemode.phpt b/ext/posix/tests/posix_mkfifo_safemode.phpt new file mode 100644 index 0000000..1126c00 --- /dev/null +++ b/ext/posix/tests/posix_mkfifo_safemode.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test posix_mkfifo() with safe_mode. +--DESCRIPTION-- +The test attempts to enable safe_mode, catches all the relevant E_WARNING's and tries to create a fifo in /tmp. + +The first attempt (writing to /tmp) should effectively fail because /tmp is owned by root. + +The second attempt (writing to a local created file) works. +--CREDITS-- +Till Klampaeckel, till@php.net +TestFest Berlin 2009 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +if (posix_geteuid() == 0) { + die('SKIP Cannot run test as root.'); +} +if (PHP_VERSION_ID < 503099) { + die('SKIP Safe mode is no longer available.'); +} +?> +--FILE-- +<?php +var_dump(posix_mkfifo('/tmp/foobar', 0644)); + +$dir = dirname(__FILE__) . '/foo'; +mkdir ($dir); +var_dump(posix_mkfifo($dir . '/bar', 0644)); +?> +===DONE=== +--CLEAN-- +<?php +$dir = dirname(__FILE__) . '/foo'; +unlink($dir . '/bar'); +rmdir($dir); +?> +--EXPECTF-- +Deprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in %s on line %d + +Warning: posix_mkfifo(): SAFE MODE Restriction in effect. The script whose uid is %d is not allowed to access /tmp owned by uid %d in %s on line %d +bool(false) +bool(true) +===DONE=== diff --git a/ext/posix/tests/posix_mkfifo_wrongparams.phpt b/ext/posix/tests/posix_mkfifo_wrongparams.phpt new file mode 100644 index 0000000..0d4df7b --- /dev/null +++ b/ext/posix/tests/posix_mkfifo_wrongparams.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test parameter validation in posix_mkfifo(). +--CREDITS-- +Till Klampaeckel, till@php.net +TestFest Berlin 2009 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +?> +--FILE-- +<?php +posix_mkfifo(null); +var_dump(posix_mkfifo(null, 0644)); +?> +===DONE=== +--EXPECTF-- +Warning: posix_mkfifo() expects exactly 2 parameters, 1 given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/posix/tests/posix_mknod.phpt b/ext/posix/tests/posix_mknod.phpt new file mode 100644 index 0000000..4044fb9 --- /dev/null +++ b/ext/posix/tests/posix_mknod.phpt @@ -0,0 +1,15 @@ +--TEST-- +posix_mknod(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_mknod')) die('skip posix_mknod() not found'); +?> +--FILE-- +<?php + +var_dump(posix_mknod(NULL, NULL, NULL, NULL)); + +?> +--EXPECT-- +bool(false) diff --git a/ext/posix/tests/posix_mknod_basic.phpt b/ext/posix/tests/posix_mknod_basic.phpt new file mode 100644 index 0000000..bc35156 --- /dev/null +++ b/ext/posix/tests/posix_mknod_basic.phpt @@ -0,0 +1,18 @@ +--TEST-- +posix_mknod(): Basic tests +--SKIPIF-- +<?php +if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +if (!function_exists('posix_mknod')) die('skip posix_mknod() not found'); +?> +--FILE-- +<?php +echo "Basic test of POSIX posix_mknod function\n"; +var_dump(posix_mknod(NULL, NULL, NULL, NULL)); + +?> +===DONE==== +--EXPECT-- +Basic test of POSIX posix_mknod function +bool(false) +===DONE====
\ No newline at end of file diff --git a/ext/posix/tests/posix_seteuid_basic.phpt b/ext/posix/tests/posix_seteuid_basic.phpt new file mode 100644 index 0000000..204ebe8 --- /dev/null +++ b/ext/posix/tests/posix_seteuid_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test function posix_seteuid() by calling it with its expected arguments +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php + +$myuid = posix_geteuid(); +$uid = var_dump(posix_seteuid( $myuid ) ); + +?> +--EXPECTF-- +bool(true) diff --git a/ext/posix/tests/posix_seteuid_error.phpt b/ext/posix/tests/posix_seteuid_error.phpt new file mode 100644 index 0000000..b10e410 --- /dev/null +++ b/ext/posix/tests/posix_seteuid_error.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test function posix_seteuid() by calling it more than or less than its expected arguments +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test by calling method or function with incorrect numbers of arguments ***\n"; + +$uid = '123'; +$extra_arg = '12312'; + +var_dump(posix_seteuid( $uid, $extra_arg ) ); +var_dump(posix_seteuid( ) ); + + +?> +--EXPECTF-- +*** Test by calling method or function with incorrect numbers of arguments *** + +Warning: posix_seteuid() expects exactly 1 parameter, 2 given in %s on line 9 +bool(false) + +Warning: posix_seteuid() expects exactly 1 parameter, 0 given in %s on line 10 +bool(false) diff --git a/ext/posix/tests/posix_seteuid_error2.phpt b/ext/posix/tests/posix_seteuid_error2.phpt new file mode 100644 index 0000000..808f2d3 --- /dev/null +++ b/ext/posix/tests/posix_seteuid_error2.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test function posix_seteuid() by substituting argument 1 with object values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with object values ***\n"; + + + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + + + +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +$variation_array = array( + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_seteuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with object values *** +Error: 2 - posix_seteuid() expects parameter 1 to be long, object given, %s +bool(false) +Error: 2 - posix_seteuid() expects parameter 1 to be long, object given, %s +bool(false) diff --git a/ext/posix/tests/posix_seteuid_variation1.phpt b/ext/posix/tests/posix_seteuid_variation1.phpt new file mode 100644 index 0000000..841bfe0 --- /dev/null +++ b/ext/posix/tests/posix_seteuid_variation1.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test function posix_seteuid() by substituting argument 1 with array values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + +$index_array = array(1, 2, 3); +$assoc_array = array(1 => 'one', 2 => 'two'); + +$variation_array = array( + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_seteuid( $var ) ); +} + +?> +--EXPECTF-- +Warning: posix_seteuid() expects parameter 1 to be long, array given in %s on line 15 +bool(false) + +Warning: posix_seteuid() expects parameter 1 to be long, array given in %s on line 15 +bool(false) + +Warning: posix_seteuid() expects parameter 1 to be long, array given in %s on line 15 +bool(false) + +Warning: posix_seteuid() expects parameter 1 to be long, array given in %s on line 15 +bool(false) diff --git a/ext/posix/tests/posix_seteuid_variation2.phpt b/ext/posix/tests/posix_seteuid_variation2.phpt new file mode 100644 index 0000000..bcba394 --- /dev/null +++ b/ext/posix/tests/posix_seteuid_variation2.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test function posix_seteuid() by substituting argument 1 with boolean values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with boolean values ***\n"; + + + +$variation_array = array( + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_seteuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with boolean values *** +bool(false) +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_seteuid_variation3.phpt b/ext/posix/tests/posix_seteuid_variation3.phpt new file mode 100644 index 0000000..8b57864 --- /dev/null +++ b/ext/posix/tests/posix_seteuid_variation3.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test function posix_seteuid() by substituting argument 1 with emptyUnsetUndefNull values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with emptyUnsetUndefNull values ***\n"; + + + +$unset_var = 10; +unset($unset_var); + +$variation_array = array( + 'unset var' => @$unset_var, + 'undefined var' => @$undefined_var, + 'empty string DQ' => "", + 'empty string SQ' => '', + 'uppercase NULL' => NULL, + 'lowercase null' => null, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_seteuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with emptyUnsetUndefNull values *** +bool(false) +bool(false) + +Warning: posix_seteuid() expects parameter 1 to be long, string given in %s on line 22 +bool(false) + +Warning: posix_seteuid() expects parameter 1 to be long, string given in %s on line 22 +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_seteuid_variation4.phpt b/ext/posix/tests/posix_seteuid_variation4.phpt new file mode 100644 index 0000000..a647328 --- /dev/null +++ b/ext/posix/tests/posix_seteuid_variation4.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test function posix_seteuid() by substituting argument 1 with float values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with float values ***\n"; + +$myUid = posix_getuid(); + +$myUid = $myUid - 1.1; + +$variation_array = array( + 'float '.$myUid => $myUid, + 'float -'.$myUid => -$myUid, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_seteuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with float values *** +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_seteuid_variation5.phpt b/ext/posix/tests/posix_seteuid_variation5.phpt new file mode 100644 index 0000000..8e43e1a --- /dev/null +++ b/ext/posix/tests/posix_seteuid_variation5.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test function posix_seteuid() by substituting argument 1 with int values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with int values ***\n"; + + + +$variation_array = array ( + 'int 0' => 0, + 'int 1' => 1, + 'int -12345' => -12345, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_seteuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with int values *** +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_seteuid_variation6.phpt b/ext/posix/tests/posix_seteuid_variation6.phpt new file mode 100644 index 0000000..65ff56b --- /dev/null +++ b/ext/posix/tests/posix_seteuid_variation6.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test function posix_seteuid() by substituting argument 1 with string values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with string values ***\n"; + + + +$heredoc = <<<EOT +hello world +EOT; + +$variation_array = array( + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_seteuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with string values *** + +Warning: posix_seteuid() expects parameter 1 to be long, string given in %s on line 21 +bool(false) + +Warning: posix_seteuid() expects parameter 1 to be long, string given in %s on line 21 +bool(false) + +Warning: posix_seteuid() expects parameter 1 to be long, string given in %s on line 21 +bool(false) + +Warning: posix_seteuid() expects parameter 1 to be long, string given in %s on line 21 +bool(false) diff --git a/ext/posix/tests/posix_setgid_basic.phpt b/ext/posix/tests/posix_setgid_basic.phpt new file mode 100644 index 0000000..da3751f --- /dev/null +++ b/ext/posix/tests/posix_setgid_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test function posix_setgid() by calling it with its expected arguments +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test by calling method or function with its expected arguments ***\n"; + +$gid = posix_getgid(); +var_dump(posix_setgid( $gid ) ); + + +?> +===DONE=== +--EXPECTF-- +*** Test by calling method or function with its expected arguments *** +bool(true) +===DONE=== +
\ No newline at end of file diff --git a/ext/posix/tests/posix_setgid_error.phpt b/ext/posix/tests/posix_setgid_error.phpt new file mode 100644 index 0000000..83d727c --- /dev/null +++ b/ext/posix/tests/posix_setgid_error.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test function posix_setgid() by calling it more than or less than its expected arguments. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test by calling method or function with incorrect numbers of arguments ***\n"; + +$gid = posix_getgid(); +$extra_arg = '123'; + +var_dump(posix_setgid( $gid, $extra_arg ) ); +var_dump(posix_setgid( ) ); + +?> +===DONE=== +--EXPECTF-- +*** Test by calling method or function with incorrect numbers of arguments *** + +Warning: posix_setgid() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) + +Warning: posix_setgid() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/posix/tests/posix_setgid_variation1.phpt b/ext/posix/tests/posix_setgid_variation1.phpt new file mode 100644 index 0000000..3690a77 --- /dev/null +++ b/ext/posix/tests/posix_setgid_variation1.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test function posix_setgid() by substituting argument 1 with array values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with array values ***\n"; + +$index_array = array(1, 2, 3); +$assoc_array = array(1 => 'one', 2 => 'two'); + +$variation_array = array( + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setgid( $var ) ); +} +?> +===DONE=== +--EXPECTF-- +*** Test substituting argument 1 with array values *** + +Warning: posix_setgid() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Warning: posix_setgid() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Warning: posix_setgid() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +Warning: posix_setgid() expects parameter 1 to be long, array given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/posix/tests/posix_setgid_variation2.phpt b/ext/posix/tests/posix_setgid_variation2.phpt new file mode 100644 index 0000000..b8e50ba --- /dev/null +++ b/ext/posix/tests/posix_setgid_variation2.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test function posix_setgid() by substituting argument 1 with boolean values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with boolean values ***\n"; + + + +$variation_array = array( + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setgid( $var ) ); +} +?> +===DONE=== +--EXPECTF-- +*** Test substituting argument 1 with boolean values *** +bool(false) +bool(false) +bool(false) +bool(false) +===DONE=== + diff --git a/ext/posix/tests/posix_setgid_variation3.phpt b/ext/posix/tests/posix_setgid_variation3.phpt new file mode 100644 index 0000000..cb9da62 --- /dev/null +++ b/ext/posix/tests/posix_setgid_variation3.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test function posix_setgid() by substituting argument 1 with emptyUnsetUndefNull values. +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with emptyUnsetUndefNull values ***\n"; + + + +$unset_var = 10; +unset($unset_var); + +$variation_array = array( + 'unset var' => @$unset_var, + 'undefined var' => @$undefined_var, + 'empty string DQ' => "", + 'empty string SQ' => '', + 'uppercase NULL' => NULL, + 'lowercase null' => null, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setgid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with emptyUnsetUndefNull values *** +bool(false) +bool(false) + +Warning: posix_setgid() expects parameter 1 to be long, string given in %s on line %d +bool(false) + +Warning: posix_setgid() expects parameter 1 to be long, string given in %s on line %d +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_setgid_variation4.phpt b/ext/posix/tests/posix_setgid_variation4.phpt new file mode 100644 index 0000000..faae4d4 --- /dev/null +++ b/ext/posix/tests/posix_setgid_variation4.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test function posix_setgid() by substituting argument 1 with float values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with float values ***\n"; + + + +$variation_array = array( + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setgid( $var ) ); +} +?> +===DONE=== +--EXPECTF-- +*** Test substituting argument 1 with float values *** +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +===DONE=== + diff --git a/ext/posix/tests/posix_setgid_variation5.phpt b/ext/posix/tests/posix_setgid_variation5.phpt new file mode 100644 index 0000000..49e98ec --- /dev/null +++ b/ext/posix/tests/posix_setgid_variation5.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test function posix_setgid() by substituting argument 1 with int values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with int values ***\n"; + + + +$variation_array = array ( + 'long 0' => 0, + 'long 1' => 1, + 'int -12345' => -2345, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setgid( $var ) ); +} +?> +===DONE=== +--EXPECTF-- +*** Test substituting argument 1 with int values *** +bool(false) +bool(false) +bool(false) +===DONE=== + diff --git a/ext/posix/tests/posix_setgid_variation6.phpt b/ext/posix/tests/posix_setgid_variation6.phpt new file mode 100644 index 0000000..8557fd2 --- /dev/null +++ b/ext/posix/tests/posix_setgid_variation6.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test function posix_setgid() by substituting argument 1 with object values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with object values ***\n"; + + + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + + + +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +$variation_array = array( + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setgid( $var ) ); +} +?> +===DONE=== +--EXPECTF-- +*** Test substituting argument 1 with object values *** +Error: 2 - posix_setgid() expects parameter 1 to be long, object given, %s +bool(false) +Error: 2 - posix_setgid() expects parameter 1 to be long, object given, %s +bool(false) +===DONE=== +
\ No newline at end of file diff --git a/ext/posix/tests/posix_setgid_variation7.phpt b/ext/posix/tests/posix_setgid_variation7.phpt new file mode 100644 index 0000000..f8083c3 --- /dev/null +++ b/ext/posix/tests/posix_setgid_variation7.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test function posix_setgid() by substituting argument 1 with string values. +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with string values ***\n"; + + + +$heredoc = <<<EOT +hello world +EOT; + +$variation_array = array( + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setgid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with string values *** + +Warning: posix_setgid() expects parameter 1 to be long, string given in %s on line %d +bool(false) + +Warning: posix_setgid() expects parameter 1 to be long, string given in %s on line %d +bool(false) + +Warning: posix_setgid() expects parameter 1 to be long, string given in %s on line %d +bool(false) + +Warning: posix_setgid() expects parameter 1 to be long, string given in %s on line %d +bool(false) diff --git a/ext/posix/tests/posix_setuid_basic.phpt b/ext/posix/tests/posix_setuid_basic.phpt new file mode 100644 index 0000000..986b0be --- /dev/null +++ b/ext/posix/tests/posix_setuid_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test function posix_setuid() by calling it with its expected arguments +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php + +$myuid = posix_getuid(); +$uid = var_dump(posix_setuid( $myuid ) ); + +?> +--EXPECTF-- +bool(true) diff --git a/ext/posix/tests/posix_setuid_error.phpt b/ext/posix/tests/posix_setuid_error.phpt new file mode 100644 index 0000000..8aa5158 --- /dev/null +++ b/ext/posix/tests/posix_setuid_error.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test function posix_setuid() by calling it more than or less than its expected arguments +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test by calling method or function with incorrect numbers of arguments ***\n"; + +$uid = '123'; + + +$extra_arg = '12312'; + +var_dump(posix_setuid( $uid, $extra_arg ) ); + +var_dump(posix_setuid( ) ); + + +?> +--EXPECTF-- +*** Test by calling method or function with incorrect numbers of arguments *** + +Warning: posix_setuid() expects exactly 1 parameter, 2 given in %s on line 11 +bool(false) + +Warning: posix_setuid() expects exactly 1 parameter, 0 given in %s on line 13 +bool(false) diff --git a/ext/posix/tests/posix_setuid_error2.phpt b/ext/posix/tests/posix_setuid_error2.phpt new file mode 100644 index 0000000..6ec0aa9 --- /dev/null +++ b/ext/posix/tests/posix_setuid_error2.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test function posix_setuid() by substituting argument 1 with object values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with object values ***\n"; + + + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + + + +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +$variation_array = array( + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with object values *** +Error: 2 - posix_setuid() expects parameter 1 to be long, object given, %s +bool(false) +Error: 2 - posix_setuid() expects parameter 1 to be long, object given, %s +bool(false) diff --git a/ext/posix/tests/posix_setuid_variation1.phpt b/ext/posix/tests/posix_setuid_variation1.phpt new file mode 100644 index 0000000..bf6d437 --- /dev/null +++ b/ext/posix/tests/posix_setuid_variation1.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test function posix_setuid() by substituting argument 1 with array values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + +$index_array = array(1, 2, 3); +$assoc_array = array(1 => 'one', 2 => 'two'); + +$variation_array = array( + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setuid( $var ) ); +} + +?> +--EXPECTF-- +Warning: posix_setuid() expects parameter 1 to be long, array given in %s on line 15 +bool(false) + +Warning: posix_setuid() expects parameter 1 to be long, array given in %s on line 15 +bool(false) + +Warning: posix_setuid() expects parameter 1 to be long, array given in %s on line 15 +bool(false) + +Warning: posix_setuid() expects parameter 1 to be long, array given in %s on line 15 +bool(false) diff --git a/ext/posix/tests/posix_setuid_variation2.phpt b/ext/posix/tests/posix_setuid_variation2.phpt new file mode 100644 index 0000000..77505a6 --- /dev/null +++ b/ext/posix/tests/posix_setuid_variation2.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test function posix_setuid() by substituting argument 1 with boolean values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with boolean values ***\n"; + + + +$variation_array = array( + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with boolean values *** +bool(false) +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_setuid_variation3.phpt b/ext/posix/tests/posix_setuid_variation3.phpt new file mode 100644 index 0000000..4957229 --- /dev/null +++ b/ext/posix/tests/posix_setuid_variation3.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test function posix_setuid() by substituting argument 1 with emptyUnsetUndefNull values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with emptyUnsetUndefNull values ***\n"; + + + +$unset_var = 10; +unset($unset_var); + +$variation_array = array( + 'unset var' => @$unset_var, + 'undefined var' => @$undefined_var, + 'empty string DQ' => "", + 'empty string SQ' => '', + 'uppercase NULL' => NULL, + 'lowercase null' => null, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with emptyUnsetUndefNull values *** +bool(false) +bool(false) + +Warning: posix_setuid() expects parameter 1 to be long, string given in %s on line 22 +bool(false) + +Warning: posix_setuid() expects parameter 1 to be long, string given in %s on line 22 +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_setuid_variation4.phpt b/ext/posix/tests/posix_setuid_variation4.phpt new file mode 100644 index 0000000..288ac0d --- /dev/null +++ b/ext/posix/tests/posix_setuid_variation4.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test function posix_setuid() by substituting argument 1 with float values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with float values ***\n"; + +$myUid = posix_getuid(); + +$myUid = $myUid - 1.1; + +$variation_array = array( + 'float '.$myUid => $myUid, + 'float -'.$myUid => -$myUid, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with float values *** +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_setuid_variation5.phpt b/ext/posix/tests/posix_setuid_variation5.phpt new file mode 100644 index 0000000..a4ebe63 --- /dev/null +++ b/ext/posix/tests/posix_setuid_variation5.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test function posix_setuid() by substituting argument 1 with int values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; + if(posix_geteuid() == 0) print "skip - Cannot run test as root."; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with int values ***\n"; + + + +$variation_array = array ( + 'int 0' => 0, + 'int 1' => 1, + 'int -12345' => -12345, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with int values *** +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_setuid_variation6.phpt b/ext/posix/tests/posix_setuid_variation6.phpt new file mode 100644 index 0000000..79e614f --- /dev/null +++ b/ext/posix/tests/posix_setuid_variation6.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test function posix_setuid() by substituting argument 1 with string values. +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with string values ***\n"; + + + +$heredoc = <<<EOT +hello world +EOT; + +$variation_array = array( + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_setuid( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with string values *** + +Warning: posix_setuid() expects parameter 1 to be long, string given in %s on line 21 +bool(false) + +Warning: posix_setuid() expects parameter 1 to be long, string given in %s on line 21 +bool(false) + +Warning: posix_setuid() expects parameter 1 to be long, string given in %s on line 21 +bool(false) + +Warning: posix_setuid() expects parameter 1 to be long, string given in %s on line 21 +bool(false) diff --git a/ext/posix/tests/posix_strerror_error.phpt b/ext/posix/tests/posix_strerror_error.phpt new file mode 100644 index 0000000..3803f46 --- /dev/null +++ b/ext/posix/tests/posix_strerror_error.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test posix_strerror() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto string posix_strerror(int errno) + * Description: Retrieve the system error message associated with the given errno. + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_strerror() : error conditions ***\n"; + +echo "\n-- Testing posix_strerror() function with Zero arguments --\n"; +var_dump( posix_strerror() ); + +echo "\n-- Testing posix_strerror() function with more than expected no. of arguments --\n"; +$errno = posix_get_last_error(); +$extra_arg = 10; +var_dump( posix_strerror($errno, $extra_arg) ); + +echo "\n-- Testing posix_strerror() function with invalid error number --\n"; +$errno = -999; +echo gettype( posix_strerror($errno) )."\n"; + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_strerror() : error conditions *** + +-- Testing posix_strerror() function with Zero arguments -- + +Warning: posix_strerror() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing posix_strerror() function with more than expected no. of arguments -- + +Warning: posix_strerror() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) + +-- Testing posix_strerror() function with invalid error number -- +string +Done diff --git a/ext/posix/tests/posix_strerror_variation1.phpt b/ext/posix/tests/posix_strerror_variation1.phpt new file mode 100644 index 0000000..4d2b526 --- /dev/null +++ b/ext/posix/tests/posix_strerror_variation1.phpt @@ -0,0 +1,178 @@ +--TEST-- +Test posix_strerror() function : usage variations +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto string posix_strerror(int errno) + * Description: Retrieve the system error message associated with the given errno. + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_strerror() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, + + // object data + new stdclass(), +); + +// loop through each element of the array for errno + +foreach($values as $value) { + echo "\nArg value $value \n"; + echo gettype( posix_strerror($value) )."\n"; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_strerror() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +Arg value 10.5 +string + +Arg value -10.5 +string + +Arg value 101234567000 +string + +Arg value 1.07654321E-9 +string + +Arg value 0.5 +string + +Notice: Array to string conversion in %sposix_strerror_variation1.php on line %d + +Arg value Array + +Warning: posix_strerror() expects parameter 1 to be long, array given in %s on line %d +boolean + +Notice: Array to string conversion in %sposix_strerror_variation1.php on line %d + +Arg value Array + +Warning: posix_strerror() expects parameter 1 to be long, array given in %s on line %d +boolean + +Notice: Array to string conversion in %sposix_strerror_variation1.php on line %d + +Arg value Array + +Warning: posix_strerror() expects parameter 1 to be long, array given in %s on line %d +boolean + +Notice: Array to string conversion in %sposix_strerror_variation1.php on line %d + +Arg value Array + +Warning: posix_strerror() expects parameter 1 to be long, array given in %s on line %d +boolean + +Notice: Array to string conversion in %sposix_strerror_variation1.php on line %d + +Arg value Array + +Warning: posix_strerror() expects parameter 1 to be long, array given in %s on line %d +boolean + +Arg value +string + +Arg value +string + +Arg value 1 +string + +Arg value +string + +Arg value 1 +string + +Arg value +string + +Arg value + +Warning: posix_strerror() expects parameter 1 to be long, string given in %s on line %d +boolean + +Arg value + +Warning: posix_strerror() expects parameter 1 to be long, string given in %s on line %d +boolean + +Arg value string + +Warning: posix_strerror() expects parameter 1 to be long, string given in %s on line %d +boolean + +Arg value string + +Warning: posix_strerror() expects parameter 1 to be long, string given in %s on line %d +boolean + +Arg value +string + +Arg value +string + +Catchable fatal error: Object of class stdClass could not be converted to string in %s on line %d diff --git a/ext/posix/tests/posix_times.phpt b/ext/posix/tests/posix_times.phpt new file mode 100644 index 0000000..6ad3407 --- /dev/null +++ b/ext/posix/tests/posix_times.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test posix_times() +--DESCRIPTION-- +Gets information about the current CPU usage. +Source code: ext/posix/posix.c +--CREDITS-- +Falko Menge, mail at falko-menge dot de +PHP Testfest Berlin 2009-05-10 +--SKIPIF-- +<?php + if (!extension_loaded('posix')) { + die('SKIP - POSIX extension not available'); + } +?> +--FILE-- +<?php + var_dump(posix_times()); +?> +===DONE=== +--EXPECTF-- +array(5) { + ["ticks"]=> + int(%i) + ["utime"]=> + int(%d) + ["stime"]=> + int(%d) + ["cutime"]=> + int(%d) + ["cstime"]=> + int(%d) +} +===DONE=== diff --git a/ext/posix/tests/posix_times_basic.phpt b/ext/posix/tests/posix_times_basic.phpt new file mode 100644 index 0000000..5da6434 --- /dev/null +++ b/ext/posix/tests/posix_times_basic.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test posix_times() function : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of POSIX times function\n"; + + $times = posix_times(); + + var_dump($times); + + + if ($times == FALSE) { + $errno= posix_get_last_error(); + var_dump(posix_strerror($errno)); + } + +?> +===DONE==== +--EXPECTF-- +Basic test of POSIX times function +array(5) { + ["ticks"]=> + int(%i) + ["utime"]=> + int(%i) + ["stime"]=> + int(%i) + ["cutime"]=> + int(%i) + ["cstime"]=> + int(%i) +} +===DONE==== diff --git a/ext/posix/tests/posix_times_error.phpt b/ext/posix/tests/posix_times_error.phpt new file mode 100644 index 0000000..2766bc9 --- /dev/null +++ b/ext/posix/tests/posix_times_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test posix_times() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto array posix_times(void) + * Description: Get process times (POSIX.1, 4.5.2) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_times() : error conditions ***\n"; + +// One argument +echo "\n-- Testing posix_times() function with one argument --\n"; +$extra_arg = 10;; +var_dump( posix_times($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_times() : error conditions *** + +-- Testing posix_times() function with one argument -- + +Warning: posix_times() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/posix/tests/posix_ttyname.phpt b/ext/posix/tests/posix_ttyname.phpt new file mode 100644 index 0000000..76dff4e --- /dev/null +++ b/ext/posix/tests/posix_ttyname.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test posix_ttyname() +--DESCRIPTION-- +Gets the absolute path to the current terminal device that is open on a given file descriptor. +Source code: ext/posix/posix.c +--CREDITS-- +Falko Menge, mail at falko-menge dot de +PHP Testfest Berlin 2009-05-10 +--SKIPIF-- +<?php + if (!extension_loaded('posix')) { + die('SKIP - POSIX extension not available'); + } +?> +--FILE-- +<?php + var_dump(posix_ttyname(STDIN)); + var_dump(posix_ttyname(STDERR)); + var_dump(posix_ttyname(STDOUT)); +?> +===DONE=== +--EXPECTF-- +bool(false) +bool(false) +bool(false) +===DONE=== diff --git a/ext/posix/tests/posix_ttyname_error.phpt b/ext/posix/tests/posix_ttyname_error.phpt new file mode 100644 index 0000000..f7b011e --- /dev/null +++ b/ext/posix/tests/posix_ttyname_error.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test function posix_ttyname() by calling it more than or less than its expected arguments +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +?> +--FILE-- +<?php + + +echo "*** Test by calling method or function with incorrect numbers of arguments ***\n"; + +$fd = 'foo'; +$extra_arg = 'bar'; + +var_dump(posix_ttyname( $fd, $extra_arg ) ); + +var_dump(posix_ttyname( ) ); + + +?> +--EXPECTF-- +*** Test by calling method or function with incorrect numbers of arguments *** + +Warning: posix_ttyname() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) + +Warning: posix_ttyname() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) diff --git a/ext/posix/tests/posix_ttyname_error_wrongparams.phpt b/ext/posix/tests/posix_ttyname_error_wrongparams.phpt new file mode 100644 index 0000000..daa487f --- /dev/null +++ b/ext/posix/tests/posix_ttyname_error_wrongparams.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test posix_ttyname() with wrong parameters +--DESCRIPTION-- +Gets the absolute path to the current terminal device that is open on a given file descriptor. +Source code: ext/posix/posix.c +--CREDITS-- +Falko Menge, mail at falko-menge dot de +PHP Testfest Berlin 2009-05-10 +--SKIPIF-- +<?php + if (!extension_loaded('posix')) { + die('SKIP - POSIX extension not available'); + } + if (!extension_loaded('gd')) { + die('SKIP - GD extension not available'); + } + if (!function_exists('imagecreate')) { + die('SKIP - Function imagecreate() not available'); + } +?> +--FILE-- +<?php + var_dump(posix_ttyname()); // param missing + var_dump(posix_ttyname(0)); // param not a ressource + var_dump(posix_ttyname(imagecreate(1, 1))); // wrong resource type +?> +===DONE=== +--EXPECTF-- +Warning: posix_ttyname() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) +bool(false) + +Warning: posix_ttyname(): supplied resource is not a valid stream resource in %s on line %s + +Warning: posix_ttyname(): expects argument 1 to be a valid stream resource in %s on line %d +bool(false) +===DONE=== diff --git a/ext/posix/tests/posix_ttyname_variation1.phpt b/ext/posix/tests/posix_ttyname_variation1.phpt new file mode 100644 index 0000000..efbf64a --- /dev/null +++ b/ext/posix/tests/posix_ttyname_variation1.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test function posix_ttyname() by substituting argument 1 with array values. +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +?> +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with array values ***\n"; + + + +$index_array = array(1, 2, 3); +$assoc_array = array(1 => 'one', 2 => 'two'); + +$variation_array = array( + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_ttyname( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with array values *** +bool(false) +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_ttyname_variation2.phpt b/ext/posix/tests/posix_ttyname_variation2.phpt new file mode 100644 index 0000000..3246142 --- /dev/null +++ b/ext/posix/tests/posix_ttyname_variation2.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test function posix_ttyname() by substituting argument 1 with boolean values. +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +?> +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with boolean values ***\n"; + + + +$variation_array = array( + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_ttyname( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with boolean values *** +bool(false) +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_ttyname_variation3.phpt b/ext/posix/tests/posix_ttyname_variation3.phpt new file mode 100644 index 0000000..a3ebc8c --- /dev/null +++ b/ext/posix/tests/posix_ttyname_variation3.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test function posix_ttyname() by substituting argument 1 with emptyUnsetUndefNull values. +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +?> +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with emptyUnsetUndefNull values ***\n"; + + + +$unset_var = 10; +unset($unset_var); + +$variation_array = array( + 'unset var' => @$unset_var, + 'undefined var' => @$undefined_var, + 'empty string DQ' => "", + 'empty string SQ' => '', + 'uppercase NULL' => NULL, + 'lowercase null' => null, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_ttyname( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with emptyUnsetUndefNull values *** +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_ttyname_variation4.phpt b/ext/posix/tests/posix_ttyname_variation4.phpt new file mode 100644 index 0000000..da99934 --- /dev/null +++ b/ext/posix/tests/posix_ttyname_variation4.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test function posix_ttyname() by substituting argument 1 with float values. +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +?> +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with float values ***\n"; + + + +$variation_array = array( + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_ttyname( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with float values *** +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_ttyname_variation5.phpt b/ext/posix/tests/posix_ttyname_variation5.phpt new file mode 100644 index 0000000..7290f07 --- /dev/null +++ b/ext/posix/tests/posix_ttyname_variation5.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test function posix_ttyname() by substituting argument 1 with int values. +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +?> +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with int values ***\n"; + + + +$variation_array = array ( + 'int 12345' => 12345, + 'int -12345' => -2345, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_ttyname( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with int values *** +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_ttyname_variation6.phpt b/ext/posix/tests/posix_ttyname_variation6.phpt new file mode 100644 index 0000000..eecae67 --- /dev/null +++ b/ext/posix/tests/posix_ttyname_variation6.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test function posix_ttyname() by substituting argument 1 with object values. +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +?> +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with object values ***\n"; + + + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + + + +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +$variation_array = array( + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_ttyname( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with object values *** +Error: 8 - Object of class classWithToString could not be converted to int, %s(%d) +bool(false) +Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d) +bool(false) diff --git a/ext/posix/tests/posix_ttyname_variation7.phpt b/ext/posix/tests/posix_ttyname_variation7.phpt new file mode 100644 index 0000000..8a92ef6 --- /dev/null +++ b/ext/posix/tests/posix_ttyname_variation7.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test function posix_ttyname() by substituting argument 1 with string values. +--CREDITS-- +Marco Fabbri mrfabbri@gmail.com +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--SKIPIF-- +<?php +if (!extension_loaded('posix')) { + die('SKIP The posix extension is not loaded.'); +} +?> +--FILE-- +<?php + + +echo "*** Test substituting argument 1 with string values ***\n"; + + + +$heredoc = <<<EOT +hello world +EOT; + +$variation_array = array( + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + ); + + +foreach ( $variation_array as $var ) { + var_dump(posix_ttyname( $var ) ); +} +?> +--EXPECTF-- +*** Test substituting argument 1 with string values *** +bool(false) +bool(false) +bool(false) +bool(false) diff --git a/ext/posix/tests/posix_uname_basic.phpt b/ext/posix/tests/posix_uname_basic.phpt new file mode 100644 index 0000000..6bd5b10 --- /dev/null +++ b/ext/posix/tests/posix_uname_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test posix_uname() function : basic functionality +--SKIPIF-- +<?php + if (!extension_loaded('posix')) die('skip - POSIX extension not loaded'); +?> +--FILE-- +<?php + echo "Basic test of POSIX uname function\n"; + + $uname = posix_uname(); + unset($uname['domainname']); + print_r($uname); + +?> +===DONE==== +--EXPECTF-- +Basic test of POSIX uname function +Array +( + [sysname] => %s + [nodename] => %s + [release] => %s + [version] => %s + [machine] => %s +) +===DONE==== +
\ No newline at end of file diff --git a/ext/posix/tests/posix_uname_error.phpt b/ext/posix/tests/posix_uname_error.phpt new file mode 100644 index 0000000..4c753fe --- /dev/null +++ b/ext/posix/tests/posix_uname_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test posix_uname() function : error conditions +--SKIPIF-- +<?php + if(!extension_loaded("posix")) print "skip - POSIX extension not loaded"; +?> +--FILE-- +<?php +/* Prototype : proto array posix_uname(void) + * Description: Get system name (POSIX.1, 4.4.1) + * Source code: ext/posix/posix.c + * Alias to functions: + */ + +echo "*** Testing posix_uname() : error conditions ***\n"; + +// One argument +echo "\n-- Testing posix_uname() function with one argument --\n"; +$extra_arg = 10;; +var_dump( posix_uname($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing posix_uname() : error conditions *** + +-- Testing posix_uname() function with one argument -- + +Warning: posix_uname() expects exactly 0 parameters, 1 given in %s on line %d +NULL +Done |