Convert strtold to Rust

This commit is contained in:
Wildan M
2025-12-25 16:11:36 +07:00
parent d82db81ae2
commit 08485648f6
6 changed files with 10 additions and 42 deletions
-36
View File
@@ -1,36 +0,0 @@
extern crate cc;
use std::{env, fs};
fn get_target() -> String {
env::var("TARGET").unwrap_or(
option_env!("TARGET").map_or("x86_64-unknown-redox".to_string(), |x| x.to_string()),
)
}
fn main() {
let _crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
let target = get_target();
println!("cargo:rerun-if-changed=src/c");
let mut cc_builder = &mut cc::Build::new();
cc_builder = cc_builder.flag("-nostdinc").flag("-nostdlib");
if target.starts_with("aarch64") {
cc_builder = cc_builder.flag("-mno-outline-atomics")
}
cc_builder
.flag("-fno-stack-protector")
.flag("-Wno-expansion-to-defined")
.files(
fs::read_dir("src/c")
.expect("src/c directory missing")
.map(|res| res.expect("read_dir error").path()),
)
.compile("relibc_c");
println!("cargo:rustc-link-lib=static=relibc_c");
}
-5
View File
@@ -1,5 +0,0 @@
double strtod(const char *nptr, char **endptr);
long double strtold(const char *nptr, char **endptr) {
return (long double)strtod(nptr, endptr);
}
+3
View File
@@ -6,5 +6,8 @@ style = "Type"
no_includes = true
cpp_compat = true
[export.rename]
"c_longdouble" = "long double"
[enum]
prefix_with_name = true
+5 -1
View File
@@ -1479,7 +1479,11 @@ pub unsafe extern "C" fn strtol(s: *const c_char, endptr: *mut *mut c_char, base
)
}
// TODO: strtold(), when long double is available
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtold.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn strtold(s: *const c_char, endptr: *mut *mut c_char) -> c_longdouble {
strto_float_impl!(c_longdouble, s, endptr)
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtol.html>.
#[unsafe(no_mangle)]
+1
View File
@@ -16,6 +16,7 @@
#![feature(asm_const)]
#![feature(c_variadic)]
#![feature(core_intrinsics)]
#![feature(f128)]
#![feature(macro_derive)]
#![feature(maybe_uninit_slice)]
#![feature(lang_items)]
+1
View File
@@ -31,6 +31,7 @@ pub type c_int = i32;
pub type c_uint = u32;
pub type c_float = f32;
pub type c_double = f64;
pub type c_longdouble = f128;
pub type c_longlong = i64;
pub type c_ulonglong = u64;
pub type intmax_t = i64;