Skip to content

Commit 0618fac

Browse files
committed
posix: Add pathconf and fpathconf
These POSIX apis provide for path-dependent limits. Signed-off-by: Keith Packard <[email protected]>
1 parent 5c818bc commit 0618fac

File tree

5 files changed

+177
-0
lines changed

5 files changed

+177
-0
lines changed

newlib/libc/include/sys/syslimits.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,50 @@
5959
#define LINE_MAX 2048 /* max bytes in an input line */
6060
#define RE_DUP_MAX 255 /* max RE's in interval notation */
6161

62+
63+
#define _POSIX_AIO_LISTIO_MAX 2
64+
#define _POSIX_AIO_MAX 1
65+
#define _POSIX_ARG_MAX 4096
66+
#define _POSIX_CHILD_MAX 6
67+
#define _POSIX_DELAYTIMER_MAX 32
68+
#define _POSIX_LINK_MAX 8
69+
#define _POSIX_LOGIN_NAME_MAX 9
70+
#define _POSIX_MAX_CANON 255
71+
#define _POSIX_MAX_INPUT 255
72+
#define _POSIX_MQ_OPEN_MAX 8
73+
#define _POSIX_MQ_PRIO_MAX 32
74+
#define _POSIX_NAME_MAX 14
75+
#define _POSIX_NGROUPS_MAX 0
76+
#define _POSIX_OPEN_MAX 16
77+
#define _POSIX_PATH_MAX 255
78+
#define _POSIX_PIPE_BUF 512
79+
#define _POSIX_RTSIG_MAX 8
80+
#define _POSIX_SEM_NSEMS_MAX 256
81+
#define _POSIX_SEM_VALUE_MAX 32767
82+
#define _POSIX_SIGQUEUE_MAX 32
83+
#define _POSIX_SSIZE_MAX 32767
84+
#define _POSIX_STREAM_MAX 8
85+
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
86+
#define _POSIX_THREAD_KEYS_MAX 128
87+
#define _POSIX_THREAD_THREADS_MAX 64
88+
#define _POSIX_TIMER_MAX 32
89+
#define _POSIX_TTY_NAME_MAX 9
90+
#define _POSIX_TZNAME_MAX 3
91+
#define _POSIX2_BC_BASE_MAX 99
92+
#define _POSIX2_BC_DIM_MAX 2048
93+
#define _POSIX2_BC_SCALE_MAX 99
94+
#define _POSIX2_BC_STRING_MAX 1000
95+
#define _POSIX2_COLL_WEIGHTS_MAX 2
96+
#define _POSIX2_EXPR_NEST_MAX 32
97+
#define _POSIX2_LINE_MAX 2048
98+
#define _POSIX2_RE_DUP_MAX 255
99+
62100
#endif /* __POSIX_VISIBLE */
63101

102+
#ifdef _XOPEN_SOURCE
103+
#define _XOPEN_IOV_MAX 16
104+
#endif
105+
64106
#if __MISC_VISIBLE
65107
#define NSIG_MAX __LONG_WIDTH__ /* max signal number */
66108
#endif

newlib/libc/posix/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ picolibc_sources(
3636
basename.c
3737
dirname.c
3838
fnmatch.c
39+
fpathconf.c
40+
pathconf.c
3941
regcomp.c
4042
regerror.c
4143
regexec.c

newlib/libc/posix/fpathconf.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* SPDX-License-Identifier: BSD-3-Clause
3+
*
4+
* Copyright © 2024 Keith Packard
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above
14+
* copyright notice, this list of conditions and the following
15+
* disclaimer in the documentation and/or other materials provided
16+
* with the distribution.
17+
*
18+
* 3. Neither the name of the copyright holder nor the names of its
19+
* contributors may be used to endorse or promote products derived
20+
* from this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33+
* OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
#define _DEFAULT_SOURCE
37+
#include <unistd.h>
38+
#include <errno.h>
39+
#include <limits.h>
40+
41+
long
42+
fpathconf (int fd, int name)
43+
{
44+
(void) fd;
45+
return pathconf(".", name);
46+
}

newlib/libc/posix/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ srcs_posix = [
3636
'basename.c',
3737
'dirname.c',
3838
'fnmatch.c',
39+
'fpathconf.c',
40+
'pathconf.c',
3941
'regcomp.c',
4042
'regerror.c',
4143
'regexec.c',

newlib/libc/posix/pathconf.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* SPDX-License-Identifier: BSD-3-Clause
3+
*
4+
* Copyright © 2024 Keith Packard
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above
14+
* copyright notice, this list of conditions and the following
15+
* disclaimer in the documentation and/or other materials provided
16+
* with the distribution.
17+
*
18+
* 3. Neither the name of the copyright holder nor the names of its
19+
* contributors may be used to endorse or promote products derived
20+
* from this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33+
* OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
#define _DEFAULT_SOURCE
37+
#include <unistd.h>
38+
#include <errno.h>
39+
#include <limits.h>
40+
41+
long
42+
pathconf (const char *path, int name)
43+
{
44+
(void) path;
45+
switch (name) {
46+
case _PC_LINK_MAX:
47+
return _POSIX_LINK_MAX;
48+
49+
case _PC_MAX_CANON:
50+
return _POSIX_MAX_CANON;
51+
52+
case _PC_MAX_INPUT:
53+
return _POSIX_MAX_INPUT;
54+
55+
case _PC_NAME_MAX:
56+
return _POSIX_NAME_MAX;
57+
58+
case _PC_PATH_MAX:
59+
return _POSIX_PATH_MAX;
60+
61+
case _PC_PIPE_BUF:
62+
return _POSIX_PIPE_BUF;
63+
64+
case _PC_CHOWN_RESTRICTED:
65+
#ifdef _POSIX_CHOWN_RESTRICTED
66+
return _POSIX_CHOWN_RESTRICTED;
67+
#else
68+
return 0;
69+
#endif
70+
71+
case _PC_NO_TRUNC:
72+
#ifdef _POSIX_NO_TRUNC
73+
return _POSIX_NO_TRUNC;
74+
#else
75+
return 0;
76+
#endif
77+
78+
case _PC_VDISABLE:
79+
return 0;
80+
81+
default:
82+
errno = EINVAL;
83+
return -1;
84+
}
85+
}

0 commit comments

Comments
 (0)