diff options
author | Oxore <oxore@protonmail.com> | 2023-03-07 16:05:46 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2023-03-07 17:58:42 +0300 |
commit | 5f7d4d6e9f47d328e7c4ef71030bdc9e34892798 (patch) | |
tree | 1f4dbecf6b27e268c0590404399c5d5fd91965d0 /app/platform/retarget.cpp | |
parent | e4a9be2a4f68781d318770296a50f4823c419805 (diff) |
Get rid of libc, take just parts of it
Diffstat (limited to 'app/platform/retarget.cpp')
-rw-r--r-- | app/platform/retarget.cpp | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/app/platform/retarget.cpp b/app/platform/retarget.cpp index 52be99f..524840e 100644 --- a/app/platform/retarget.cpp +++ b/app/platform/retarget.cpp @@ -1,9 +1,22 @@ -extern "C" void vApplicationMallocFailedHook(void) +#include "unistd.h" +#include <cassert> +#include <cstdio> +#include <cstdlib> +#include <cerrno> +#include "third_party/printf/printf.h" + +#ifdef errno +#undef errno +#endif + +int errno{}; + +extern "C" [[noreturn]] void vApplicationMallocFailedHook(void) { for (;;); } -extern "C" void vApplicationStackOverflowHook(void *task_handle, char *task_name) +extern "C" [[noreturn]] void vApplicationStackOverflowHook(void *task_handle, char *task_name) { (void) task_handle; (void) task_name; @@ -13,3 +26,68 @@ extern "C" void vApplicationStackOverflowHook(void *task_handle, char *task_name extern "C" void vApplicationIdleHook(void) { } + +extern "C" [[noreturn]] void _exit(int __status) +{ + (void) __status; + for (;;); +} + +/* func can be NULL, in which case no function information is given. */ +extern "C" [[noreturn]] void __assert_func ( + const char *file, int line, const char *func, const char *failedexpr) +{ + dprintf(STDERR_FILENO, + "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", + failedexpr, file, line, + func ? ", function: " : "", func ? func : ""); + abort(); + /* NOTREACHED */ +} + +extern "C" ssize_t read(int fd, void *buf, size_t nbytes) +{ + (void) fd; + (void) buf; + (void) nbytes; + errno = ENOSYS; + return -1; +} + +extern "C" ssize_t write(int fd, const void *buf, size_t nbytes) +{ + (void) fd; + (void) buf; + (void) nbytes; + errno = ENOSYS; + return -1; +} + +static void dputchar2(char c, void* fd) +{ + write(reinterpret_cast<int>(fd), &c, 1); +} + +static void dputchar(char c, int fd) +{ + write(fd, &c, 1); +} + +extern "C" int dprintf(int fd, const char * format, ...) +{ + va_list args; + va_start(args, format); + const int ret = vfctprintf(dputchar2, reinterpret_cast<void *>(fd), format, args); + va_end(args); + return ret; +} + +extern "C" int vdprintf(int fd, const char * format, va_list args) +{ + return vfctprintf(dputchar2, reinterpret_cast<void *>(fd), format, args); +} + +extern "C" void putchar_(char c) +{ + dputchar(c, STDIN_FILENO); +} |