From 53635c399061f9a37095bf9557cb9d3dbc6135b7 Mon Sep 17 00:00:00 2001 From: Matheus Date: Fri, 24 Apr 2026 00:26:09 -0300 Subject: [PATCH] mlibc: backport inttypes fixes --- patches/mlibc/jinx-working-patch.patch | 125 ++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 4 deletions(-) diff --git a/patches/mlibc/jinx-working-patch.patch b/patches/mlibc/jinx-working-patch.patch index fbc266ca..3b74360f 100644 --- a/patches/mlibc/jinx-working-patch.patch +++ b/patches/mlibc/jinx-working-patch.patch @@ -4,13 +4,130 @@ index 8edf44b..c13a2c1 100644 +++ mlibc-workdir/options/ansi/generic/time.cpp @@ -598,7 +598,7 @@ int nanosleep(const struct timespec *req, struct timespec *rem) { int e = mlibc::sys_sleep(&tmp.tv_sec, &tmp.tv_nsec); - if (!e) - return 0; + if (!e) + return 0; - else if (e == EINTR) + else if (e == EINTR && rem) - *rem = tmp; + *rem = tmp; + + errno = e; +diff --git mlibc-clean/options/internal/include/mlibc/strtol.hpp mlibc-workdir/options/internal/include/mlibc/strtol.hpp +index a77d9d0..9f3fe08 100644 +--- mlibc-clean/options/internal/include/mlibc/strtol.hpp ++++ mlibc-workdir/options/internal/include/mlibc/strtol.hpp +@@ -4,6 +4,7 @@ + #include + #include + #include ++#include + #include - errno = e; + namespace mlibc { +diff --git mlibc-clean/options/ansi/generic/inttypes.cpp mlibc-workdir/options/ansi/generic/inttypes.cpp +index 6478680..1ca08f4 100644 +--- mlibc-clean/options/ansi/generic/inttypes.cpp ++++ mlibc-workdir/options/ansi/generic/inttypes.cpp +@@ -1,11 +1,7 @@ +- +-#include + #include +-#include ++#include + + #include + #include +- +-static const char *__mlibc_digits = "0123456789abcdefghijklmnopqrstuvwxyz"; + + intmax_t imaxabs(intmax_t num) { +@@ -16,83 +14,17 @@ imaxdiv_t imaxdiv(intmax_t number, intmax_t denom) { + return r; + } + +-template T strtoxmax(const char *it, char **out, int base) { +- T v = 0; +- bool negate = false; +- const unsigned char *s = (const unsigned char *)it; +- int c; +- +- if(std::is_signed_v) { +- if(*s == '+') { +- s++; +- }else if(*s == '-') { +- negate = true; +- s++; +- } +- } +- +- do { +- c = *s++; +- } while (isspace(c)); +- if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { +- c = s[1]; +- s += 2; +- base = 16; +- } +- if (base == 0) +- base = c == '0' ? 8 : 10; +- +- if(base == 8) { +- if(*it != 0) +- goto parse_digits; +- it++; +- }else if(base == 16) { +- if(*it != 0) +- goto parse_digits; +- it++; +- if(*it != 'x' && *it != 'X') +- goto parse_digits; +- it++; +- } +- +-parse_digits: +- while(*it) { +- if(isspace(*it)) { +- it++; +- continue; +- } +- +- __ensure(base <= 10); // TODO: For base > 10 we need to implement tolower(). +- //auto c = strchr(__mlibc_digits, tolower(*it)); +- auto c = strchr(__mlibc_digits, *it); +- if(!c || (c - __mlibc_digits) >= base) +- break; +- v = v * base + (c - __mlibc_digits); +- it++; +- } +- +- if(std::is_signed_v) { +- if(negate) +- v = -v; +- } +- +- if(out) +- *out = const_cast(it); +- return v; +-} +- +-intmax_t strtoimax(const char *it, char **out, int base) { +- // TODO: This function has to check for overflow! +- return strtoxmax(it, out, base); ++intmax_t strtoimax(const char *string, char **end, int base) { ++ return mlibc::stringToInteger(string, end, base); + } +-uintmax_t strtoumax(const char *it, char **out, int base) { +- return strtoxmax(it, out, base); ++uintmax_t strtoumax(const char *string, char **end, int base) { ++ return mlibc::stringToInteger(string, end, base); + } + intmax_t wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int) { + __ensure(!"Not implemented"); + __builtin_unreachable(); + } + uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int) { + __ensure(!"Not implemented"); + __builtin_unreachable(); + } diff --git mlibc-clean/options/ansi/generic/wchar.cpp mlibc-workdir/options/ansi/generic/wchar.cpp index b44ebc2..9339316 100644 --- mlibc-clean/options/ansi/generic/wchar.cpp