Commit ab8b28ed authored by Chris Friedt's avatar Chris Friedt Committed by Henrik Brix Andersen
Browse files

posix: device_io: implement fileno()



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

Signed-off-by: default avatarChris Friedt <cfriedt@tenstorrent.com>
parent 399458e3
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -409,6 +409,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 −0
Original line number Diff line number Diff line
@@ -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 */