|
| 1 | +//! This module attempts to attempts to give reasonable definitions for most |
| 2 | +//! basic C types. Note that these are essentially educated guesses and are NOT |
| 3 | +//! guaranteed to match the types produced by your C compiler. |
| 4 | +
|
| 5 | +// Per the C11 specification, these type definitions are not guaranteed to be |
| 6 | +// correct for all platforms. However, virtually all platforms use these |
| 7 | +// definitions, including all targets supported by rustc. |
| 8 | +pub type c_short = i16; |
| 9 | +pub type c_ushort = u16; |
| 10 | +pub type c_int = i32; |
| 11 | +pub type c_uint = u32; |
| 12 | +pub type c_longlong = i64; |
| 13 | +pub type c_ulonglong = u64; |
| 14 | +pub type intmax_t = i64; |
| 15 | +pub type uintmax_t = u64; |
| 16 | +pub type size_t = usize; |
| 17 | +pub type ptrdiff_t = isize; |
| 18 | +pub type ssize_t = isize; |
| 19 | + |
| 20 | +pub const INT_MIN: c_int = -2147483648; |
| 21 | +pub const INT_MAX: c_int = 2147483647; |
| 22 | + |
| 23 | +// There are two ways that platforms (in practice) differ in their C types: |
| 24 | +// - chars can either be signed or unsigned |
| 25 | +// - longs can either be 32-bit or 64-bit |
| 26 | + |
| 27 | +// Whether chars default to signed or unsigned is primarily determined by |
| 28 | +// architecture (windows is the main exception here). |
| 29 | +pub use self::chars::*; |
| 30 | +#[cfg(any( |
| 31 | + target_arch = "aarch64", |
| 32 | + target_arch = "arm", |
| 33 | + target_arch = "armebv7r", |
| 34 | + target_arch = "armv5te", |
| 35 | + target_arch = "armv7", |
| 36 | + target_arch = "armv7r", |
| 37 | + target_arch = "armv7s", |
| 38 | + target_arch = "asmjs", |
| 39 | + target_arch = "wasm32", |
| 40 | + target_arch = "wasm64", |
| 41 | + target_arch = "powerpc", |
| 42 | + target_arch = "powerpc64", |
| 43 | + target_arch = "powerpc64le", |
| 44 | + target_arch = "s390x", |
| 45 | + target_arch = "thumbv6", |
| 46 | + target_arch = "thumbv6m", |
| 47 | + target_arch = "thummv7", |
| 48 | + target_arch = "thumbv7em", |
| 49 | + target_arch = "thumbv7m", |
| 50 | + target_arch = "thumbv7neon", |
| 51 | + target_arch = "tummbv8", |
| 52 | + target_arch = "thumbv8m", |
| 53 | + target_arch = "thumbv8m.main" |
| 54 | +))] |
| 55 | +mod chars { |
| 56 | + pub type c_char = u8; |
| 57 | + pub type wchar_t = u32; |
| 58 | +} |
| 59 | + |
| 60 | +#[cfg(any( |
| 61 | + target_arch = "i386", |
| 62 | + target_arch = "i586", |
| 63 | + target_arch = "i686", |
| 64 | + target_arch = "x86", |
| 65 | + target_arch = "x86_64", |
| 66 | + target_arch = "mips", |
| 67 | + target_arch = "mips64", |
| 68 | + target_arch = "mips64el", |
| 69 | + target_arch = "mipsel", |
| 70 | + target_arch = "nvptx", |
| 71 | + target_arch = "nvptx64", |
| 72 | + target_arch = "sparc64", |
| 73 | + target_arch = "sparcv9", |
| 74 | + target_arch = "riscv64", |
| 75 | + target_arch = "riscv32", |
| 76 | + target_arch = "riscv32imac", |
| 77 | + target_arch = "riscv32imc" |
| 78 | +))] |
| 79 | +mod chars { |
| 80 | + pub type c_char = i8; |
| 81 | + pub type wchar_t = i32; |
| 82 | +} |
| 83 | + |
| 84 | +// On all platforms but Windows, longs are the same size as a pointer. |
| 85 | +pub use self::long::*; |
| 86 | +#[cfg(target_pointer_width = "64")] |
| 87 | +mod long { |
| 88 | + pub type c_long = i64; |
| 89 | + pub type c_ulong = u64; |
| 90 | +} |
| 91 | + |
| 92 | +#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))] |
| 93 | +mod long { |
| 94 | + pub type c_long = i32; |
| 95 | + pub type c_ulong = u32; |
| 96 | +} |
| 97 | + |
| 98 | +// POSIX specifications make no guarantees that off_t == long int, but this is |
| 99 | +// what GNU and others always do. |
| 100 | +pub type off_t = ::c_long; |
0 commit comments