From a8f3608f3c26a73d31ab5dc77c89efbce5a14be3 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 14 Dec 2018 13:41:22 -0700 Subject: [PATCH] Fix stdlib div functions, add _Exit --- src/header/stdlib/cbindgen.toml | 2 +- src/header/stdlib/mod.rs | 10 ++++++++++ tests/Makefile | 1 + tests/expected/stdlib/div.stderr | 0 tests/expected/stdlib/div.stdout | 0 tests/stdlib/div.c | 24 ++++++++++++++++++++++++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/expected/stdlib/div.stderr create mode 100644 tests/expected/stdlib/div.stdout create mode 100644 tests/stdlib/div.c diff --git a/src/header/stdlib/cbindgen.toml b/src/header/stdlib/cbindgen.toml index bd8618caa5..278c2eebac 100644 --- a/src/header/stdlib/cbindgen.toml +++ b/src/header/stdlib/cbindgen.toml @@ -2,7 +2,7 @@ sys_includes = ["stddef.h", "alloca.h"] include_guard = "_STDLIB_H" trailer = "#include " language = "C" -style = "Tag" +style = "Type" [enum] prefix_with_name = true diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index d7070da2cf..bf00d54ea0 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -33,6 +33,11 @@ pub const MB_LEN_MAX: c_int = 4; static mut ATEXIT_FUNCS: [Option; 32] = [None; 32]; static mut RNG: Option = None; +#[no_mangle] +pub extern "C" fn _Exit(status: c_int) { + unistd::_exit(status); +} + #[no_mangle] pub unsafe extern "C" fn a64l(s: *const c_char) -> c_long { if s.is_null() { @@ -144,6 +149,11 @@ pub extern "C" fn atol(s: *const c_char) -> c_long { dec_num_from_ascii!(s, c_long) } +#[no_mangle] +pub extern "C" fn atoll(s: *const c_char) -> c_longlong { + dec_num_from_ascii!(s, c_longlong) +} + unsafe extern "C" fn void_cmp(a: *const c_void, b: *const c_void) -> c_int { *(a as *const i32) - *(b as *const i32) as c_int } diff --git a/tests/Makefile b/tests/Makefile index 163a50410e..efdf091019 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -38,6 +38,7 @@ EXPECT_BINS=\ stdlib/a64l \ stdlib/atof \ stdlib/atoi \ + stdlib/div \ stdlib/env \ stdlib/mkostemps \ stdlib/rand \ diff --git a/tests/expected/stdlib/div.stderr b/tests/expected/stdlib/div.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/stdlib/div.stdout b/tests/expected/stdlib/div.stdout new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/stdlib/div.c b/tests/stdlib/div.c new file mode 100644 index 0000000000..22acb9176a --- /dev/null +++ b/tests/stdlib/div.c @@ -0,0 +1,24 @@ +#include + volatile float f; + volatile long double ld; + volatile unsigned long long ll; + lldiv_t mydivt; +int +main () +{ +char* tmp; + f = strtof("gnu", &tmp); + ld = strtold("gnu", &tmp); + ll = strtoll("gnu", &tmp, 10); + ll = strtoull("gnu", &tmp, 10); + ll = llabs(10); + mydivt = lldiv(10,1); + ll = mydivt.quot; + ll = mydivt.rem; + ll = atoll("10"); + _Exit(0); + + ; + return 0; +} +