Skip to content

posix adding posix_pathconf. #10238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
72 changes: 72 additions & 0 deletions ext/posix/posix.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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 {}
39 changes: 38 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.

16 changes: 16 additions & 0 deletions ext/posix/tests/posix_pathconf.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Test posix_pathconf
--EXTENSIONS--
posix
--FILE--
<?php
var_dump(posix_pathconf('', POSIX_PC_PATH_MAX));
var_dump(posix_pathconf(str_repeat('non_existent', 4096), POSIX_PC_NAME_MAX));
var_dump(posix_errno() != 0);
var_dump(posix_pathconf(sys_get_temp_dir(), POSIX_PC_PATH_MAX));
?>
--EXPECTF--
bool(false)
bool(false)
bool(true)
int(%d)