Skip to content

Commit 69d49e4

Browse files
committedJan 6, 2023
posix adding posix_pathconf.
to get configuration variables from a directory/file. Closes GH-10238.
1 parent 3ab72a4 commit 69d49e4

File tree

6 files changed

+153
-1
lines changed

6 files changed

+153
-1
lines changed
 

‎NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ PHP NEWS
6464

6565
- Posix:
6666
. Added posix_sysconf. (David Carlier)
67+
. Added posix_pathconf. (David Carlier)
6768

6869
- Random:
6970
. Added Randomizer::getBytesFromString(). (Joshua Rüsweg)

‎UPGRADING

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ PHP 8.3 UPGRADE NOTES
7171

7272
- Posix:
7373
. Added posix_sysconf call to get runtime informations.
74+
. Added posix_pathconf call to get configuration value from a directory/file.
7475

7576
- Random:
7677
. Added Randomizer::getBytesFromString().

‎ext/posix/posix.c

+25
Original file line numberDiff line numberDiff line change
@@ -1196,3 +1196,28 @@ PHP_FUNCTION(posix_sysconf)
11961196

11971197
RETURN_LONG(sysconf(conf_id));
11981198
}
1199+
1200+
PHP_FUNCTION(posix_pathconf)
1201+
{
1202+
zend_long name, ret;
1203+
char *path;
1204+
size_t path_len;
1205+
1206+
ZEND_PARSE_PARAMETERS_START(2, 2)
1207+
Z_PARAM_STRING(path, path_len)
1208+
Z_PARAM_LONG(name);
1209+
ZEND_PARSE_PARAMETERS_END();
1210+
1211+
if (path_len == 0) {
1212+
RETURN_FALSE;
1213+
}
1214+
1215+
ret = pathconf(path, name);
1216+
1217+
if (ret < 0 && errno != 0) {
1218+
POSIX_G(last_error) = errno;
1219+
RETURN_FALSE;
1220+
}
1221+
1222+
RETURN_LONG(ret);
1223+
}

‎ext/posix/posix.stub.php

+72
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,76 @@
219219
*/
220220
const POSIX_SC_NPROCESSORS_ONLN = UNKNOWN;
221221
#endif
222+
#ifdef _PC_LINK_MAX
223+
/**
224+
* @var int
225+
* @cvalue _PC_LINK_MAX
226+
*/
227+
const POSIX_PC_LINK_MAX = UNKNOWN;
228+
#endif
229+
#ifdef _PC_MAX_CANON
230+
/**
231+
* @var int
232+
* @cvalue _PC_MAX_CANON
233+
*/
234+
const POSIX_PC_MAX_CANON = UNKNOWN;
235+
#endif
236+
#ifdef _PC_MAX_INPUT
237+
/**
238+
* @var int
239+
* @cvalue _PC_MAX_INPUT
240+
*/
241+
const POSIX_PC_MAX_INPUT = UNKNOWN;
242+
#endif
243+
#ifdef _PC_NAME_MAX
244+
/**
245+
* @var int
246+
* @cvalue _PC_NAME_MAX
247+
*/
248+
const POSIX_PC_NAME_MAX = UNKNOWN;
249+
#endif
250+
#ifdef _PC_PATH_MAX
251+
/**
252+
* @var int
253+
* @cvalue _PC_PATH_MAX
254+
*/
255+
const POSIX_PC_PATH_MAX = UNKNOWN;
256+
#endif
257+
#ifdef _PC_PIPE_BUF
258+
/**
259+
* @var int
260+
* @cvalue _PC_PIPE_BUF
261+
*/
262+
const POSIX_PC_PIPE_BUF = UNKNOWN;
263+
#endif
264+
#ifdef _PC_CHOWN_RESTRICTED
265+
/**
266+
* @var int
267+
* @cvalue _PC_CHOWN_RESTRICTED
268+
*/
269+
const POSIX_PC_CHOWN_RESTRICTED = UNKNOWN;
270+
#endif
271+
#ifdef _PC_NO_TRUNC
272+
/**
273+
* @var int
274+
* @cvalue _PC_NO_TRUNC
275+
*/
276+
const POSIX_PC_NO_TRUNC = UNKNOWN;
277+
#endif
278+
#ifdef _PC_ALLOC_SIZE_MIN
279+
/**
280+
* @var int
281+
* @cvalue _PC_ALLOC_SIZE_MIN
282+
*/
283+
const POSIX_PC_ALLOC_SIZE_MIN = UNKNOWN;
284+
#endif
285+
#ifdef _PC_SYMLINK_MAX
286+
/**
287+
* @var int
288+
* @cvalue _PC_SYMLINK_MAX
289+
*/
290+
const POSIX_PC_SYMLINK_MAX = UNKNOWN;
291+
#endif
222292

223293
function posix_kill(int $process_id, int $signal): bool {}
224294

@@ -357,3 +427,5 @@ function posix_initgroups(string $username, int $group_id): bool {}
357427
#endif
358428

359429
function posix_sysconf(int $conf_id): int {}
430+
431+
function posix_pathconf(string $path, int $name): int|false {}

‎ext/posix/posix_arginfo.h

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

‎ext/posix/tests/posix_pathconf.phpt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Test posix_pathconf
3+
--EXTENSIONS--
4+
posix
5+
--FILE--
6+
<?php
7+
var_dump(posix_pathconf('', POSIX_PC_PATH_MAX));
8+
var_dump(posix_pathconf(str_repeat('non_existent', 4096), POSIX_PC_NAME_MAX));
9+
var_dump(posix_errno() != 0);
10+
var_dump(posix_pathconf(sys_get_temp_dir(), POSIX_PC_PATH_MAX));
11+
?>
12+
--EXPECTF--
13+
bool(false)
14+
bool(false)
15+
bool(true)
16+
int(%d)

0 commit comments

Comments
 (0)
Failed to load comments.