1 // Copyright 2015 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.
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.
11 //! Raw OS-specific types for the current platform/architecture
13 #![stable(feature = "raw_os", since = "1.1.0")]
15 #[cfg(target_arch = "aarch64")]
16 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
17 #[cfg(not(target_arch = "aarch64"))]
18 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
19 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
20 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
21 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
22 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
23 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
24 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
25 #[cfg(any(target_pointer_width = "32", windows))]
26 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
27 #[cfg(any(target_pointer_width = "32", windows))]
28 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
29 #[cfg(all(target_pointer_width = "64", not(windows)))]
30 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
31 #[cfg(all(target_pointer_width = "64", not(windows)))]
32 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
33 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
34 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
35 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
36 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
38 /// Type used to construct void pointers for use with C.
40 /// This type is only useful as a pointer target. Do not use it as a
41 /// return type for FFI functions which have the `void` return type in
42 /// C. Use the unit type `()` or omit the return type instead.
43 // NB: For LLVM to recognize the void pointer type and by extension
44 // functions like malloc(), we need to have it represented as i8* in
45 // LLVM bitcode. The enum used here ensures this and prevents misuse
46 // of the "raw" type by only having private variants.. We need two
47 // variants, because the compiler complains about the repr attribute
50 #[stable(feature = "raw_os", since = "1.1.0")]
52 #[unstable(feature = "c_void_variant", reason = "should not have to exist")]
53 #[doc(hidden)] __variant1,
54 #[unstable(feature = "c_void_variant", reason = "should not have to exist")]
55 #[doc(hidden)] __variant2,
66 assert!(TypeId::of::<libc::$t>() == TypeId::of::<raw::$t>(),
67 "{} is wrong", stringify!($t));
71 macro_rules! ok_size {
73 assert!(mem::size_of::<libc::$t>() == mem::size_of::<raw::$t>(),
74 "{} is wrong", stringify!($t));
81 ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong
82 c_longlong c_ulonglong c_float c_double);
89 ok!(uid_t gid_t dev_t ino_t mode_t nlink_t off_t blksize_t blkcnt_t);
92 use sys::platform::raw;