|
| 1 | +// mod types.rs |
| 2 | +#![allow(non_camel_case_types)] |
| 3 | + |
| 4 | +type_alias! { "c_char.md", c_char = c_char_definition::c_char;} |
| 5 | +type_alias! { "c_schar.md", c_schar = i8; } |
| 6 | +type_alias! { "c_uchar.md", c_uchar = u8; } |
| 7 | +type_alias! { "c_short.md", c_short = i16; } |
| 8 | +type_alias! { "c_ushort.md", c_ushort = u16; } |
| 9 | +type_alias! { "c_int.md", c_int = c_int_definition::c_int;} |
| 10 | +type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint;} |
| 11 | +type_alias! { "c_long.md", c_long = c_long_definition::c_long;} |
| 12 | +type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong;} |
| 13 | +type_alias! { "c_longlong.md", c_longlong = i64; } |
| 14 | +type_alias! { "c_ulonglong.md", c_ulonglong = u64; } |
| 15 | +type_alias! { "c_float.md", c_float = f32; } |
| 16 | +type_alias! { "c_double.md", c_double = f64; } |
| 17 | + |
| 18 | +pub type c_size_t = usize; |
| 19 | +pub type c_ptrdiff_t = isize; |
| 20 | +pub type c_ssize_t = isize; |
| 21 | + |
| 22 | +mod c_char_definition { |
| 23 | + cfg_if! { |
| 24 | + // These are the targets on which c_char is unsigned. |
| 25 | + if #[cfg(any( |
| 26 | + all( |
| 27 | + target_os = "linux", |
| 28 | + any( |
| 29 | + target_arch = "aarch64", |
| 30 | + target_arch = "arm", |
| 31 | + target_arch = "hexagon", |
| 32 | + target_arch = "powerpc", |
| 33 | + target_arch = "powerpc64", |
| 34 | + target_arch = "s390x", |
| 35 | + target_arch = "riscv64", |
| 36 | + target_arch = "riscv32", |
| 37 | + target_arch = "csky" |
| 38 | + ) |
| 39 | + ), |
| 40 | + all(target_os = "android", any(target_arch = "aarch64", target_arch = "arm")), |
| 41 | + all(target_os = "l4re", target_arch = "x86_64"), |
| 42 | + all( |
| 43 | + any(target_os = "freebsd", target_os = "openbsd", target_os = "rtems"), |
| 44 | + any( |
| 45 | + target_arch = "aarch64", |
| 46 | + target_arch = "arm", |
| 47 | + target_arch = "powerpc", |
| 48 | + target_arch = "powerpc64", |
| 49 | + target_arch = "riscv64" |
| 50 | + ) |
| 51 | + ), |
| 52 | + all( |
| 53 | + target_os = "netbsd", |
| 54 | + any( |
| 55 | + target_arch = "aarch64", |
| 56 | + target_arch = "arm", |
| 57 | + target_arch = "powerpc", |
| 58 | + target_arch = "riscv64" |
| 59 | + ) |
| 60 | + ), |
| 61 | + all( |
| 62 | + target_os = "vxworks", |
| 63 | + any( |
| 64 | + target_arch = "aarch64", |
| 65 | + target_arch = "arm", |
| 66 | + target_arch = "powerpc64", |
| 67 | + target_arch = "powerpc" |
| 68 | + ) |
| 69 | + ), |
| 70 | + all( |
| 71 | + target_os = "fuchsia", |
| 72 | + any(target_arch = "aarch64", target_arch = "riscv64") |
| 73 | + ), |
| 74 | + all(target_os = "nto", target_arch = "aarch64"), |
| 75 | + target_os = "horizon", |
| 76 | + target_os = "aix", |
| 77 | + ))] { |
| 78 | + pub type c_char = u8; |
| 79 | + } else { |
| 80 | + // On every other target, c_char is signed. |
| 81 | + pub type c_char = i8; |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +mod c_int_definition { |
| 87 | + cfg_if! { |
| 88 | + if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] { |
| 89 | + pub type c_int = i16; |
| 90 | + pub type c_uint = u16; |
| 91 | + } else { |
| 92 | + pub type c_int = i32; |
| 93 | + pub type c_uint = u32; |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +mod c_long_definition { |
| 99 | + cfg_if! { |
| 100 | + if #[cfg(all(target_pointer_width = "64", not(windows)))] { |
| 101 | + pub type c_long = i64; |
| 102 | + pub type c_ulong = u64; |
| 103 | + } else { |
| 104 | + // The minimal size of `long` in the C standard is 32 bits |
| 105 | + pub type c_long = i32; |
| 106 | + pub type c_ulong = u32; |
| 107 | + } |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +#[cfg_attr(not(doc), repr(u8))] |
| 112 | +pub enum c_void { |
| 113 | + __variant1, |
| 114 | + __variant2, |
| 115 | +} |
0 commit comments