]> git.lizzy.rs Git - rust.git/blob - src/libstd/os/raw/mod.rs
Rollup merge of #60938 - jonas-schievink:doc-include-paths, r=petrochenkov
[rust.git] / src / libstd / os / raw / mod.rs
1 //! Platform-specific types, as defined by C.
2 //!
3 //! Code that interacts via FFI will almost certainly be using the
4 //! base types provided by C, which aren't nearly as nicely defined
5 //! as Rust's primitive types. This module provides types which will
6 //! match those defined by C, so that code that interacts with C will
7 //! refer to the correct types.
8
9 #![stable(feature = "raw_os", since = "1.1.0")]
10
11 #[cfg_attr(bootstrap, doc(include = "os/raw/char.md"))]
12 #[cfg_attr(not(bootstrap), doc(include = "char.md"))]
13 #[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
14                                        target_arch = "arm",
15                                        target_arch = "hexagon",
16                                        target_arch = "powerpc",
17                                        target_arch = "powerpc64",
18                                        target_arch = "s390x")),
19           all(target_os = "android", any(target_arch = "aarch64",
20                                          target_arch = "arm")),
21           all(target_os = "l4re", target_arch = "x86_64"),
22           all(target_os = "freebsd", any(target_arch = "aarch64",
23                                          target_arch = "arm",
24                                          target_arch = "powerpc",
25                                          target_arch = "powerpc64")),
26           all(target_os = "netbsd", any(target_arch = "aarch64",
27                                         target_arch = "arm",
28                                         target_arch = "powerpc")),
29           all(target_os = "openbsd", target_arch = "aarch64"),
30           all(target_os = "vxworks", any(target_arch = "aarch64",
31                                          target_arch = "arm",
32                                          target_arch = "powerpc64",
33                                          target_arch = "powerpc")),
34           all(target_os = "fuchsia", target_arch = "aarch64")))]
35 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
36 #[cfg_attr(bootstrap, doc(include = "os/raw/char.md"))]
37 #[cfg_attr(not(bootstrap), doc(include = "char.md"))]
38 #[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
39                                            target_arch = "arm",
40                                            target_arch = "hexagon",
41                                            target_arch = "powerpc",
42                                            target_arch = "powerpc64",
43                                            target_arch = "s390x")),
44               all(target_os = "android", any(target_arch = "aarch64",
45                                              target_arch = "arm")),
46               all(target_os = "l4re", target_arch = "x86_64"),
47               all(target_os = "freebsd", any(target_arch = "aarch64",
48                                              target_arch = "arm",
49                                              target_arch = "powerpc",
50                                              target_arch = "powerpc64")),
51               all(target_os = "netbsd", any(target_arch = "aarch64",
52                                             target_arch = "arm",
53                                             target_arch = "powerpc")),
54               all(target_os = "openbsd", target_arch = "aarch64"),
55               all(target_os = "vxworks", any(target_arch = "aarch64",
56                                              target_arch = "arm",
57                                              target_arch = "powerpc64",
58                                              target_arch = "powerpc")),
59               all(target_os = "fuchsia", target_arch = "aarch64"))))]
60 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
61 #[cfg_attr(bootstrap, doc(include = "os/raw/schar.md"))]
62 #[cfg_attr(not(bootstrap), doc(include = "schar.md"))]
63 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
64 #[cfg_attr(bootstrap, doc(include = "os/raw/uchar.md"))]
65 #[cfg_attr(not(bootstrap), doc(include = "uchar.md"))]
66 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
67 #[cfg_attr(bootstrap, doc(include = "os/raw/short.md"))]
68 #[cfg_attr(not(bootstrap), doc(include = "short.md"))]
69 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
70 #[cfg_attr(bootstrap, doc(include = "os/raw/ushort.md"))]
71 #[cfg_attr(not(bootstrap), doc(include = "ushort.md"))]
72 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
73 #[cfg_attr(bootstrap, doc(include = "os/raw/int.md"))]
74 #[cfg_attr(not(bootstrap), doc(include = "int.md"))]
75 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
76 #[cfg_attr(bootstrap, doc(include = "os/raw/uint.md"))]
77 #[cfg_attr(not(bootstrap), doc(include = "uint.md"))]
78 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
79 #[cfg_attr(bootstrap, doc(include = "os/raw/long.md"))]
80 #[cfg_attr(not(bootstrap), doc(include = "long.md"))]
81 #[cfg(any(target_pointer_width = "32", windows))]
82 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
83 #[cfg_attr(bootstrap, doc(include = "os/raw/ulong.md"))]
84 #[cfg_attr(not(bootstrap), doc(include = "ulong.md"))]
85 #[cfg(any(target_pointer_width = "32", windows))]
86 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
87 #[cfg_attr(bootstrap, doc(include = "os/raw/long.md"))]
88 #[cfg_attr(not(bootstrap), doc(include = "long.md"))]
89 #[cfg(all(target_pointer_width = "64", not(windows)))]
90 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
91 #[cfg_attr(bootstrap, doc(include = "os/raw/ulong.md"))]
92 #[cfg_attr(not(bootstrap), doc(include = "ulong.md"))]
93 #[cfg(all(target_pointer_width = "64", not(windows)))]
94 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
95 #[cfg_attr(bootstrap, doc(include = "os/raw/longlong.md"))]
96 #[cfg_attr(not(bootstrap), doc(include = "longlong.md"))]
97 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
98 #[cfg_attr(bootstrap, doc(include = "os/raw/ulonglong.md"))]
99 #[cfg_attr(not(bootstrap), doc(include = "ulonglong.md"))]
100 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
101 #[cfg_attr(bootstrap, doc(include = "os/raw/float.md"))]
102 #[cfg_attr(not(bootstrap), doc(include = "float.md"))]
103 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
104 #[cfg_attr(bootstrap, doc(include = "os/raw/double.md"))]
105 #[cfg_attr(not(bootstrap), doc(include = "double.md"))]
106 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
107
108 #[stable(feature = "raw_os", since = "1.1.0")]
109 #[doc(no_inline)]
110 pub use core::ffi::c_void;
111
112 #[cfg(test)]
113 #[allow(unused_imports)]
114 mod tests {
115     use crate::any::TypeId;
116     use crate::mem;
117
118     macro_rules! ok {
119         ($($t:ident)*) => {$(
120             assert!(TypeId::of::<libc::$t>() == TypeId::of::<raw::$t>(),
121                     "{} is wrong", stringify!($t));
122         )*}
123     }
124
125     #[test]
126     fn same() {
127         use crate::os::raw;
128         ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong
129             c_longlong c_ulonglong c_float c_double);
130     }
131 }