posix: deprecate POSIX_FNMATCH GETOPT GETENTROPY
The functions fnmatch(), getopt(), getentropy() and others are grouped into the standard Option Group POSIX_C_LIB_EXT. The getentropy() function is currently in-draft for Issue 8 as of 2021. https://www.opengroup.org/austin/docs/austin_1110.pdf Not surprisingly, the POSIX_C_LIB_EXT Option Group also includes the highly debated strnlen() function. Moving that function will be deferred until later. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
parent
70e2b02c8e
commit
2bc722a97e
24 changed files with 115 additions and 104 deletions
|
@ -9,8 +9,6 @@ implementation of the POSIX API.
|
|||
* :kconfig:option:`CONFIG_EVENTFD`
|
||||
* :kconfig:option:`CONFIG_EVENTFD_MAX`
|
||||
* :kconfig:option:`CONFIG_FDTABLE`
|
||||
* :kconfig:option:`CONFIG_FNMATCH`
|
||||
* :kconfig:option:`CONFIG_GETOPT`
|
||||
* :kconfig:option:`CONFIG_GETOPT_LONG`
|
||||
* :kconfig:option:`CONFIG_MAX_PTHREAD_COUNT`
|
||||
* :kconfig:option:`CONFIG_MAX_PTHREAD_KEY_COUNT`
|
||||
|
|
|
@ -151,6 +151,31 @@ Group.
|
|||
For more information on developing Zephyr applications in the C programming language, please refer
|
||||
to :ref:`details<language_support>`.
|
||||
|
||||
.. _posix_option_group_c_lib_ext:
|
||||
|
||||
POSIX_C_LIB_EXT
|
||||
===============
|
||||
|
||||
.. csv-table:: POSIX_C_LIB_EXT
|
||||
:header: API, Supported
|
||||
:widths: 50,10
|
||||
|
||||
fnmatch(), yes
|
||||
getopt(), yes
|
||||
getsubopt(),
|
||||
optarg, yes
|
||||
opterr, yes
|
||||
optind, yes
|
||||
optopt, yes
|
||||
stpcpy(),
|
||||
stpncpy(),
|
||||
strcasecmp(),
|
||||
strdup(),
|
||||
strfmon(),
|
||||
strncasecmp(), yes
|
||||
strndup(),
|
||||
strnlen(), yes
|
||||
|
||||
.. _posix_option_group_realtime_signals:
|
||||
|
||||
POSIX_REALTIME_SIGNALS
|
||||
|
|
|
@ -556,7 +556,7 @@ is accomplished by the ``getopt`` family functions.
|
|||
|
||||
For this purpose shell supports the getopt and getopt_long libraries available
|
||||
in the FreeBSD project. This feature is activated by:
|
||||
:kconfig:option:`CONFIG_GETOPT` set to ``y`` and :kconfig:option:`CONFIG_GETOPT_LONG`
|
||||
:kconfig:option:`CONFIG_POSIX_C_LIB_EXT` set to ``y`` and :kconfig:option:`CONFIG_GETOPT_LONG`
|
||||
set to ``y``.
|
||||
|
||||
This feature can be used in thread safe as well as non thread safe manner.
|
||||
|
|
|
@ -16,7 +16,6 @@ config GROVE_LIGHT_SENSOR
|
|||
bool "The Seeed Grove Light Sensor"
|
||||
default y
|
||||
depends on DT_HAS_SEEED_GROVE_LIGHT_ENABLED
|
||||
depends on !MINIMAL_LIBC
|
||||
select ADC
|
||||
help
|
||||
Setting this value will enable driver support for the Grove Light
|
||||
|
@ -26,7 +25,6 @@ config GROVE_TEMPERATURE_SENSOR
|
|||
bool "The Seeed Grove Temperature Sensor"
|
||||
default y
|
||||
depends on DT_HAS_SEEED_GROVE_TEMPERATURE_ENABLED
|
||||
depends on !MINIMAL_LIBC
|
||||
select ADC
|
||||
help
|
||||
Setting this value will enable driver support for the Grove
|
||||
|
|
|
@ -52,7 +52,7 @@ static inline int gethostname(char *buf, size_t len)
|
|||
|
||||
#endif /* CONFIG_POSIX_API */
|
||||
|
||||
#ifdef CONFIG_GETOPT
|
||||
#ifdef CONFIG_POSIX_C_LIB_EXT
|
||||
int getopt(int argc, char *const argv[], const char *optstring);
|
||||
extern char *optarg;
|
||||
extern int opterr, optind, optopt;
|
||||
|
|
|
@ -10,7 +10,7 @@ if CRC
|
|||
config CRC_SHELL
|
||||
bool "CRC Shell"
|
||||
depends on SHELL
|
||||
select GETOPT
|
||||
select POSIX_C_LIB_EXT
|
||||
help
|
||||
Enable CRC checking for memory regions from the shell.
|
||||
endif # CRC
|
||||
|
|
|
@ -25,7 +25,7 @@ if(CONFIG_POSIX_SIGNAL)
|
|||
endif()
|
||||
|
||||
if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_TIMERS OR
|
||||
CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FS OR CONFIG_EVENTFD OR CONFIG_GETOPT OR
|
||||
CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FS OR CONFIG_EVENTFD OR CONFIG_POSIX_C_LIB_EXT OR
|
||||
CONFIG_POSIX_SINGLE_PROCESS)
|
||||
# This is a temporary workaround so that Newlib declares the appropriate
|
||||
# types for us. POSIX features to be formalized as part of #51211
|
||||
|
@ -34,12 +34,15 @@ if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_TIMERS OR
|
|||
endif()
|
||||
|
||||
zephyr_library()
|
||||
add_subdirectory_ifdef(CONFIG_GETOPT getopt)
|
||||
zephyr_library_sources_ifdef(CONFIG_EVENTFD eventfd.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_FNMATCH fnmatch.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GETENTROPY getentropy.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_ASYNCHRONOUS_IO aio.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_BARRIERS barrier.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_C_LIB_EXT
|
||||
fnmatch.c
|
||||
getentropy.c
|
||||
getopt/getopt.c
|
||||
getopt/getopt_common.c
|
||||
)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_DEVICE_IO
|
||||
# perror should be moved to the common libc
|
||||
perror.c
|
||||
|
@ -77,6 +80,13 @@ zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_POSIX_READER_WRITER_LOCKS rwlock.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_GETOPT_LONG
|
||||
getopt/getopt_long.c
|
||||
)
|
||||
zephyr_include_directories_ifdef(CONFIG_POSIX_C_LIB_EXT
|
||||
getopt/
|
||||
)
|
||||
|
||||
zephyr_library_include_directories(
|
||||
${ZEPHYR_BASE}/kernel/include
|
||||
${ARCH_DIR}/${ARCH}/include
|
||||
|
|
|
@ -26,13 +26,10 @@ config PTHREAD_IPC
|
|||
rsource "Kconfig.aio"
|
||||
rsource "Kconfig.barrier"
|
||||
rsource "Kconfig.cond"
|
||||
rsource "Kconfig.c_lib_ext"
|
||||
rsource "Kconfig.device_io"
|
||||
rsource "Kconfig.eventfd"
|
||||
rsource "Kconfig.fd_mgmt"
|
||||
rsource "Kconfig.fnmatch"
|
||||
rsource "Kconfig.fs"
|
||||
rsource "Kconfig.getentropy"
|
||||
rsource "Kconfig.getopt"
|
||||
rsource "Kconfig.key"
|
||||
rsource "Kconfig.mem"
|
||||
rsource "Kconfig.mqueue"
|
||||
|
|
30
lib/posix/options/Kconfig.c_lib_ext
Normal file
30
lib/posix/options/Kconfig.c_lib_ext
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Copyright (c) 2024 Tenstorrent AI ULC
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menuconfig POSIX_C_LIB_EXT
|
||||
bool "POSIX general C library extension"
|
||||
default y if POSIX_API
|
||||
help
|
||||
Select 'y' here and Zephyr will provide an implementation of the POSIX_C_LIB_EXT Option
|
||||
Group, consisting of fnmatch(), getopt(), getsubopt(), optarg, opterr, optind, optopt,
|
||||
stpcpy(), stpncpy(), strcasecmp(), strdup(), strfmon(), and strncasecmp(), strndup(), and
|
||||
strnlen().
|
||||
|
||||
For more informnation, please see
|
||||
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
|
||||
|
||||
if POSIX_C_LIB_EXT
|
||||
|
||||
config GETOPT_LONG
|
||||
bool "Getopt long library support"
|
||||
help
|
||||
This option adds support of the getopt long.
|
||||
Different shell backends are using their own instance of getopt to
|
||||
not interfere with each other.
|
||||
All not shell threads share one global instance of getopt state, hence
|
||||
apart from shell this library is not thread safe. User can add support
|
||||
for other threads by extending function getopt_state_get in
|
||||
getopt_common.c file.
|
||||
|
||||
endif # POSIX_C_LIB_EXT
|
|
@ -6,6 +6,33 @@
|
|||
|
||||
menu "Deprecated POSIX options"
|
||||
|
||||
config FNMATCH
|
||||
bool "Support for fnmatch [DEPRECATED]"
|
||||
select DEPRECATED
|
||||
select POSIX_C_LIB_EXT
|
||||
help
|
||||
This option is deprecated.
|
||||
|
||||
Please use CONFIG_POSIX_C_LIB_EXT instead.
|
||||
|
||||
config GETENTROPY
|
||||
bool "Support for getentropy [DEPRECATED]"
|
||||
select DEPRECATED
|
||||
select POSIX_C_LIB_EXT
|
||||
help
|
||||
This option is deprecated.
|
||||
|
||||
Please use CONFIG_POSIX_C_LIB_EXT instead.
|
||||
|
||||
config GETOPT
|
||||
bool "Getopt library support [DEPRECATED]"
|
||||
select DEPRECATED
|
||||
select POSIX_C_LIB_EXT
|
||||
help
|
||||
This option is deprecated.
|
||||
|
||||
Please use CONFIG_POSIX_C_LIB_EXT instead.
|
||||
|
||||
config MAX_TIMER_COUNT
|
||||
int "Maximum number of timer_t [DEPRECATED]"
|
||||
default POSIX_TIMER_MAX if POSIX_TIMERS
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
# Copyright (c) 2018 Nordic Semiconductor ASA
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config FNMATCH
|
||||
bool "Support for fnmatch"
|
||||
default y if POSIX_API
|
||||
help
|
||||
Match filenames using the the fnmatch function. For example, the pattern
|
||||
"*.c" matches the filename "hello.c".
|
|
@ -1,14 +0,0 @@
|
|||
# Copyright (c) 2024 Google LLC
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
DT_CHOSEN_ZEPHYR_ENTROPY := zephyr,entropy
|
||||
|
||||
config GETENTROPY
|
||||
bool "Support for getentropy"
|
||||
depends on !NATIVE_APPLICATION
|
||||
select NATIVE_LIBC_INCOMPATIBLE
|
||||
depends on ENTROPY_HAS_DRIVER
|
||||
depends on $(dt_chosen_enabled,$(DT_CHOSEN_ZEPHYR_ENTROPY))
|
||||
help
|
||||
Enable support for getentropy() function.
|
|
@ -1,5 +0,0 @@
|
|||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
rsource "getopt/Kconfig"
|
|
@ -10,11 +10,11 @@
|
|||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/posix/unistd.h>
|
||||
|
||||
#define ENTROPY_NODE DT_CHOSEN(zephyr_entropy)
|
||||
#define ENTROPY_NODE DEVICE_DT_GET_OR_NULL(DT_CHOSEN(zephyr_entropy))
|
||||
|
||||
int getentropy(void *buffer, size_t length)
|
||||
{
|
||||
const struct device * const entropy = DEVICE_DT_GET(ENTROPY_NODE);
|
||||
const struct device *const entropy = ENTROPY_NODE;
|
||||
|
||||
if (!buffer) {
|
||||
errno = EFAULT;
|
||||
|
@ -26,7 +26,7 @@ int getentropy(void *buffer, size_t length)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (!device_is_ready(entropy)) {
|
||||
if (entropy == NULL || !device_is_ready(entropy)) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
# Copyright (c) 2021 Nordic Semiconductor
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
zephyr_include_directories_ifdef(
|
||||
CONFIG_GETOPT
|
||||
.
|
||||
)
|
||||
|
||||
zephyr_sources_ifdef(
|
||||
CONFIG_GETOPT
|
||||
getopt.c
|
||||
getopt_common.c
|
||||
)
|
||||
|
||||
zephyr_sources_ifdef(
|
||||
CONFIG_GETOPT_LONG
|
||||
getopt_long.c
|
||||
)
|
|
@ -1,28 +0,0 @@
|
|||
# Copyright (c) 2021 Nordic Semiconductor
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
|
||||
menuconfig GETOPT
|
||||
bool "Getopt library support"
|
||||
default y if POSIX_API
|
||||
help
|
||||
This option adds support of getopt.
|
||||
Different shell backends are use their own instance of getopt to
|
||||
not interfere with each other.
|
||||
All not shell threads share one global instance of getopt state, hence
|
||||
apart from shell this library is not thread safe. User can add support
|
||||
for other threads by extending function getopt_state_get in
|
||||
getopt_common.c file.
|
||||
This option enables the following function: getopt.
|
||||
|
||||
config GETOPT_LONG
|
||||
bool "Getopt long library support"
|
||||
depends on GETOPT
|
||||
help
|
||||
This option adds support of the getopt long.
|
||||
Different shell backends are using their own instance of getopt to
|
||||
not interfere with each other.
|
||||
All not shell threads share one global instance of getopt state, hence
|
||||
apart from shell this library is not thread safe. User can add support
|
||||
for other threads by extending function getopt_state_get in
|
||||
getopt_common.c file.
|
|
@ -29,6 +29,10 @@ struct getopt_state {
|
|||
};
|
||||
|
||||
extern int optreset; /* reset getopt */
|
||||
extern char *optarg;
|
||||
extern int opterr;
|
||||
extern int optind;
|
||||
extern int optopt;
|
||||
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
CONFIG_SHELL=y
|
||||
CONFIG_SHELL_GETOPT=y
|
||||
CONFIG_GETOPT=y
|
||||
CONFIG_POSIX_C_LIB_EXT=y
|
||||
CONFIG_GETOPT_LONG=y
|
||||
CONFIG_GPIO=y
|
||||
CONFIG_REGULATOR=y
|
||||
|
|
|
@ -132,7 +132,7 @@ config SHELL_ASCII_FILTER
|
|||
|
||||
config SHELL_WILDCARD
|
||||
bool "Wildcard support in shell"
|
||||
select FNMATCH
|
||||
select POSIX_C_LIB_EXT
|
||||
default y if !SHELL_MINIMAL
|
||||
help
|
||||
Enables using wildcards: * and ? in the shell.
|
||||
|
@ -176,7 +176,7 @@ config SHELL_VT100_COLORS
|
|||
|
||||
config SHELL_GETOPT
|
||||
bool "Threadsafe getopt support in shell"
|
||||
select GETOPT
|
||||
select POSIX_C_LIB_EXT
|
||||
help
|
||||
This config creates a separate getopt_state for the shell instance.
|
||||
It ensures that using getopt with shell is thread safe.
|
||||
|
|
|
@ -42,6 +42,6 @@ config DATE_SHELL
|
|||
config DEVMEM_SHELL
|
||||
bool "Devmem shell"
|
||||
default y if !SHELL_MINIMAL
|
||||
select GETOPT
|
||||
select POSIX_C_LIB_EXT
|
||||
help
|
||||
This shell command provides read/write access to physical memory.
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
CONFIG_ENTROPY_GENERATOR=y
|
||||
CONFIG_GETENTROPY=y
|
||||
CONFIG_POSIX_API=y
|
||||
CONFIG_POSIX_C_LIB_EXT=y
|
||||
CONFIG_ZTEST=y
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <zephyr/posix/unistd.h>
|
||||
|
||||
ZTEST(getentropy_test_suite, test_getentropy_too_large)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CONFIG_GETOPT=y
|
||||
CONFIG_POSIX_C_LIB_EXT=y
|
||||
CONFIG_GETOPT_LONG=y
|
||||
CONFIG_LOG=n
|
||||
CONFIG_ZTEST=y
|
||||
|
|
|
@ -19,4 +19,4 @@ CONFIG_POSIX_FS=y
|
|||
CONFIG_POSIX_TIMERS=y
|
||||
CONFIG_POSIX_MESSAGE_PASSING=y
|
||||
CONFIG_EVENTFD=y
|
||||
CONFIG_GETOPT=y
|
||||
CONFIG_POSIX_C_LIB_EXT=y
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue