os-rust/tests/ui/abi/c-stack-returning-int64.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
705 B
Rust
Raw Normal View History

//@ run-pass
2019-04-24 09:26:33 -07:00
//@ ignore-sgx no libc
use std::ffi::CString;
2014-02-26 12:58:41 -05:00
mod mlibc {
use std::ffi::{c_char, c_long, c_longlong};
2013-08-17 08:37:42 -07:00
2020-09-01 17:12:52 -04:00
extern "C" {
2014-06-25 12:47:34 -07:00
pub fn atol(x: *const c_char) -> c_long;
pub fn atoll(x: *const c_char) -> c_longlong;
}
2011-10-24 17:03:18 -07:00
}
fn atol(s: String) -> isize {
2015-02-18 14:39:37 -08:00
let c = CString::new(s).unwrap();
unsafe { mlibc::atol(c.as_ptr()) as isize }
2011-10-24 17:03:18 -07:00
}
fn atoll(s: String) -> i64 {
2015-02-18 14:39:37 -08:00
let c = CString::new(s).unwrap();
unsafe { mlibc::atoll(c.as_ptr()) as i64 }
2011-10-24 17:03:18 -07:00
}
pub fn main() {
assert_eq!(atol("1024".to_string()) * 10, atol("10240".to_string()));
2020-09-01 17:12:52 -04:00
assert_eq!(
(atoll("11111111111111111".to_string()) * 10),
atoll("111111111111111110".to_string())
);
2011-10-24 17:03:18 -07:00
}