cxx/
c_char.rs

1#![allow(clippy::duplicated_attributes)] // clippy bug: https://github.com/rust-lang/rust-clippy/issues/12538
2
3#[allow(missing_docs)]
4pub type c_char = c_char_definition::c_char;
5
6// Validate that our definition is consistent with libstd's definition, without
7// introducing a dependency on libstd in ordinary builds.
8#[cfg(all(test, feature = "std"))]
9const _: self::c_char = 0 as std::os::raw::c_char;
10
11#[cfg(not(no_core_ffi_c_char))]
12mod c_char_definition {
13    pub use core::ffi::c_char;
14}
15
16#[cfg(no_core_ffi_c_char)]
17#[allow(dead_code)]
18mod c_char_definition {
19    // These are the targets on which c_char is unsigned.
20    #[cfg(any(
21        all(
22            target_os = "linux",
23            any(
24                target_arch = "aarch64",
25                target_arch = "arm",
26                target_arch = "hexagon",
27                target_arch = "powerpc",
28                target_arch = "powerpc64",
29                target_arch = "s390x",
30                target_arch = "riscv64",
31                target_arch = "riscv32"
32            )
33        ),
34        all(
35            target_os = "android",
36            any(target_arch = "aarch64", target_arch = "arm")
37        ),
38        all(target_os = "l4re", target_arch = "x86_64"),
39        all(
40            target_os = "freebsd",
41            any(
42                target_arch = "aarch64",
43                target_arch = "arm",
44                target_arch = "powerpc",
45                target_arch = "powerpc64",
46                target_arch = "riscv64"
47            )
48        ),
49        all(
50            target_os = "netbsd",
51            any(target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc")
52        ),
53        all(target_os = "openbsd", target_arch = "aarch64"),
54        all(
55            target_os = "vxworks",
56            any(
57                target_arch = "aarch64",
58                target_arch = "arm",
59                target_arch = "powerpc64",
60                target_arch = "powerpc"
61            )
62        ),
63        all(target_os = "fuchsia", target_arch = "aarch64")
64    ))]
65    pub use self::unsigned::c_char;
66
67    // On every other target, c_char is signed.
68    pub use self::signed::*;
69
70    mod unsigned {
71        pub type c_char = u8;
72    }
73
74    mod signed {
75        pub type c_char = i8;
76    }
77}