From 80a897fbc5fc2dc4be1217fe59522de1223f66a0 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 12 Mar 2023 17:38:35 +0100 Subject: [PATCH] libc: Add fileno() --- libc/include/stdio.h | 3 +++ libc/src/stdio.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/libc/include/stdio.h b/libc/include/stdio.h index de22722f..831d0069 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -32,6 +32,9 @@ extern "C" /* Close a file and frees up its stream. */ int fclose(FILE* stream); + /* Return the file descriptor associated with a stream. */ + int fileno(FILE* stream); + /* Read arbitrarily sized items from a stream. */ size_t fread(void* buf, size_t size, size_t nmemb, FILE* stream); diff --git a/libc/src/stdio.cpp b/libc/src/stdio.cpp index e34f59d0..e6f3ff8e 100644 --- a/libc/src/stdio.cpp +++ b/libc/src/stdio.cpp @@ -66,6 +66,11 @@ extern "C" return 0; } + int fileno(FILE* stream) + { + return stream->_fd; + } + size_t fread(void* buf, size_t size, size_t nmemb, FILE* stream) { if (size * nmemb == 0) return 0;