Skip to content

Commit 78f6442

Browse files
committed
posix adding posix_fpathconf.
follow-up on phpGH-10238 but with the file descriptor flavor.
1 parent 1b3e175 commit 78f6442

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

ext/posix/posix.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,3 +1221,35 @@ PHP_FUNCTION(posix_pathconf)
12211221

12221222
RETURN_LONG(ret);
12231223
}
1224+
1225+
PHP_FUNCTION(posix_fpathconf)
1226+
{
1227+
zend_long name, ret, fd;
1228+
zval *z_fd;
1229+
1230+
ZEND_PARSE_PARAMETERS_START(2, 2)
1231+
Z_PARAM_ZVAL(z_fd)
1232+
Z_PARAM_LONG(name);
1233+
ZEND_PARSE_PARAMETERS_END();
1234+
1235+
if (Z_TYPE_P(z_fd) == IS_RESOURCE) {
1236+
if (!php_posix_stream_get_fd(z_fd, &fd)) {
1237+
RETURN_FALSE;
1238+
}
1239+
} else {
1240+
if (!zend_parse_arg_long(z_fd, &fd, /* is_null */ false, /* check_null */ false, /* arg_num */ 1)) {
1241+
php_error_docref(NULL, E_WARNING, "Argument #1 ($file_descriptor) must be of type int|resource, %s given",
1242+
zend_zval_type_name(z_fd));
1243+
fd = zval_get_long(z_fd);
1244+
}
1245+
}
1246+
1247+
ret = fpathconf(fd, name);
1248+
1249+
if (ret < 0 && errno != 0) {
1250+
POSIX_G(last_error) = errno;
1251+
RETURN_FALSE;
1252+
}
1253+
1254+
RETURN_LONG(ret);
1255+
}

ext/posix/posix.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,4 @@ function posix_initgroups(string $username, int $group_id): bool {}
429429
function posix_sysconf(int $conf_id): int {}
430430

431431
function posix_pathconf(string $path, int $name): int|false {}
432+
function posix_fpathconf(int $fd, int $name): int|false {}

ext/posix/posix_arginfo.h

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/posix/tests/posix_fpathconf.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Test posix_fpathconf
3+
--EXTENSIONS--
4+
posix
5+
--FILE--
6+
<?php
7+
var_dump(posix_fpathconf(-1, POSIX_PC_PATH_MAX));
8+
var_dump(posix_errno() != 0);
9+
var_dump(posix_fpathconf(STDERR, POSIX_PC_PATH_MAX));
10+
?>
11+
--EXPECTF--
12+
bool(false)
13+
bool(true)
14+
int(%d)

0 commit comments

Comments
 (0)