posix: device_io: implement fileno()

Implement fileno() as required by the POSIX_DEVICE_IO Option
Group.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
Chris Friedt 2024-06-15 12:05:48 -04:00 committed by Anas Nashif
parent 581a0f56e6
commit 48dff5562c
2 changed files with 16 additions and 0 deletions

View File

@ -414,6 +414,16 @@ FILE *zvfs_fdopen(int fd, const char *mode)
return (FILE *)&fdtable[fd];
}
int zvfs_fileno(FILE *file)
{
if (!IS_ARRAY_ELEMENT(fdtable, file)) {
errno = EBADF;
return -1;
}
return (struct fd_entry *)file - fdtable;
}
int zvfs_fstat(int fd, struct stat *buf)
{
if (_check_fd(fd) < 0) {

View File

@ -15,6 +15,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_fileno(FILE *file);
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);
@ -52,6 +53,11 @@ FILE *fdopen(int fd, const char *mode)
return zvfs_fdopen(fd, mode);
}
int fileno(FILE *file)
{
return zvfs_fileno(file);
}
int open(const char *name, int flags, ...)
{
/* FIXME: necessarily need to check for O_CREAT and unpack ... if set */