Skip to content

posix: implement putmsg() #67711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions include/zephyr/posix/stropts.h
Original file line number Diff line number Diff line change
@@ -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_ */
1 change: 1 addition & 0 deletions lib/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/posix/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
9 changes: 9 additions & 0 deletions lib/posix/Kconfig.stropts
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 20 additions & 0 deletions lib/posix/stropts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2024 Abhinav Srivastava
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/posix/stropts.h>
#include <errno.h>
#include <zephyr/kernel.h>

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;
}
21 changes: 21 additions & 0 deletions tests/posix/common/src/stropts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Abhinav Srivastava
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/ztest.h>
#include <stropts.h>
#include <errno.h>

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);
28 changes: 28 additions & 0 deletions tests/posix/headers/src/stropts_h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Abhinav Srivastava
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "_common.h"
#ifdef CONFIG_POSIX_API
#include <stropts.h>
#else
#include <zephyr/posix/stropts.h>
#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
}