From e17a21dbad826dc5952d672a000ce1da8d3b7273 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 17 Oct 2022 20:54:09 +0200 Subject: [PATCH] libc: Use fdopen() after calling open() in fopen() --- libs/libc/src/file.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libs/libc/src/file.cpp b/libs/libc/src/file.cpp index 60e5ac45..0ef00616 100644 --- a/libs/libc/src/file.cpp +++ b/libs/libc/src/file.cpp @@ -30,14 +30,11 @@ extern "C" return 0; // FIXME: Implement buffered IO. } - FILE* fopen(const char* pathname, const char*) + FILE* fopen(const char* pathname, const char* mode) { int fd = open(pathname, O_RDWR); // FIXME: Use the mode string. if (fd < 0) { return 0; } - FILE* stream = (FILE*)malloc(sizeof(FILE)); - stream->f_fd = fd; - clearerr(stream); - return stream; + return fdopen(fd, mode); } FILE* fdopen(int fd, const char*)