posix: device_io: implement fdopen()
Implement fdopen(), as required by the POSIX_DEVICE_IO Option Group. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
parent
1715196cff
commit
399458e3b4
2 changed files with 19 additions and 0 deletions
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <zephyr/posix/fcntl.h>
|
#include <zephyr/posix/fcntl.h>
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
|
@ -397,6 +398,17 @@ int zvfs_close(int fd)
|
||||||
return res;
|
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)
|
int zvfs_fstat(int fd, struct stat *buf)
|
||||||
{
|
{
|
||||||
if (_check_fd(fd) < 0) {
|
if (_check_fd(fd) < 0) {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <zephyr/posix/poll.h>
|
#include <zephyr/posix/poll.h>
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
|
|
||||||
/* prototypes for external, not-yet-public, functions in fdtable.c or fs.c */
|
/* prototypes for external, not-yet-public, functions in fdtable.c or fs.c */
|
||||||
int zvfs_close(int fd);
|
int zvfs_close(int fd);
|
||||||
|
FILE *zvfs_fdopen(int fd, const char *mode);
|
||||||
int zvfs_open(const char *name, int flags);
|
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_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);
|
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);
|
FUNC_ALIAS(close, _close, int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
FILE *fdopen(int fd, const char *mode)
|
||||||
|
{
|
||||||
|
return zvfs_fdopen(fd, mode);
|
||||||
|
}
|
||||||
|
|
||||||
int open(const char *name, int flags, ...)
|
int open(const char *name, int flags, ...)
|
||||||
{
|
{
|
||||||
/* FIXME: necessarily need to check for O_CREAT and unpack ... if set */
|
/* FIXME: necessarily need to check for O_CREAT and unpack ... if set */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue