From 8659e2f69e5c0f86c0aebc210e10cb8c243d25f1 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Wed, 16 Nov 2022 17:04:17 -0500 Subject: [PATCH] libc: minimal: include: move fcntl.h to posix The `fcntl.h` header has never been a part of ISO C so move it to `include/zephyr/posix`. To ensure a smooth migration, a header was left in `lib/libc/minimal/include` that prints a deprecation warning. Users should either include `` or switch to `CONFIG_POSIX_API=y`. Signed-off-by: Chris Friedt --- drivers/wifi/simplelink/simplelink_sockets.c | 2 +- include/zephyr/posix/fcntl.h | 21 +++++++++++++++++++ include/zephyr/posix/sys/eventfd.h | 2 +- lib/libc/minimal/include/fcntl.h | 17 ++++++--------- lib/posix/fs.c | 2 +- .../socketpair/src/test_socketpair_block.c | 5 +++++ .../src/test_socketpair_closed_ends.c | 4 ++++ .../src/test_socketpair_expected_failures.c | 4 ++++ .../socketpair/src/test_socketpair_fcntl.c | 4 ++++ .../src/test_socketpair_happy_path.c | 4 ++++ .../socketpair/src/test_socketpair_nonblock.c | 4 ++++ .../socketpair/src/test_socketpair_poll.c | 5 +++++ .../src/test_socketpair_unsupported_calls.c | 4 ++++ 13 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 include/zephyr/posix/fcntl.h diff --git a/drivers/wifi/simplelink/simplelink_sockets.c b/drivers/wifi/simplelink/simplelink_sockets.c index 7bc97b687e7..2f23d6d0cd5 100644 --- a/drivers/wifi/simplelink/simplelink_sockets.c +++ b/drivers/wifi/simplelink/simplelink_sockets.c @@ -9,7 +9,7 @@ LOG_MODULE_DECLARE(LOG_MODULE_NAME); #include #include -#include +#include #include /* Define sockaddr, etc, before simplelink.h */ diff --git a/include/zephyr/posix/fcntl.h b/include/zephyr/posix/fcntl.h new file mode 100644 index 00000000000..99e8ad462f3 --- /dev/null +++ b/include/zephyr/posix/fcntl.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2018 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_POSIX_FCNTL_H_ +#define ZEPHYR_POSIX_FCNTL_H_ + +#define O_CREAT 0x0200 +#define O_APPEND 0x0400 +#define O_EXCL 0x0800 +#define O_NONBLOCK 0x4000 + +#define F_DUPFD 0 +#define F_GETFL 3 +#define F_SETFL 4 + +int open(const char *name, int flags, ...); + +#endif /* ZEPHYR_POSIX_FCNTL_H_ */ diff --git a/include/zephyr/posix/sys/eventfd.h b/include/zephyr/posix/sys/eventfd.h index 1228613b607..fc4e30fa211 100644 --- a/include/zephyr/posix/sys/eventfd.h +++ b/include/zephyr/posix/sys/eventfd.h @@ -11,7 +11,7 @@ #include #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/lib/libc/minimal/include/fcntl.h b/lib/libc/minimal/include/fcntl.h index 6fdb8494d3f..768ce47e8a3 100644 --- a/lib/libc/minimal/include/fcntl.h +++ b/lib/libc/minimal/include/fcntl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Linaro Limited + * Copyright (c) 2022 Meta * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,15 +7,10 @@ #ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_FCNTL_H_ #define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_FCNTL_H_ -#define O_CREAT 0x0200 -#define O_APPEND 0x0400 -#define O_EXCL 0x0800 -#define O_NONBLOCK 0x4000 - -#define F_DUPFD 0 -#define F_GETFL 3 -#define F_SETFL 4 - -int open(const char *name, int flags, ...); +#ifndef CONFIG_POSIX_API +#pragma message("#include without CONFIG_POSIX_API is deprecated. " \ + "Please use CONFIG_POSIX_API or #include ") +#endif +#include #endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_FCNTL_H_ */ diff --git a/lib/posix/fs.c b/lib/posix/fs.c index b724b80188b..f0cd51d0d96 100644 --- a/lib/posix/fs.c +++ b/lib/posix/fs.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include BUILD_ASSERT(PATH_MAX >= MAX_FILE_NAME, "PATH_MAX is less than MAX_FILE_NAME"); diff --git a/tests/net/socket/socketpair/src/test_socketpair_block.c b/tests/net/socket/socketpair/src/test_socketpair_block.c index 67c373b9330..d8afd3da870 100644 --- a/tests/net/socket/socketpair/src/test_socketpair_block.c +++ b/tests/net/socket/socketpair/src/test_socketpair_block.c @@ -4,7 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifdef CONFIG_ARCH_POSIX #include +#else +#include +#endif + #include #include diff --git a/tests/net/socket/socketpair/src/test_socketpair_closed_ends.c b/tests/net/socket/socketpair/src/test_socketpair_closed_ends.c index 52d424b08b9..79c103057fb 100644 --- a/tests/net/socket/socketpair/src/test_socketpair_closed_ends.c +++ b/tests/net/socket/socketpair/src/test_socketpair_closed_ends.c @@ -2,7 +2,11 @@ * * Copyright (c) 2020 Friedt Professional Engineering Services, Inc */ +#ifdef CONFIG_ARCH_POSIX #include +#else +#include +#endif #include LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL); diff --git a/tests/net/socket/socketpair/src/test_socketpair_expected_failures.c b/tests/net/socket/socketpair/src/test_socketpair_expected_failures.c index ce00d1e6684..baa224c0c90 100644 --- a/tests/net/socket/socketpair/src/test_socketpair_expected_failures.c +++ b/tests/net/socket/socketpair/src/test_socketpair_expected_failures.c @@ -4,7 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifdef CONFIG_ARCH_POSIX #include +#else +#include +#endif #include LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL); diff --git a/tests/net/socket/socketpair/src/test_socketpair_fcntl.c b/tests/net/socket/socketpair/src/test_socketpair_fcntl.c index ba9a16eb57b..bdaacacf724 100644 --- a/tests/net/socket/socketpair/src/test_socketpair_fcntl.c +++ b/tests/net/socket/socketpair/src/test_socketpair_fcntl.c @@ -4,7 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifdef CONFIG_ARCH_POSIX #include +#else +#include +#endif #include LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL); diff --git a/tests/net/socket/socketpair/src/test_socketpair_happy_path.c b/tests/net/socket/socketpair/src/test_socketpair_happy_path.c index dbb8f580617..583a897023c 100644 --- a/tests/net/socket/socketpair/src/test_socketpair_happy_path.c +++ b/tests/net/socket/socketpair/src/test_socketpair_happy_path.c @@ -4,7 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifdef CONFIG_ARCH_POSIX #include +#else +#include +#endif #include LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL); diff --git a/tests/net/socket/socketpair/src/test_socketpair_nonblock.c b/tests/net/socket/socketpair/src/test_socketpair_nonblock.c index 090790363fc..582c3f18814 100644 --- a/tests/net/socket/socketpair/src/test_socketpair_nonblock.c +++ b/tests/net/socket/socketpair/src/test_socketpair_nonblock.c @@ -4,7 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifdef CONFIG_ARCH_POSIX #include +#else +#include +#endif #include LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL); diff --git a/tests/net/socket/socketpair/src/test_socketpair_poll.c b/tests/net/socket/socketpair/src/test_socketpair_poll.c index aeb49ff8ed0..65f6414d69b 100644 --- a/tests/net/socket/socketpair/src/test_socketpair_poll.c +++ b/tests/net/socket/socketpair/src/test_socketpair_poll.c @@ -4,7 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifdef CONFIG_ARCH_POSIX #include +#else +#include +#endif + #include #include diff --git a/tests/net/socket/socketpair/src/test_socketpair_unsupported_calls.c b/tests/net/socket/socketpair/src/test_socketpair_unsupported_calls.c index 280a912de5b..fb9ed87c8eb 100644 --- a/tests/net/socket/socketpair/src/test_socketpair_unsupported_calls.c +++ b/tests/net/socket/socketpair/src/test_socketpair_unsupported_calls.c @@ -4,7 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifdef CONFIG_ARCH_POSIX #include +#else +#include +#endif #include LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);