]> git.lizzy.rs Git - rust.git/blob - src/test/ui/abi/c-stack-returning-int64.rs
Rollup merge of #92899 - cameron1024:zip-docs, r=dtolnay
[rust.git] / src / test / ui / abi / c-stack-returning-int64.rs
1 // run-pass
2 // ignore-wasm32-bare no libc to test with
3 // ignore-sgx no libc
4
5 #![feature(rustc_private)]
6
7 extern crate libc;
8
9 use std::ffi::CString;
10
11 mod mlibc {
12     use libc::{c_char, c_long, c_longlong};
13
14     extern "C" {
15         pub fn atol(x: *const c_char) -> c_long;
16         pub fn atoll(x: *const c_char) -> c_longlong;
17     }
18 }
19
20 fn atol(s: String) -> isize {
21     let c = CString::new(s).unwrap();
22     unsafe { mlibc::atol(c.as_ptr()) as isize }
23 }
24
25 fn atoll(s: String) -> i64 {
26     let c = CString::new(s).unwrap();
27     unsafe { mlibc::atoll(c.as_ptr()) as i64 }
28 }
29
30 pub fn main() {
31     assert_eq!(atol("1024".to_string()) * 10, atol("10240".to_string()));
32     assert_eq!(
33         (atoll("11111111111111111".to_string()) * 10),
34         atoll("111111111111111110".to_string())
35     );
36 }