diff --git a/include/zephyr/posix/stropts.h b/include/zephyr/posix/stropts.h new file mode 100644 index 000000000000..9474c36edb2c --- /dev/null +++ b/include/zephyr/posix/stropts.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Abhinav Srivastava + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_INCLUDE_POSIX_STROPTS_H_ +#define ZEPHYR_INCLUDE_POSIX_STROPTS_H_ +#define RS_HIPRI BIT(0) + +#ifdef __cplusplus +extern "C" { +#endif + +struct strbuf { + int maxlen; + int len; + char *buf; +}; + +int putmsg(int fildes, const struct strbuf *ctlptr, const struct strbuf *dataptr, int flags); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_POSIX_STROPTS_H_ */ diff --git a/lib/posix/CMakeLists.txt b/lib/posix/CMakeLists.txt index 5477e27b3868..c8d836f58464 100644 --- a/lib/posix/CMakeLists.txt +++ b/lib/posix/CMakeLists.txt @@ -58,6 +58,7 @@ zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_SPINLOCK spinlock.c) zephyr_library_sources_ifdef(CONFIG_TIMER timer.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_PUTMSG stropts.c) zephyr_library_include_directories( ${ZEPHYR_BASE}/kernel/include diff --git a/lib/posix/Kconfig b/lib/posix/Kconfig index b1443a5ab715..6547b1bea1f9 100644 --- a/lib/posix/Kconfig +++ b/lib/posix/Kconfig @@ -58,6 +58,7 @@ source "lib/posix/Kconfig.signal" source "lib/posix/Kconfig.spinlock" source "lib/posix/Kconfig.timer" source "lib/posix/Kconfig.uname" +source "lib/posix/Kconfig.stropts" rsource "shell/Kconfig" diff --git a/lib/posix/Kconfig.stropts b/lib/posix/Kconfig.stropts new file mode 100644 index 000000000000..347f0f33c150 --- /dev/null +++ b/lib/posix/Kconfig.stropts @@ -0,0 +1,9 @@ +# copyright (c) 2024 Abhinav Srivastava +# +# SPDX-License-Identifier: Apache-2.0 + +config POSIX_PUTMSG + bool "Support for putmsg function" + default y if POSIX_API + help + This option provides support for the putmsg function used in message passing. diff --git a/lib/posix/stropts.c b/lib/posix/stropts.c new file mode 100644 index 000000000000..54fca00cc9ff --- /dev/null +++ b/lib/posix/stropts.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Abhinav Srivastava + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +int putmsg(int fildes, const struct strbuf *ctlptr, const struct strbuf *dataptr, int flags) +{ + ARG_UNUSED(fildes); + ARG_UNUSED(ctlptr); + ARG_UNUSED(dataptr); + ARG_UNUSED(flags); + + errno = ENOSYS; + return -1; +} diff --git a/tests/posix/common/src/stropts.c b/tests/posix/common/src/stropts.c new file mode 100644 index 000000000000..4c9221a398ca --- /dev/null +++ b/tests/posix/common/src/stropts.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Abhinav Srivastava + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include + +ZTEST(stropts, test_putmsg) +{ + const struct strbuf *ctrl = NULL; + const struct strbuf *data = NULL; + int fd = -1; + int ret = putmsg(fd, ctrl, data, 0); + + zassert_equal(ret, -1, "Expected return value -1, got %d", ret); + zassert_equal(errno, ENOSYS, "Expected errno ENOSYS, got %d", errno); +} + +ZTEST_SUITE(stropts, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/posix/headers/src/stropts_h.c b/tests/posix/headers/src/stropts_h.c new file mode 100644 index 000000000000..a095c83c98cc --- /dev/null +++ b/tests/posix/headers/src/stropts_h.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 Abhinav Srivastava + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "_common.h" +#ifdef CONFIG_POSIX_API +#include +#else +#include +#endif + +/** + * @brief Test existence and basic functionality of stropts.h + * + * @see stropts.h + */ +ZTEST(posix_headers, test_stropts_h) +{ + #ifdef CONFIG_POSIX_API + zassert_not_null((void *)putmsg, "putmsg is null"); + + zassert_true(sizeof(((struct strbuf *)0)->maxlen) > 0, "maxlen size is 0"); + zassert_true(sizeof(((struct strbuf *)0)->len) > 0, "len size is 0"); + zassert_true(sizeof(((struct strbuf *)0)->buf) > 0, "buf size is 0"); + zassert_not_equal(RS_HIPRI, ~RS_HIPRI); + #endif +}