]> git.lizzy.rs Git - rust.git/blob - src/libstd/os/raw.rs
Auto merge of #29741 - Manishearth:fix-flowgraph, r=alexcrichton
[rust.git] / src / libstd / os / raw.rs
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.
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 //! Raw OS-specific types for the current platform/architecture
12
13 #![stable(feature = "raw_os", since = "1.1.0")]
14
15 #[cfg(any(target_arch = "aarch64", target_os = "android"))]
16 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
17 #[cfg(not(any(target_arch = "aarch64", target_os = "android")))]
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;
37
38 /// Type used to construct void pointers for use with C.
39 ///
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
48 //     otherwise.
49 #[repr(u8)]
50 #[stable(feature = "raw_os", since = "1.1.0")]
51 pub enum c_void {
52     #[unstable(feature = "c_void_variant", reason = "should not have to exist",
53                issue = "0")]
54     #[doc(hidden)] __variant1,
55     #[unstable(feature = "c_void_variant", reason = "should not have to exist",
56                issue = "0")]
57     #[doc(hidden)] __variant2,
58 }
59
60 #[cfg(test)]
61 mod tests {
62     use any::TypeId;
63     use libc;
64     use mem;
65
66     macro_rules! ok {
67         ($($t:ident)*) => {$(
68             assert!(TypeId::of::<libc::$t>() == TypeId::of::<raw::$t>(),
69                     "{} is wrong", stringify!($t));
70         )*}
71     }
72
73     macro_rules! ok_size {
74         ($($t:ident)*) => {$(
75             assert!(mem::size_of::<libc::$t>() == mem::size_of::<raw::$t>(),
76                     "{} is wrong", stringify!($t));
77         )*}
78     }
79
80     #[test]
81     fn same() {
82         use os::raw;
83         ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong
84             c_longlong c_ulonglong c_float c_double);
85     }
86
87     #[cfg(unix)]
88     fn unix() {
89         {
90             use os::unix::raw;
91             ok!(uid_t gid_t dev_t ino_t mode_t nlink_t off_t blksize_t blkcnt_t);
92         }
93         {
94             use sys::platform::raw;
95             ok_size!(stat);
96         }
97     }
98
99     #[cfg(windows)]
100     fn windows() {
101         use os::windows::raw;
102     }
103 }