From c77e752a821fa49d383543f6ce92515ff1dc14cc Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 15 Oct 2022 10:28:52 +0200 Subject: [PATCH] libc: Implement fileno() --- libs/libc/include/stdio.h | 3 +++ libs/libc/src/file.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/libs/libc/include/stdio.h b/libs/libc/include/stdio.h index abed2254..768a60f5 100644 --- a/libs/libc/include/stdio.h +++ b/libs/libc/include/stdio.h @@ -40,6 +40,9 @@ extern "C" /* Returns a new file associated with the file descriptor fd. */ FILE* fdopen(int fd, const char* mode); + /* Returns the file descriptor associated with the file stream. */ + int fileno(FILE* stream); + /* Writes formatted output according to the string format to the file stream. */ int fprintf(FILE* stream, const char* format, ...); diff --git a/libs/libc/src/file.cpp b/libs/libc/src/file.cpp index 206d4f5d..60e5ac45 100644 --- a/libs/libc/src/file.cpp +++ b/libs/libc/src/file.cpp @@ -53,6 +53,11 @@ extern "C" return stream; } + int fileno(FILE* stream) + { + return stream->f_fd; + } + size_t fread(void* buf, size_t size, size_t nmemb, FILE* stream) { ssize_t status = read(stream->f_fd, buf, size * nmemb);