libc/
primitives.rs

1//! This module contains type aliases for C's platform-specific types
2//! and fixed-width integer types.
3//!
4//! The platform-specific types definitions were taken from rust-lang/rust in
5//! library/core/src/ffi/primitives.rs
6//!
7//! The fixed-width integer aliases are deprecated: use the Rust types instead.
8
9pub type c_schar = i8;
10pub type c_uchar = u8;
11pub type c_short = i16;
12pub type c_ushort = u16;
13
14pub type c_longlong = i64;
15pub type c_ulonglong = u64;
16
17pub type c_float = f32;
18pub type c_double = f64;
19
20cfg_if! {
21    if #[cfg(all(
22        not(windows),
23        not(target_vendor = "apple"),
24        not(target_os = "vita"),
25        any(
26            target_arch = "aarch64",
27            target_arch = "arm",
28            target_arch = "csky",
29            target_arch = "hexagon",
30            target_arch = "msp430",
31            target_arch = "powerpc",
32            target_arch = "powerpc64",
33            target_arch = "riscv32",
34            target_arch = "riscv64",
35            target_arch = "s390x",
36            target_arch = "xtensa",
37        )
38    ))] {
39        pub type c_char = u8;
40    } else {
41        // On every other target, c_char is signed.
42        pub type c_char = i8;
43    }
44}
45
46cfg_if! {
47    if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] {
48        pub type c_int = i16;
49        pub type c_uint = u16;
50    } else {
51        pub type c_int = i32;
52        pub type c_uint = u32;
53    }
54}
55
56cfg_if! {
57    if #[cfg(all(target_pointer_width = "64", not(windows)))] {
58        pub type c_long = i64;
59        pub type c_ulong = u64;
60    } else {
61        // The minimal size of `long` in the C standard is 32 bits
62        pub type c_long = i32;
63        pub type c_ulong = u32;
64    }
65}
66
67#[deprecated(since = "0.2.55", note = "Use i8 instead.")]
68pub type int8_t = i8;
69#[deprecated(since = "0.2.55", note = "Use i16 instead.")]
70pub type int16_t = i16;
71#[deprecated(since = "0.2.55", note = "Use i32 instead.")]
72pub type int32_t = i32;
73#[deprecated(since = "0.2.55", note = "Use i64 instead.")]
74pub type int64_t = i64;
75#[deprecated(since = "0.2.55", note = "Use u8 instead.")]
76pub type uint8_t = u8;
77#[deprecated(since = "0.2.55", note = "Use u16 instead.")]
78pub type uint16_t = u16;
79#[deprecated(since = "0.2.55", note = "Use u32 instead.")]
80pub type uint32_t = u32;
81#[deprecated(since = "0.2.55", note = "Use u64 instead.")]
82pub type uint64_t = u64;
83
84cfg_if! {
85    if #[cfg(all(target_arch = "aarch64", not(target_os = "windows")))] {
86        /// C `__int128` (a GCC extension that's part of many ABIs)
87        pub type __int128 = i128;
88        /// C `unsigned __int128` (a GCC extension that's part of many ABIs)
89        pub type __uint128 = u128;
90        /// C __int128_t (alternate name for [__int128][])
91        pub type __int128_t = i128;
92        /// C __uint128_t (alternate name for [__uint128][])
93        pub type __uint128_t = u128;
94    }
95}