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