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 <cfriedt@meta.com>
This commit is contained in:
parent
b7e301ed26
commit
c9edda0fbf
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Meta
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_CONFSTR_H_
|
||||
#define ZEPHYR_INCLUDE_POSIX_SYS_CONFSTR_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
_CS_PATH,
|
||||
_CS_POSIX_V7_ILP32_OFF32_CFLAGS,
|
||||
_CS_POSIX_V7_ILP32_OFF32_LDFLAGS,
|
||||
_CS_POSIX_V7_ILP32_OFF32_LIBS,
|
||||
_CS_POSIX_V7_ILP32_OFFBIG_CFLAGS,
|
||||
_CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS,
|
||||
_CS_POSIX_V7_ILP32_OFFBIG_LIBS,
|
||||
_CS_POSIX_V7_LP64_OFF64_CFLAGS,
|
||||
_CS_POSIX_V7_LP64_OFF64_LDFLAGS,
|
||||
_CS_POSIX_V7_LP64_OFF64_LIBS,
|
||||
_CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS,
|
||||
_CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS,
|
||||
_CS_POSIX_V7_LPBIG_OFFBIG_LIBS,
|
||||
_CS_POSIX_V7_THREADS_CFLAGS,
|
||||
_CS_POSIX_V7_THREADS_LDFLAGS,
|
||||
_CS_POSIX_V7_WIDTH_RESTRICTED_ENVS,
|
||||
_CS_V7_ENV,
|
||||
_CS_POSIX_V6_ILP32_OFF32_CFLAGS,
|
||||
_CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
|
||||
_CS_POSIX_V6_ILP32_OFF32_LIBS,
|
||||
_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
|
||||
_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
|
||||
_CS_POSIX_V6_ILP32_OFFBIG_LIBS,
|
||||
_CS_POSIX_V6_LP64_OFF64_CFLAGS,
|
||||
_CS_POSIX_V6_LP64_OFF64_LDFLAGS,
|
||||
_CS_POSIX_V6_LP64_OFF64_LIBS,
|
||||
_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
|
||||
_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
|
||||
_CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
|
||||
_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS,
|
||||
_CS_V6_ENV,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_POSIX_SYS_CONFSTR_H_ */
|
|
@ -19,6 +19,7 @@
|
|||
#ifdef CONFIG_POSIX_SYSCONF
|
||||
#include <zephyr/posix/signal.h>
|
||||
#endif
|
||||
#include <zephyr/posix/sys/confstr.h>
|
||||
#include <zephyr/posix/sys/stat.h>
|
||||
#include <zephyr/posix/sys/sysconf.h>
|
||||
|
||||
|
@ -266,6 +267,9 @@ int usleep(useconds_t useconds);
|
|||
#ifdef CONFIG_POSIX_SYSCONF_IMPL_FULL
|
||||
long sysconf(int opt);
|
||||
#endif
|
||||
#if _POSIX_C_SOURCE >= 2
|
||||
size_t confstr(int name, char *buf, size_t len);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ zephyr_library_sources_ifdef(CONFIG_POSIX_API perror.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK clock.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK nanosleep.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK sleep.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_CONFSTR confstr.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_ENV env.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_MQUEUE mqueue.c)
|
||||
|
|
|
@ -27,6 +27,7 @@ endif # POSIX_CLOCK
|
|||
rsource "Kconfig.barrier"
|
||||
rsource "Kconfig.clock"
|
||||
rsource "Kconfig.cond"
|
||||
rsource "Kconfig.confstr"
|
||||
rsource "Kconfig.env"
|
||||
rsource "Kconfig.eventfd"
|
||||
rsource "Kconfig.fdtable"
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) 2024, Meta
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config POSIX_CONFSTR
|
||||
bool "Retrieve string system configuration"
|
||||
default y if POSIX_API
|
||||
help
|
||||
This enables the POSIX confstr() function.
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Meta
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/posix/unistd.h>
|
||||
|
||||
size_t confstr(int name, char *buf, size_t len)
|
||||
{
|
||||
if (name < 0 || name > _CS_V6_ENV) {
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buf != NULL && len > 0) {
|
||||
buf[0] = '\0';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue