posix add sysconf call.

providing handful of common and most used constants.

Closes GH-9481.
This commit is contained in:
David Carlier 2022-09-04 10:42:22 +01:00
parent 181ac4617b
commit a5a8b5ff7e
4 changed files with 74 additions and 1 deletions

View File

@ -1145,3 +1145,14 @@ PHP_FUNCTION(posix_initgroups)
} }
/* }}} */ /* }}} */
#endif #endif
PHP_FUNCTION(posix_sysconf)
{
zend_long conf_id;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_LONG(conf_id)
ZEND_PARSE_PARAMETERS_END();
RETURN_LONG(sysconf(conf_id));
}

View File

@ -191,6 +191,34 @@ const POSIX_RLIMIT_NPTS = UNKNOWN;
*/ */
const POSIX_RLIMIT_INFINITY = UNKNOWN; const POSIX_RLIMIT_INFINITY = UNKNOWN;
#endif #endif
#ifdef _SC_ARG_MAX
/**
* @var int
* @cvalue _SC_ARG_MAX
*/
const POSIX_SC_ARG_MAX = UNKNOWN;
#endif
#ifdef _SC_PAGESIZE
/**
* @var int
* @cvalue _SC_PAGESIZE
*/
const POSIX_SC_PAGESIZE = UNKNOWN;
#endif
#ifdef _SC_NPROCESSORS_CONF
/**
* @var int
* @cvalue _SC_NPROCESSORS_CONF
*/
const POSIX_SC_NPROCESSORS_CONF = UNKNOWN;
#endif
#ifdef _SC_NPROCESSORS_ONLN
/**
* @var int
* @cvalue _SC_NPROCESSORS_ONLN
*/
const POSIX_SC_NPROCESSORS_ONLN = UNKNOWN;
#endif
function posix_kill(int $process_id, int $signal): bool {} function posix_kill(int $process_id, int $signal): bool {}
@ -327,3 +355,5 @@ function posix_strerror(int $error_code): string {}
#ifdef HAVE_INITGROUPS #ifdef HAVE_INITGROUPS
function posix_initgroups(string $username, int $group_id): bool {} function posix_initgroups(string $username, int $group_id): bool {}
#endif #endif
function posix_sysconf(int $conf_id): int {}

View File

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead. /* This is a generated file, edit the .stub.php file instead.
* Stub hash: e7f501e4ca2c30f6bf52ea5912037c1e59743949 */ * Stub hash: 82454cec6f55336a530c23663efeb7ac71932bba */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_kill, 0, 2, _IS_BOOL, 0) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_kill, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, process_id, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, process_id, IS_LONG, 0)
@ -159,6 +159,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_initgroups, 0, 2, _IS_BOOL
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
#endif #endif
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_sysconf, 0, 1, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, conf_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_FUNCTION(posix_kill); ZEND_FUNCTION(posix_kill);
ZEND_FUNCTION(posix_getpid); ZEND_FUNCTION(posix_getpid);
@ -222,6 +226,7 @@ ZEND_FUNCTION(posix_strerror);
#if defined(HAVE_INITGROUPS) #if defined(HAVE_INITGROUPS)
ZEND_FUNCTION(posix_initgroups); ZEND_FUNCTION(posix_initgroups);
#endif #endif
ZEND_FUNCTION(posix_sysconf);
static const zend_function_entry ext_functions[] = { static const zend_function_entry ext_functions[] = {
@ -288,6 +293,7 @@ static const zend_function_entry ext_functions[] = {
#if defined(HAVE_INITGROUPS) #if defined(HAVE_INITGROUPS)
ZEND_FE(posix_initgroups, arginfo_posix_initgroups) ZEND_FE(posix_initgroups, arginfo_posix_initgroups)
#endif #endif
ZEND_FE(posix_sysconf, arginfo_posix_sysconf)
ZEND_FE_END ZEND_FE_END
}; };
@ -369,4 +375,16 @@ static void register_posix_symbols(int module_number)
#if defined(HAVE_SETRLIMIT) #if defined(HAVE_SETRLIMIT)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_INFINITY", RLIM_INFINITY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("POSIX_RLIMIT_INFINITY", RLIM_INFINITY, CONST_PERSISTENT);
#endif #endif
#if defined(_SC_ARG_MAX)
REGISTER_LONG_CONSTANT("POSIX_SC_ARG_MAX", _SC_ARG_MAX, CONST_PERSISTENT);
#endif
#if defined(_SC_PAGESIZE)
REGISTER_LONG_CONSTANT("POSIX_SC_PAGESIZE", _SC_PAGESIZE, CONST_PERSISTENT);
#endif
#if defined(_SC_NPROCESSORS_CONF)
REGISTER_LONG_CONSTANT("POSIX_SC_NPROCESSORS_CONF", _SC_NPROCESSORS_CONF, CONST_PERSISTENT);
#endif
#if defined(_SC_NPROCESSORS_ONLN)
REGISTER_LONG_CONSTANT("POSIX_SC_NPROCESSORS_ONLN", _SC_NPROCESSORS_ONLN, CONST_PERSISTENT);
#endif
} }

View File

@ -0,0 +1,14 @@
--TEST--
Test posix_sysconf
--EXTENSIONS--
posix
--FILE--
<?php
var_dump(posix_sysconf(-1));
var_dump(posix_errno() != 0);
var_dump(posix_sysconf(POSIX_SC_NPROCESSORS_ONLN));
?>
--EXPECTF--
int(-1)
bool(false)
int(%d)