Skip to content

Commit 9a7563b

Browse files
committed
posix: unistd: support for confstr()
Support querying POSIX string configuration values (similar to sysconf()). confstr() is required by the POSIX_SINGLE_PROCESS Option Group as detailed in Section E.1 of IEEE-1003.1-2017 and has been part of the specification since POSIX-2. The POSIX_SINGLE_PROCESS Option Group is required for PSE51, PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory for any POSIX conforming system as per Section A.2.1.3 of IEEE-1003-1.2017. With this, we have complete support for the POSIX_SINGLE_PROCESS Option Group. Signed-off-by: Christopher Friedt <[email protected]>
1 parent ddb147d commit 9a7563b

File tree

6 files changed

+87
-0
lines changed

6 files changed

+87
-0
lines changed

include/zephyr/posix/sys/confstr.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2024, Meta
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_CONFSTR_H_
7+
#define ZEPHYR_INCLUDE_POSIX_SYS_CONFSTR_H_
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
enum {
14+
_CS_PATH,
15+
_CS_POSIX_V7_ILP32_OFF32_CFLAGS,
16+
_CS_POSIX_V7_ILP32_OFF32_LDFLAGS,
17+
_CS_POSIX_V7_ILP32_OFF32_LIBS,
18+
_CS_POSIX_V7_ILP32_OFFBIG_CFLAGS,
19+
_CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS,
20+
_CS_POSIX_V7_ILP32_OFFBIG_LIBS,
21+
_CS_POSIX_V7_LP64_OFF64_CFLAGS,
22+
_CS_POSIX_V7_LP64_OFF64_LDFLAGS,
23+
_CS_POSIX_V7_LP64_OFF64_LIBS,
24+
_CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS,
25+
_CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS,
26+
_CS_POSIX_V7_LPBIG_OFFBIG_LIBS,
27+
_CS_POSIX_V7_THREADS_CFLAGS,
28+
_CS_POSIX_V7_THREADS_LDFLAGS,
29+
_CS_POSIX_V7_WIDTH_RESTRICTED_ENVS,
30+
_CS_V7_ENV,
31+
_CS_POSIX_V6_ILP32_OFF32_CFLAGS,
32+
_CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
33+
_CS_POSIX_V6_ILP32_OFF32_LIBS,
34+
_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
35+
_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
36+
_CS_POSIX_V6_ILP32_OFFBIG_LIBS,
37+
_CS_POSIX_V6_LP64_OFF64_CFLAGS,
38+
_CS_POSIX_V6_LP64_OFF64_LDFLAGS,
39+
_CS_POSIX_V6_LP64_OFF64_LIBS,
40+
_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
41+
_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
42+
_CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
43+
_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS,
44+
_CS_V6_ENV,
45+
};
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
#endif /* ZEPHYR_INCLUDE_POSIX_SYS_CONFSTR_H_ */

include/zephyr/posix/unistd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifdef CONFIG_POSIX_SYSCONF
2020
#include <zephyr/posix/signal.h>
2121
#endif
22+
#include <zephyr/posix/sys/confstr.h>
2223
#include <zephyr/posix/sys/stat.h>
2324
#include <zephyr/posix/sys/sysconf.h>
2425

@@ -266,6 +267,9 @@ int usleep(useconds_t useconds);
266267
#ifdef CONFIG_POSIX_SYSCONF_IMPL_FULL
267268
long sysconf(int opt);
268269
#endif
270+
#if _POSIX_C_SOURCE >= 2
271+
size_t confstr(int name, char *buf, size_t len);
272+
#endif
269273

270274
#ifdef __cplusplus
271275
}

lib/posix/options/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ zephyr_library_sources_ifdef(CONFIG_POSIX_API perror.c)
4040
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK clock.c)
4141
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK nanosleep.c)
4242
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK sleep.c)
43+
zephyr_library_sources_ifdef(CONFIG_POSIX_CONFSTR confstr.c)
4344
zephyr_library_sources_ifdef(CONFIG_POSIX_ENV env.c)
4445
zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c)
4546
zephyr_library_sources_ifdef(CONFIG_POSIX_MQUEUE mqueue.c)

lib/posix/options/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ endif # POSIX_CLOCK
2727
rsource "Kconfig.barrier"
2828
rsource "Kconfig.clock"
2929
rsource "Kconfig.cond"
30+
rsource "Kconfig.confstr"
3031
rsource "Kconfig.env"
3132
rsource "Kconfig.eventfd"
3233
rsource "Kconfig.fdtable"

lib/posix/options/Kconfig.confstr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2024, Meta
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
config POSIX_CONFSTR
6+
bool "Retrieve string system configuration"
7+
default y if POSIX_API
8+
help
9+
This enables the POSIX confstr() function.

lib/posix/options/confstr.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2024, Meta
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/posix/unistd.h>
8+
9+
size_t confstr(int name, char *buf, size_t len)
10+
{
11+
if (name < 0 || name > _CS_V6_ENV) {
12+
errno = EINVAL;
13+
return 0;
14+
}
15+
16+
if (buf != NULL && len > 0) {
17+
buf[0] = '\0';
18+
}
19+
20+
return 1;
21+
}

0 commit comments

Comments
 (0)