relibc/platform/types.rs
1//! C data types for this platform.
2
3// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
4// more optimization opportunities around it recognizing things like
5// malloc/free.
6/// The `void` type in C.
7#[repr(u8)]
8pub enum c_void {
9 // Two dummy variants so the #[repr] attribute can be used.
10 #[doc(hidden)]
11 __variant1,
12 #[doc(hidden)]
13 __variant2,
14}
15
16/// The `int8_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
17pub type int8_t = i8;
18/// The `int16_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
19pub type int16_t = i16;
20/// The `int32_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
21pub type int32_t = i32;
22/// The `int64_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
23pub type int64_t = i64;
24/// The `uint8_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
25pub type uint8_t = u8;
26/// The `uint16_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
27pub type uint16_t = u16;
28/// The `uint32_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
29pub type uint32_t = u32;
30/// The `uint64_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
31pub type uint64_t = u64;
32
33/// The `signed char` type in C.
34pub type c_schar = i8;
35/// The `unsigned char` type in C.
36pub type c_uchar = u8;
37/// The `short` type in C.
38pub type c_short = i16;
39/// The `unsigned short` type in C.
40pub type c_ushort = u16;
41/// The `int` type in C.
42pub type c_int = i32;
43/// The `unsigned int` type in C.
44pub type c_uint = u32;
45/// The `float` type in C.
46pub type c_float = f32;
47/// The `double` type in C.
48pub type c_double = f64;
49/// The `long long` type in C.
50pub type c_longlong = i64;
51/// The `unsigned long long` type in C.
52pub type c_ulonglong = u64;
53/// The `intmax_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
54pub type intmax_t = i64;
55/// The `uintmax_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
56pub type uintmax_t = u64;
57
58/// The `size_t` type provided in `stddef.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html>.
59pub type size_t = usize;
60/// The `ptrdiff_t` type provided in `stddef.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html>.
61pub type ptrdiff_t = isize;
62/// The `intptr_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
63pub type intptr_t = isize;
64/// The `uintptr_t` type provided in `stdint.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html>.
65pub type uintptr_t = usize;
66/// The `ssize_t` type provided in [`sys/types.h`](crate::header::sys_types).
67pub type ssize_t = isize;
68
69/// The `char` type in C.
70pub type c_char = core::ffi::c_char;
71/// The `long` type in C.
72#[cfg(target_pointer_width = "32")]
73pub type c_long = i32;
74/// The `unsigned long` type in C.
75#[cfg(target_pointer_width = "32")]
76pub type c_ulong = u32;
77/// The `long` type in C.
78#[cfg(target_pointer_width = "64")]
79pub type c_long = i64;
80/// The `unsigned long` type in C.
81#[cfg(target_pointer_width = "64")]
82pub type c_ulong = u64;
83
84/// The `wchar_t` type provided in `stddef.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html>.
85pub type wchar_t = i32;
86/// The `wint_t` type provided in [`wchar.h`](crate::header::wchar).
87pub type wint_t = u32;
88
89/// The `regoff_t` type provided in [`regex.h`](crate::header::regex).
90pub type regoff_t = size_t;
91/// The `off_t` type provided in [`sys/types.h`](crate::header::sys_types).
92pub type off_t = c_longlong;
93/// The `mode_t` type provided in [`sys/types.h`](crate::header::sys_types).
94#[cfg(target_os = "linux")]
95pub type mode_t = c_uint;
96/// The `mode_t` type provided in [`sys/types.h`](crate::header::sys_types).
97#[cfg(not(target_os = "linux"))]
98pub type mode_t = c_int;
99/// The `time_t` type provided in [`sys/types.h`](crate::header::sys_types).
100pub type time_t = c_longlong;
101/// The `pid_t` type provided in [`sys/types.h`](crate::header::sys_types).
102pub type pid_t = c_int;
103/// The `id_t` type provided in [`sys/types.h`](crate::header::sys_types).
104pub type id_t = c_uint;
105/// The `gid_t` type provided in [`sys/types.h`](crate::header::sys_types).
106pub type gid_t = c_int;
107/// The `uid_t` type provided in [`sys/types.h`](crate::header::sys_types).
108pub type uid_t = c_int;
109/// The `dev_t` type provided in [`sys/types.h`](crate::header::sys_types).
110pub type dev_t = c_ulonglong;
111/// The `ino_t` type provided in [`sys/types.h`](crate::header::sys_types).
112pub type ino_t = c_ulonglong;
113/// The `reclen_t` type provided in [`sys/types.h`](crate::header::sys_types).
114pub type reclen_t = c_ushort;
115/// The `nlink_t` type provided in [`sys/types.h`](crate::header::sys_types).
116pub type nlink_t = c_ulong;
117/// The `blksize_t` type provided in [`sys/types.h`](crate::header::sys_types).
118pub type blksize_t = c_long;
119/// The `blkcnt_t` type provided in [`sys/types.h`](crate::header::sys_types).
120pub type blkcnt_t = c_longlong;
121/// The `key_t` type provided in [`sys/types.h`](crate::header::sys_types).
122pub type key_t = c_int;
123
124/// The `fsblkcnt_t` type provided in [`sys/types.h`](crate::header::sys_types).
125pub type fsblkcnt_t = c_ulong;
126/// The `fsfilcnt_t` type provided in [`sys/types.h`](crate::header::sys_types).
127pub type fsfilcnt_t = c_ulong;
128
129/// The `useconds_t` type provided in [`sys/types.h`](crate::header::sys_types) prior to Issue 7.
130#[deprecated]
131pub type useconds_t = c_uint;
132/// The `suseconds_t` type provided in [`sys/types.h`](crate::header::sys_types).
133#[cfg(target_os = "linux")]
134pub type suseconds_t = c_long;
135// TODO: Should we break this to c_long as well? This also breaks timeval as well
136// but it will be consistent with timespec.tv_nsec (note that syscall already uses c_int)
137/// The `suseconds_t` type provided in [`sys/types.h`](crate::header::sys_types).
138#[cfg(not(target_os = "linux"))]
139pub type suseconds_t = c_int;
140
141/// The `clock_t` type provided in [`sys/types.h`](crate::header::sys_types).
142pub type clock_t = c_long;
143/// The `clockid_t` type provided in [`sys/types.h`](crate::header::sys_types).
144pub type clockid_t = c_int;
145/// The `timer_t` type provided in [`sys/types.h`](crate::header::sys_types).
146pub type timer_t = *mut c_void;
147
148// A C long double is 96 bit in x86, 128 bit in other 64-bit targets
149// However, both in x86 and x86_64 is actually f80 padded which rust has no underlying support,
150// while aarch64 (and possibly riscv64) support full f128 type but behind a feature gate.
151// Until rust supporting them, relibc will lose precision to get them working, plus:
152// All read operation to this type must be converted from "relibc_ldtod".
153// All write operation to this type must be converted with "relibc_dtold".
154/// The `long double` type in C.
155#[cfg(target_pointer_width = "64")]
156pub type c_longdouble = u128;
157/// The `long double` type in C.
158#[cfg(target_pointer_width = "32")]
159pub type c_longdouble = [u32; 3];
160
161pub use crate::header::bits_pthread::*;
162
163/// The `max_align_t` type provided in `stddef.h`, see <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html>.
164#[repr(C, align(16))]
165pub struct max_align_t {
166 _priv: [f64; 4],
167}