]> git.lizzy.rs Git - rust.git/blob - src/libstd/os/raw.rs
add aarch64-unknown-openbsd support
[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 use fmt;
16
17 #[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
18                                        target_arch = "arm",
19                                        target_arch = "powerpc",
20                                        target_arch = "powerpc64",
21                                        target_arch = "s390x")),
22           all(target_os = "android", any(target_arch = "aarch64",
23                                          target_arch = "arm")),
24           all(target_os = "l4re", target_arch = "x86_64"),
25           all(target_os = "openbsd", target_arch = "aarch64"),
26           all(target_os = "fuchsia", target_arch = "aarch64")))]
27 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
28 #[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
29                                            target_arch = "arm",
30                                            target_arch = "powerpc",
31                                            target_arch = "powerpc64",
32                                            target_arch = "s390x")),
33               all(target_os = "android", any(target_arch = "aarch64",
34                                              target_arch = "arm")),
35               all(target_os = "l4re", target_arch = "x86_64"),
36               all(target_os = "openbsd", target_arch = "aarch64"),
37               all(target_os = "fuchsia", target_arch = "aarch64"))))]
38 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
39 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
40 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
41 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
42 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
43 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
44 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
45 #[cfg(any(target_pointer_width = "32", windows))]
46 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
47 #[cfg(any(target_pointer_width = "32", windows))]
48 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
49 #[cfg(all(target_pointer_width = "64", not(windows)))]
50 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
51 #[cfg(all(target_pointer_width = "64", not(windows)))]
52 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
53 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
54 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
55 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
56 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
57
58 /// Type used to construct void pointers for use with C.
59 ///
60 /// This type is only useful as a pointer target. Do not use it as a
61 /// return type for FFI functions which have the `void` return type in
62 /// C. Use the unit type `()` or omit the return type instead.
63 // NB: For LLVM to recognize the void pointer type and by extension
64 //     functions like malloc(), we need to have it represented as i8* in
65 //     LLVM bitcode. The enum used here ensures this and prevents misuse
66 //     of the "raw" type by only having private variants.. We need two
67 //     variants, because the compiler complains about the repr attribute
68 //     otherwise.
69 #[repr(u8)]
70 #[stable(feature = "raw_os", since = "1.1.0")]
71 pub enum c_void {
72     #[unstable(feature = "c_void_variant", reason = "should not have to exist",
73                issue = "0")]
74     #[doc(hidden)] __variant1,
75     #[unstable(feature = "c_void_variant", reason = "should not have to exist",
76                issue = "0")]
77     #[doc(hidden)] __variant2,
78 }
79
80 #[stable(feature = "std_debug", since = "1.16.0")]
81 impl fmt::Debug for c_void {
82     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
83         f.pad("c_void")
84     }
85 }
86
87 #[cfg(test)]
88 #[allow(unused_imports)]
89 mod tests {
90     use any::TypeId;
91     use libc;
92     use mem;
93
94     macro_rules! ok {
95         ($($t:ident)*) => {$(
96             assert!(TypeId::of::<libc::$t>() == TypeId::of::<raw::$t>(),
97                     "{} is wrong", stringify!($t));
98         )*}
99     }
100
101     #[test]
102     fn same() {
103         use os::raw;
104         ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong
105             c_longlong c_ulonglong c_float c_double);
106     }
107 }