diff --git a/ext/posix/posix.c b/ext/posix/posix.c index bfdb0fa4bbc4a..feecfaa119f7d 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -1196,3 +1196,28 @@ PHP_FUNCTION(posix_sysconf) RETURN_LONG(sysconf(conf_id)); } + +PHP_FUNCTION(posix_pathconf) +{ + zend_long name, ret; + char *path; + size_t path_len; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STRING(path, path_len) + Z_PARAM_LONG(name); + ZEND_PARSE_PARAMETERS_END(); + + if (path_len == 0) { + RETURN_FALSE; + } + + ret = pathconf(path, name); + + if (ret < 0 && errno != 0) { + POSIX_G(last_error) = errno; + RETURN_FALSE; + } + + RETURN_LONG(ret); +} diff --git a/ext/posix/posix.stub.php b/ext/posix/posix.stub.php index cc73901444fbb..94caf3cc261eb 100644 --- a/ext/posix/posix.stub.php +++ b/ext/posix/posix.stub.php @@ -219,6 +219,76 @@ */ const POSIX_SC_NPROCESSORS_ONLN = UNKNOWN; #endif +#ifdef _PC_LINK_MAX +/** + * @var int + * @cvalue _PC_LINK_MAX + */ +const POSIX_PC_LINK_MAX = UNKNOWN; +#endif +#ifdef _PC_MAX_CANON +/** + * @var int + * @cvalue _PC_MAX_CANON + */ +const POSIX_PC_MAX_CANON = UNKNOWN; +#endif +#ifdef _PC_MAX_INPUT +/** + * @var int + * @cvalue _PC_MAX_INPUT + */ +const POSIX_PC_MAX_INPUT = UNKNOWN; +#endif +#ifdef _PC_NAME_MAX +/** + * @var int + * @cvalue _PC_NAME_MAX + */ +const POSIX_PC_NAME_MAX = UNKNOWN; +#endif +#ifdef _PC_PATH_MAX +/** + * @var int + * @cvalue _PC_PATH_MAX + */ +const POSIX_PC_PATH_MAX = UNKNOWN; +#endif +#ifdef _PC_PIPE_BUF +/** + * @var int + * @cvalue _PC_PIPE_BUF + */ +const POSIX_PC_PIPE_BUF = UNKNOWN; +#endif +#ifdef _PC_CHOWN_RESTRICTED +/** + * @var int + * @cvalue _PC_CHOWN_RESTRICTED + */ +const POSIX_PC_CHOWN_RESTRICTED = UNKNOWN; +#endif +#ifdef _PC_NO_TRUNC +/** + * @var int + * @cvalue _PC_NO_TRUNC + */ +const POSIX_PC_NO_TRUNC = UNKNOWN; +#endif +#ifdef _PC_ALLOC_SIZE_MIN +/** + * @var int + * @cvalue _PC_ALLOC_SIZE_MIN + */ +const POSIX_PC_ALLOC_SIZE_MIN = UNKNOWN; +#endif +#ifdef _PC_SYMLINK_MAX +/** + * @var int + * @cvalue _PC_SYMLINK_MAX + */ +const POSIX_PC_SYMLINK_MAX = UNKNOWN; +#endif function posix_kill(int $process_id, int $signal): bool {} @@ -357,3 +427,5 @@ function posix_initgroups(string $username, int $group_id): bool {} #endif function posix_sysconf(int $conf_id): int {} + +function posix_pathconf(string $path, int $name): int|false {} diff --git a/ext/posix/posix_arginfo.h b/ext/posix/posix_arginfo.h index bc7f4791ef086..6bbf4ca25dce9 100644 --- a/ext/posix/posix_arginfo.h +++ b/ext/posix/posix_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: a6ba91179f2a7ca3622aed0c28e8431868076567 */ + * Stub hash: 68daa5f0b270b307501a785ca6a197ea161a2ded */ 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) @@ -164,6 +164,11 @@ 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_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_pathconf, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, name, IS_LONG, 0) +ZEND_END_ARG_INFO() + ZEND_FUNCTION(posix_kill); ZEND_FUNCTION(posix_getpid); @@ -228,6 +233,7 @@ ZEND_FUNCTION(posix_strerror); ZEND_FUNCTION(posix_initgroups); #endif ZEND_FUNCTION(posix_sysconf); +ZEND_FUNCTION(posix_pathconf); static const zend_function_entry ext_functions[] = { @@ -295,6 +301,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(posix_initgroups, arginfo_posix_initgroups) #endif ZEND_FE(posix_sysconf, arginfo_posix_sysconf) + ZEND_FE(posix_pathconf, arginfo_posix_pathconf) ZEND_FE_END }; @@ -388,4 +395,34 @@ static void register_posix_symbols(int module_number) #if defined(_SC_NPROCESSORS_ONLN) REGISTER_LONG_CONSTANT("POSIX_SC_NPROCESSORS_ONLN", _SC_NPROCESSORS_ONLN, CONST_PERSISTENT); #endif +#if defined(_PC_LINK_MAX) + REGISTER_LONG_CONSTANT("POSIX_PC_LINK_MAX", _PC_LINK_MAX, CONST_PERSISTENT); +#endif +#if defined(_PC_MAX_CANON) + REGISTER_LONG_CONSTANT("POSIX_PC_MAX_CANON", _PC_MAX_CANON, CONST_PERSISTENT); +#endif +#if defined(_PC_MAX_INPUT) + REGISTER_LONG_CONSTANT("POSIX_PC_MAX_INPUT", _PC_MAX_INPUT, CONST_PERSISTENT); +#endif +#if defined(_PC_NAME_MAX) + REGISTER_LONG_CONSTANT("POSIX_PC_NAME_MAX", _PC_NAME_MAX, CONST_PERSISTENT); +#endif +#if defined(_PC_PATH_MAX) + REGISTER_LONG_CONSTANT("POSIX_PC_PATH_MAX", _PC_PATH_MAX, CONST_PERSISTENT); +#endif +#if defined(_PC_PIPE_BUF) + REGISTER_LONG_CONSTANT("POSIX_PC_PIPE_BUF", _PC_PIPE_BUF, CONST_PERSISTENT); +#endif +#if defined(_PC_CHOWN_RESTRICTED) + REGISTER_LONG_CONSTANT("POSIX_PC_CHOWN_RESTRICTED", _PC_CHOWN_RESTRICTED, CONST_PERSISTENT); +#endif +#if defined(_PC_NO_TRUNC) + REGISTER_LONG_CONSTANT("POSIX_PC_NO_TRUNC", _PC_NO_TRUNC, CONST_PERSISTENT); +#endif +#if defined(_PC_ALLOC_SIZE_MIN) + REGISTER_LONG_CONSTANT("POSIX_PC_ALLOC_SIZE_MIN", _PC_ALLOC_SIZE_MIN, CONST_PERSISTENT); +#endif +#if defined(_PC_SYMLINK_MAX) + REGISTER_LONG_CONSTANT("POSIX_PC_SYMLINK_MAX", _PC_SYMLINK_MAX, CONST_PERSISTENT); +#endif } diff --git a/ext/posix/tests/posix_pathconf.phpt b/ext/posix/tests/posix_pathconf.phpt new file mode 100644 index 0000000000000..7214e32c186ed --- /dev/null +++ b/ext/posix/tests/posix_pathconf.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test posix_pathconf +--EXTENSIONS-- +posix +--FILE-- + +--EXPECTF-- +bool(false) +bool(false) +bool(true) +int(%d)