diff --git a/libs/libc/src/file.cpp b/libs/libc/src/file.cpp index c98db0ee..8e70e47a 100644 --- a/libs/libc/src/file.cpp +++ b/libs/libc/src/file.cpp @@ -5,6 +5,9 @@ #include #include +FILE* __stderr; +FILE* __stdout; + extern "C" { int fclose(FILE* stream) @@ -29,7 +32,7 @@ extern "C" FILE* fopen(const char* pathname, const char*) { - int fd = open(pathname, O_RDONLY); // FIXME: Use the mode string. + 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; @@ -74,9 +77,16 @@ extern "C" NOT_IMPLEMENTED("ftell"); } - size_t fwrite(const void*, size_t, size_t, FILE*) + size_t fwrite(const void* buf, size_t size, size_t nmemb, FILE* stream) { - NOT_IMPLEMENTED("fwrite"); + ssize_t status = write(stream->f_fd, buf, size * nmemb); + if (status < 0) + { + stream->f_err = 1; + return 0; + } + if (status == 0) stream->f_eof = 1; + return (size_t)status; } void setbuf(FILE*, char*)