Browse Source

posix: device_io: implement fileno()

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

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
pull/75104/head
Chris Friedt 1 year ago committed by Anas Nashif
parent
commit
48dff5562c
  1. 10
      lib/os/fdtable.c
  2. 6
      lib/posix/options/device_io.c

10
lib/os/fdtable.c

@ -414,6 +414,16 @@ FILE *zvfs_fdopen(int fd, const char *mode) @@ -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) {

6
lib/posix/options/device_io.c

@ -15,6 +15,7 @@ @@ -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) @@ -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 */

Loading…
Cancel
Save