Skip to content

Commit

Permalink
posix adding posix_fpathconf.
Browse files Browse the repository at this point in the history
follow-up on GH-10238 but with the file descriptor flavor.

Close GH-10253
  • Loading branch information
devnexen committed Jan 12, 2023
1 parent 41c0304 commit 55d19ee
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ PHP NEWS
- Posix:
. Added posix_sysconf. (David Carlier)
. Added posix_pathconf. (David Carlier)
. Added posix_fpathconf. (David Carlier)

- Random:
. Added Randomizer::getBytesFromString(). (Joshua Rüsweg)
Expand Down
1 change: 1 addition & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ PHP 8.3 UPGRADE NOTES
- Posix:
. Added posix_sysconf call to get runtime informations.
. 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:
. Added Randomizer::getBytesFromString().
Expand Down
32 changes: 32 additions & 0 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,3 +1225,35 @@ PHP_FUNCTION(posix_pathconf)

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);
}
2 changes: 2 additions & 0 deletions ext/posix/posix.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,5 @@ function posix_initgroups(string $username, int $group_id): bool {}
function posix_sysconf(int $conf_id): int {}

function posix_pathconf(string $path, int $name): int|false {}
/** @param resource|int $file_descriptor */
function posix_fpathconf($file_descriptor, int $name): int|false {}
9 changes: 8 additions & 1 deletion ext/posix/posix_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions ext/posix/tests/posix_fpathconf.phpt
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 55d19ee

Please sign in to comment.