Skip to content

Commit 33f4725

Browse files
committed
posix adding posix_fpathconf.
follow-up on GH-10238 but with the file descriptor flavor.
1 parent e7c0f4e commit 33f4725

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

ext/posix/posix.c

+32
Original file line numberDiff line numberDiff line change
@@ -1225,3 +1225,35 @@ PHP_FUNCTION(posix_pathconf)
12251225

12261226
RETURN_LONG(ret);
12271227
}
1228+
1229+
PHP_FUNCTION(posix_fpathconf)
1230+
{
1231+
zend_long name, ret, fd;
1232+
zval *z_fd;
1233+
1234+
ZEND_PARSE_PARAMETERS_START(2, 2)
1235+
Z_PARAM_ZVAL(z_fd)
1236+
Z_PARAM_LONG(name);
1237+
ZEND_PARSE_PARAMETERS_END();
1238+
1239+
if (Z_TYPE_P(z_fd) == IS_RESOURCE) {
1240+
if (!php_posix_stream_get_fd(z_fd, &fd)) {
1241+
RETURN_FALSE;
1242+
}
1243+
} else {
1244+
if (!zend_parse_arg_long(z_fd, &fd, /* is_null */ false, /* check_null */ false, /* arg_num */ 1)) {
1245+
zend_argument_type_error(1, "must be of type int/resource, %s given",
1246+
zend_zval_type_name(z_fd));
1247+
RETURN_THROWS();
1248+
}
1249+
}
1250+
1251+
ret = fpathconf(fd, name);
1252+
1253+
if (ret < 0 && errno != 0) {
1254+
POSIX_G(last_error) = errno;
1255+
RETURN_FALSE;
1256+
}
1257+
1258+
RETURN_LONG(ret);
1259+
}

ext/posix/posix.stub.php

+2
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,5 @@ 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+
/** @param resource|int $file_descriptor */
433+
function posix_fpathconf($file_descriptor, int $name): int|false {}

ext/posix/posix_arginfo.h

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/posix/tests/posix_fpathconf.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
try {
10+
posix_fpathconf("string arg", POSIX_PC_PATH_MAX);
11+
} catch (\TypeError $e) {
12+
echo $e->getMessage() . "\n";
13+
}
14+
$fd = fopen(sys_get_temp_dir(), "r");
15+
var_dump(posix_fpathconf($fd, POSIX_PC_PATH_MAX));
16+
fclose($fd);
17+
?>
18+
--EXPECTF--
19+
bool(false)
20+
bool(true)
21+
posix_fpathconf(): Argument #1 ($file_descriptor) must be of type int|resource, string given
22+
int(%d)

0 commit comments

Comments
 (0)