2019-07-27 00:54:25 +03:00
|
|
|
//@ run-pass
|
2019-04-24 09:26:33 -07:00
|
|
|
//@ ignore-sgx no libc
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2014-11-25 13:28:35 -08:00
|
|
|
use std::ffi::CString;
|
2014-12-22 09:04:23 -08:00
|
|
|
|
2014-02-26 12:58:41 -05:00
|
|
|
mod mlibc {
|
2024-04-14 16:23:07 -04:00
|
|
|
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;
|
2013-03-05 14:42:58 -08:00
|
|
|
}
|
2011-10-24 17:03:18 -07:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
fn atol(s: String) -> isize {
|
2015-02-18 14:39:37 -08:00
|
|
|
let c = CString::new(s).unwrap();
|
2015-03-25 17:06:52 -07:00
|
|
|
unsafe { mlibc::atol(c.as_ptr()) as isize }
|
2011-10-24 17:03:18 -07:00
|
|
|
}
|
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
fn atoll(s: String) -> i64 {
|
2015-02-18 14:39:37 -08:00
|
|
|
let c = CString::new(s).unwrap();
|
2014-11-25 13:28:35 -08:00
|
|
|
unsafe { mlibc::atoll(c.as_ptr()) as i64 }
|
2011-10-24 17:03:18 -07:00
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2014-05-25 03:17:19 -07:00
|
|
|
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
|
|
|
}
|