]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/c-stack-returning-int64.rs
e91c11f5cd0a703eea86f5080aec6051d1c52bf9
[rust.git] / src / test / run-pass / c-stack-returning-int64.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use std::str;
12
13 mod libc {
14     #[abi = "cdecl"]
15     #[nolink]
16     extern {
17         pub fn atol(x: *u8) -> int;
18         pub fn atoll(x: *u8) -> i64;
19     }
20 }
21
22 fn atol(s: ~str) -> int {
23     s.to_c_str().with_ref(|x| unsafe { libc::atol(x as *u8) })
24 }
25
26 fn atoll(s: ~str) -> i64 {
27     s.to_c_str().with_ref(|x| unsafe { libc::atoll(x as *u8) })
28 }
29
30 pub fn main() {
31     unsafe {
32         assert_eq!(atol(~"1024") * 10, atol(~"10240"));
33         assert!((atoll(~"11111111111111111") * 10i64)
34             == atoll(~"111111111111111110"));
35     }
36 }