Files
RedBear-OS/local/patches/relibc/P0-strtold-cpp-linkage-and-compat.patch

107 lines
3.3 KiB
Diff

diff --git a/include/features.h b/include/features.h
index 6d0a0d6..d14516f 100644
--- a/include/features.h
+++ b/include/features.h
@@ -14,6 +14,11 @@
#define __RELIBC__MAJOR 0
#define __RELIBC__MINOR 2
+#ifndef __RELIBC_C_LONGDOUBLE_DEFINED
+#define __RELIBC_C_LONGDOUBLE_DEFINED 1
+typedef long double c_longdouble;
+#endif
+
/*
* Sources:
* https://en.cppreference.com/w/c/language/attributes
diff --git a/include/stddef.h b/include/stddef.h
index 334267f..bb58d55 100644
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -11,6 +11,11 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef long unsigned int size_t;
+#ifndef __RELIBC_C_LONGDOUBLE_DEFINED
+#define __RELIBC_C_LONGDOUBLE_DEFINED 1
+typedef long double c_longdouble;
+#endif
+
typedef struct { long long __ll; long double __ld; } max_align_t;
#define offsetof(type, member) __builtin_offsetof(type, member)
diff --git a/src/c/stdlib.c b/src/c/stdlib.c
index 62e9810..4040655 100644
--- a/src/c/stdlib.c
+++ b/src/c/stdlib.c
@@ -1,9 +1,5 @@
double strtod(const char *nptr, char **endptr);
-long double strtold(const char *nptr, char **endptr) {
- return (long double)strtod(nptr, endptr);
-}
-
double relibc_ldtod(const long double* val) {
return (double)(*val);
}
diff --git a/src/header/stdlib/cbindgen.toml b/src/header/stdlib/cbindgen.toml
index c105da5..d5bcb23 100644
--- a/src/header/stdlib/cbindgen.toml
+++ b/src/header/stdlib/cbindgen.toml
@@ -1,21 +1,5 @@
sys_includes = ["stddef.h", "alloca.h", "wchar.h", "features.h"]
include_guard = "_RELIBC_STDLIB_H"
-trailer = """
-#ifndef _RELIBC_STDLIB_EXTRA_H
-#define _RELIBC_STDLIB_EXTRA_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-long double strtold(const char *nptr, char **endptr);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-"""
language = "C"
style = "Type"
no_includes = true
diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs
index 423ee95..43bc912 100644
--- a/src/header/stdlib/mod.rs
+++ b/src/header/stdlib/mod.rs
@@ -31,7 +31,7 @@ use crate::{
platform::{
self, Pal, Sys,
types::{
- c_char, c_double, c_float, c_int, c_long, c_longlong, c_uint, c_ulong, c_ulonglong,
+ c_char, c_double, c_float, c_int, c_long, c_longdouble, c_longlong, c_uint, c_ulong, c_ulonglong,
c_ushort, c_void, size_t, ssize_t, uintptr_t, wchar_t,
},
},
@@ -1490,12 +1494,19 @@ pub unsafe extern "C" fn strtod(s: *const c_char, endptr: *mut *mut c_char) -> c
strto_float_impl!(c_double, s, endptr)
}
-/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtod.html>.
+/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtof.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn strtof(s: *const c_char, endptr: *mut *mut c_char) -> c_float {
strto_float_impl!(c_float, s, endptr)
}
+/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtod.html>.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn strtold(s: *const c_char, endptr: *mut *mut c_char) -> c_longdouble {
+ let result = unsafe { strtod(s, core::ptr::null_mut()) };
+ result as c_longdouble
+}
+
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtol.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn strtol(s: *const c_char, endptr: *mut *mut c_char, base: c_int) -> c_long {