Преглед на файлове

Fix stdlib div functions, add _Exit

Jeremy Soller преди 6 години
родител
ревизия
a8f3608f3c
променени са 6 файла, в които са добавени 36 реда и са изтрити 1 реда
  1. 1 1
      src/header/stdlib/cbindgen.toml
  2. 10 0
      src/header/stdlib/mod.rs
  3. 1 0
      tests/Makefile
  4. 0 0
      tests/expected/stdlib/div.stderr
  5. 0 0
      tests/expected/stdlib/div.stdout
  6. 24 0
      tests/stdlib/div.c

+ 1 - 1
src/header/stdlib/cbindgen.toml

@@ -2,7 +2,7 @@ sys_includes = ["stddef.h", "alloca.h"]
 include_guard = "_STDLIB_H"
 trailer = "#include <bits/stdlib.h>"
 language = "C"
-style = "Tag"
+style = "Type"
 
 [enum]
 prefix_with_name = true

+ 10 - 0
src/header/stdlib/mod.rs

@@ -33,6 +33,11 @@ pub const MB_LEN_MAX: c_int = 4;
 static mut ATEXIT_FUNCS: [Option<extern "C" fn()>; 32] = [None; 32];
 static mut RNG: Option<XorShiftRng> = 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
 }

+ 1 - 0
tests/Makefile

@@ -38,6 +38,7 @@ EXPECT_BINS=\
 	stdlib/a64l \
 	stdlib/atof \
 	stdlib/atoi \
+	stdlib/div \
 	stdlib/env \
 	stdlib/mkostemps \
 	stdlib/rand \

+ 0 - 0
tests/expected/stdlib/div.stderr


+ 0 - 0
tests/expected/stdlib/div.stdout


+ 24 - 0
tests/stdlib/div.c

@@ -0,0 +1,24 @@
+#include <stdlib.h>
+         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;
+}
+