From e17119254b92bb5b9109ea94190a11303164cb42 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Mon, 19 Feb 2024 16:53:36 -0800 Subject: [PATCH] [libc] Add enough stubs to support new LLVM 16 sysroot time.h and wctype.h had "#error not yet implemented" in them. Now time.h is correct (though the functions are only declared), and wctype.h exists enough to define its types. Also a dlsym stub was added that just returns 0. --- src/libraries/libc/arch/amd64/libdl.cpp | 1 + src/libraries/libc/include/time.h | 41 ++++++++++++++++++- src/libraries/libc/include/wchar.h | 4 -- src/libraries/libc/include/wctype.h | 5 ++- src/libraries/libc/stdlib/dlmalloc.cpp | 2 + .../libc_free/include/__j6libc/wchar_t.h | 4 ++ 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/libraries/libc/arch/amd64/libdl.cpp b/src/libraries/libc/arch/amd64/libdl.cpp index 118d9a6..ab41471 100644 --- a/src/libraries/libc/arch/amd64/libdl.cpp +++ b/src/libraries/libc/arch/amd64/libdl.cpp @@ -4,4 +4,5 @@ extern "C" { // we have a real libdl int dladdr(const void *, void *) { return 0; } int dl_iterate_phdr(void *, void *) { return 0; } + int dlsym(void *, const char *) { return 0; } } diff --git a/src/libraries/libc/include/time.h b/src/libraries/libc/include/time.h index cf45619..7b207cf 100644 --- a/src/libraries/libc/include/time.h +++ b/src/libraries/libc/include/time.h @@ -10,4 +10,43 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#error time.h is not yet implemented. +#include <__j6libc/null.h> +#include <__j6libc/size_t.h> +#include + +#define CLOCKS_PER_SEC 1 +#define TIME_UTC 0 + +typedef int64_t clock_t; +typedef int64_t time_t; + +struct timespec +{ + time_t tv_sec; + long tv_nsec; +}; + +struct tm +{ + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_yday; + int tm_isdst; +}; + +clock_t clock(void); +double difftime(time_t t1, time_t t0); +time_t mktime(struct tm *timeptr); +time_t time(time_t *timer); +int timespec_get(struct timespec *ts, int base); + +char *asctime(const struct tm *timeptr); +char *ctime(const time_t *timer); +struct tm *gmtime(const time_t *timer); +struct tm *localtime(const time_t *timer); +size_t strftime(char *s, size_t maxsize, const char *fmt, const struct tm *timeptr); diff --git a/src/libraries/libc/include/wchar.h b/src/libraries/libc/include/wchar.h index 8bf424c..d317f52 100644 --- a/src/libraries/libc/include/wchar.h +++ b/src/libraries/libc/include/wchar.h @@ -17,10 +17,6 @@ #include <__j6libc/wchar_t.h> #include -typedef unsigned int wint_t; - -#define WEOF ((wint_t)-1) - struct tm; typedef struct { diff --git a/src/libraries/libc/include/wctype.h b/src/libraries/libc/include/wctype.h index d74eab5..b98ad98 100644 --- a/src/libraries/libc/include/wctype.h +++ b/src/libraries/libc/include/wctype.h @@ -10,4 +10,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#error wctype.h is not yet implemented. +#include <__j6libc/wchar_t.h> + +typedef int wctrans_t; +typedef int wctype_t; diff --git a/src/libraries/libc/stdlib/dlmalloc.cpp b/src/libraries/libc/stdlib/dlmalloc.cpp index b3d8bb9..644f7b8 100644 --- a/src/libraries/libc/stdlib/dlmalloc.cpp +++ b/src/libraries/libc/stdlib/dlmalloc.cpp @@ -5420,6 +5420,8 @@ void* dlrealloc_in_place(void* oldmem, size_t bytes) { return mem; } +void* aligned_alloc(size_t alignment, size_t size) { return dlmemalign(alignment, size); } + void* dlmemalign(size_t alignment, size_t bytes) { if (alignment <= MALLOC_ALIGNMENT) { return dlmalloc(bytes); diff --git a/src/libraries/libc_free/include/__j6libc/wchar_t.h b/src/libraries/libc_free/include/__j6libc/wchar_t.h index 4358a5b..e5093c7 100644 --- a/src/libraries/libc_free/include/__j6libc/wchar_t.h +++ b/src/libraries/libc_free/include/__j6libc/wchar_t.h @@ -14,5 +14,9 @@ typedef __WCHAR_TYPE__ wchar_t; #endif +typedef unsigned int wint_t; + +#define WEOF ((wint_t)-1) + #define WCHAR_MAX __WCHAR_MAX__ #define WCHAR_MIN ((-__WCHAR_MAX__) - 1)