Skip to content

Commit 581a0f5

Browse files
cfriedtnashif
authored andcommitted
posix: device_io: implement fdopen()
Implement fdopen(), as required by the POSIX_DEVICE_IO Option Group. Signed-off-by: Chris Friedt <[email protected]>
1 parent 305ec62 commit 581a0f5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/os/fdtable.c

+11
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,17 @@ int zvfs_close(int fd)
403403
return res;
404404
}
405405

406+
FILE *zvfs_fdopen(int fd, const char *mode)
407+
{
408+
ARG_UNUSED(mode);
409+
410+
if (_check_fd(fd) < 0) {
411+
return NULL;
412+
}
413+
414+
return (FILE *)&fdtable[fd];
415+
}
416+
406417
int zvfs_fstat(int fd, struct stat *buf)
407418
{
408419
if (_check_fd(fd) < 0) {

lib/posix/options/device_io.c

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <stddef.h>
8+
#include <stdio.h>
89
#include <stdint.h>
910

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

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

50+
FILE *fdopen(int fd, const char *mode)
51+
{
52+
return zvfs_fdopen(fd, mode);
53+
}
54+
4855
int open(const char *name, int flags, ...)
4956
{
5057
/* FIXME: necessarily need to check for O_CREAT and unpack ... if set */

0 commit comments

Comments
 (0)