Skip to content

Commit 48dff55

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

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/os/fdtable.c

+10
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,16 @@ FILE *zvfs_fdopen(int fd, const char *mode)
414414
return (FILE *)&fdtable[fd];
415415
}
416416

417+
int zvfs_fileno(FILE *file)
418+
{
419+
if (!IS_ARRAY_ELEMENT(fdtable, file)) {
420+
errno = EBADF;
421+
return -1;
422+
}
423+
424+
return (struct fd_entry *)file - fdtable;
425+
}
426+
417427
int zvfs_fstat(int fd, struct stat *buf)
418428
{
419429
if (_check_fd(fd) < 0) {

lib/posix/options/device_io.c

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/* prototypes for external, not-yet-public, functions in fdtable.c or fs.c */
1616
int zvfs_close(int fd);
1717
FILE *zvfs_fdopen(int fd, const char *mode);
18+
int zvfs_fileno(FILE *file);
1819
int zvfs_open(const char *name, int flags);
1920
ssize_t zvfs_read(int fd, void *buf, size_t sz, size_t *from_offset);
2021
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)
5253
return zvfs_fdopen(fd, mode);
5354
}
5455

56+
int fileno(FILE *file)
57+
{
58+
return zvfs_fileno(file);
59+
}
60+
5561
int open(const char *name, int flags, ...)
5662
{
5763
/* FIXME: necessarily need to check for O_CREAT and unpack ... if set */

0 commit comments

Comments
 (0)