mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
posix adding posix_fpathconf.
follow-up on GH-10238 but with the file descriptor flavor. Close GH-10253
This commit is contained in:
parent
41c0304647
commit
55d19eee49
6 changed files with 66 additions and 1 deletions
1
NEWS
1
NEWS
|
@ -69,6 +69,7 @@ PHP NEWS
|
||||||
- Posix:
|
- Posix:
|
||||||
. Added posix_sysconf. (David Carlier)
|
. Added posix_sysconf. (David Carlier)
|
||||||
. Added posix_pathconf. (David Carlier)
|
. Added posix_pathconf. (David Carlier)
|
||||||
|
. Added posix_fpathconf. (David Carlier)
|
||||||
|
|
||||||
- Random:
|
- Random:
|
||||||
. Added Randomizer::getBytesFromString(). (Joshua Rüsweg)
|
. Added Randomizer::getBytesFromString(). (Joshua Rüsweg)
|
||||||
|
|
|
@ -78,6 +78,7 @@ PHP 8.3 UPGRADE NOTES
|
||||||
- Posix:
|
- Posix:
|
||||||
. Added posix_sysconf call to get runtime informations.
|
. Added posix_sysconf call to get runtime informations.
|
||||||
. Added posix_pathconf call to get configuration value from a directory/file.
|
. Added posix_pathconf call to get configuration value from a directory/file.
|
||||||
|
. Added posix_fpathconf call to get configuration value from a file descriptor.
|
||||||
|
|
||||||
- Random:
|
- Random:
|
||||||
. Added Randomizer::getBytesFromString().
|
. Added Randomizer::getBytesFromString().
|
||||||
|
|
|
@ -1225,3 +1225,35 @@ PHP_FUNCTION(posix_pathconf)
|
||||||
|
|
||||||
RETURN_LONG(ret);
|
RETURN_LONG(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(posix_fpathconf)
|
||||||
|
{
|
||||||
|
zend_long name, ret, fd;
|
||||||
|
zval *z_fd;
|
||||||
|
|
||||||
|
ZEND_PARSE_PARAMETERS_START(2, 2)
|
||||||
|
Z_PARAM_ZVAL(z_fd)
|
||||||
|
Z_PARAM_LONG(name);
|
||||||
|
ZEND_PARSE_PARAMETERS_END();
|
||||||
|
|
||||||
|
if (Z_TYPE_P(z_fd) == IS_RESOURCE) {
|
||||||
|
if (!php_posix_stream_get_fd(z_fd, &fd)) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!zend_parse_arg_long(z_fd, &fd, /* is_null */ false, /* check_null */ false, /* arg_num */ 1)) {
|
||||||
|
zend_argument_type_error(1, "must be of type int|resource, %s given",
|
||||||
|
zend_zval_type_name(z_fd));
|
||||||
|
RETURN_THROWS();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = fpathconf(fd, name);
|
||||||
|
|
||||||
|
if (ret < 0 && errno != 0) {
|
||||||
|
POSIX_G(last_error) = errno;
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_LONG(ret);
|
||||||
|
}
|
||||||
|
|
|
@ -429,3 +429,5 @@ function posix_initgroups(string $username, int $group_id): bool {}
|
||||||
function posix_sysconf(int $conf_id): int {}
|
function posix_sysconf(int $conf_id): int {}
|
||||||
|
|
||||||
function posix_pathconf(string $path, int $name): int|false {}
|
function posix_pathconf(string $path, int $name): int|false {}
|
||||||
|
/** @param resource|int $file_descriptor */
|
||||||
|
function posix_fpathconf($file_descriptor, int $name): int|false {}
|
||||||
|
|
9
ext/posix/posix_arginfo.h
generated
9
ext/posix/posix_arginfo.h
generated
|
@ -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: 68daa5f0b270b307501a785ca6a197ea161a2ded */
|
* Stub hash: b0c74c2ad41d4ae6a624f73109815fc9fe47fd1f */
|
||||||
|
|
||||||
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)
|
||||||
|
@ -169,6 +169,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_pathconf, 0, 2, MAY_BE_LON
|
||||||
ZEND_ARG_TYPE_INFO(0, name, IS_LONG, 0)
|
ZEND_ARG_TYPE_INFO(0, name, IS_LONG, 0)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
|
|
||||||
|
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_fpathconf, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
|
||||||
|
ZEND_ARG_INFO(0, file_descriptor)
|
||||||
|
ZEND_ARG_TYPE_INFO(0, name, IS_LONG, 0)
|
||||||
|
ZEND_END_ARG_INFO()
|
||||||
|
|
||||||
|
|
||||||
ZEND_FUNCTION(posix_kill);
|
ZEND_FUNCTION(posix_kill);
|
||||||
ZEND_FUNCTION(posix_getpid);
|
ZEND_FUNCTION(posix_getpid);
|
||||||
|
@ -234,6 +239,7 @@ ZEND_FUNCTION(posix_initgroups);
|
||||||
#endif
|
#endif
|
||||||
ZEND_FUNCTION(posix_sysconf);
|
ZEND_FUNCTION(posix_sysconf);
|
||||||
ZEND_FUNCTION(posix_pathconf);
|
ZEND_FUNCTION(posix_pathconf);
|
||||||
|
ZEND_FUNCTION(posix_fpathconf);
|
||||||
|
|
||||||
|
|
||||||
static const zend_function_entry ext_functions[] = {
|
static const zend_function_entry ext_functions[] = {
|
||||||
|
@ -302,6 +308,7 @@ static const zend_function_entry ext_functions[] = {
|
||||||
#endif
|
#endif
|
||||||
ZEND_FE(posix_sysconf, arginfo_posix_sysconf)
|
ZEND_FE(posix_sysconf, arginfo_posix_sysconf)
|
||||||
ZEND_FE(posix_pathconf, arginfo_posix_pathconf)
|
ZEND_FE(posix_pathconf, arginfo_posix_pathconf)
|
||||||
|
ZEND_FE(posix_fpathconf, arginfo_posix_fpathconf)
|
||||||
ZEND_FE_END
|
ZEND_FE_END
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
22
ext/posix/tests/posix_fpathconf.phpt
Normal file
22
ext/posix/tests/posix_fpathconf.phpt
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
--TEST--
|
||||||
|
Test posix_fpathconf
|
||||||
|
--EXTENSIONS--
|
||||||
|
posix
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
var_dump(posix_fpathconf(-1, POSIX_PC_PATH_MAX));
|
||||||
|
var_dump(posix_errno() != 0);
|
||||||
|
try {
|
||||||
|
posix_fpathconf("string arg", POSIX_PC_PATH_MAX);
|
||||||
|
} catch (\TypeError $e) {
|
||||||
|
echo $e->getMessage() . "\n";
|
||||||
|
}
|
||||||
|
$fd = fopen(sys_get_temp_dir(), "r");
|
||||||
|
var_dump(posix_fpathconf($fd, POSIX_PC_PATH_MAX));
|
||||||
|
fclose($fd);
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
bool(false)
|
||||||
|
bool(true)
|
||||||
|
posix_fpathconf(): Argument #1 ($file_descriptor) must be of type int|resource, string given
|
||||||
|
int(%d)
|
Loading…
Add table
Add a link
Reference in a new issue