Commit 399458e3 authored by Chris Friedt's avatar Chris Friedt Committed by Henrik Brix Andersen
Browse files

posix: device_io: implement fdopen()



Implement fdopen(), as required by the POSIX_DEVICE_IO Option
Group.

Signed-off-by: default avatarChris Friedt <cfriedt@tenstorrent.com>
parent 1715196c
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include <errno.h>
#include <string.h>
#include <stdio.h>

#include <zephyr/posix/fcntl.h>
#include <zephyr/kernel.h>
@@ -397,6 +398,17 @@ int zvfs_close(int fd)
	return res;
}

FILE *zvfs_fdopen(int fd, const char *mode)
{
	ARG_UNUSED(mode);

	if (_check_fd(fd) < 0) {
		return NULL;
	}

	return (FILE *)&fdtable[fd];
}

int zvfs_fstat(int fd, struct stat *buf)
{
	if (_check_fd(fd) < 0) {
+7 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 */

#include <stddef.h>
#include <stdio.h>
#include <stdint.h>

#include <zephyr/posix/poll.h>
@@ -13,6 +14,7 @@

/* prototypes for external, not-yet-public, functions in fdtable.c or fs.c */
int zvfs_close(int fd);
FILE *zvfs_fdopen(int fd, const char *mode);
int zvfs_open(const char *name, int flags);
ssize_t zvfs_read(int fd, void *buf, size_t sz, size_t *from_offset);
ssize_t zvfs_write(int fd, const void *buf, size_t sz, size_t *from_offset);
@@ -45,6 +47,11 @@ int close(int fd)
FUNC_ALIAS(close, _close, int);
#endif

FILE *fdopen(int fd, const char *mode)
{
	return zvfs_fdopen(fd, mode);
}

int open(const char *name, int flags, ...)
{
	/* FIXME: necessarily need to check for O_CREAT and unpack ... if set */