1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: GPL-2.0

//! C types for the bindings.
//!
//! The bindings generated by `bindgen` use these types to map to the C ones.
//!
//! C's standard integer types may differ in width depending on
//! the architecture, thus we need to conditionally compile those.

#![allow(non_camel_case_types)]

#[cfg(any(target_arch = "arm", target_arch = "x86", target_arch = "riscv32",))]
mod c {
    /// C `void` type.
    pub type c_void = core::ffi::c_void;

    /// C `char` type.
    pub type c_char = i8;

    /// C `signed char` type.
    pub type c_schar = i8;

    /// C `unsigned char` type.
    pub type c_uchar = u8;

    /// C `short` type.
    pub type c_short = i16;

    /// C `unsigned short` type.
    pub type c_ushort = u16;

    /// C `int` type.
    pub type c_int = i32;

    /// C `unsigned int` type.
    pub type c_uint = u32;

    /// C `long` type.
    pub type c_long = i32;

    /// C `unsigned long` type.
    pub type c_ulong = u32;

    /// C `long long` type.
    pub type c_longlong = i64;

    /// C `unsigned long long` type.
    pub type c_ulonglong = u64;

    /// C `ssize_t` type (typically defined in `<sys/types.h>` by POSIX).
    ///
    /// For some 32-bit architectures like this one, the kernel defines it as
    /// `int`, i.e. it is an [`i32`].
    pub type c_ssize_t = isize;

    /// C `size_t` type (typically defined in `<stddef.h>`).
    ///
    /// For some 32-bit architectures like this one, the kernel defines it as
    /// `unsigned int`, i.e. it is an [`u32`].
    pub type c_size_t = usize;
}

#[cfg(any(
    target_arch = "aarch64",
    target_arch = "x86_64",
    target_arch = "powerpc64",
    target_arch = "riscv64",
))]
mod c {
    /// C `void` type.
    pub type c_void = core::ffi::c_void;

    /// C `char` type.
    pub type c_char = i8;

    /// C `signed char` type.
    pub type c_schar = i8;

    /// C `unsigned char` type.
    pub type c_uchar = u8;

    /// C `short` type.
    pub type c_short = i16;

    /// C `unsigned short` type.
    pub type c_ushort = u16;

    /// C `int` type.
    pub type c_int = i32;

    /// C `unsigned int` type.
    pub type c_uint = u32;

    /// C `long` type.
    pub type c_long = i64;

    /// C `unsigned long` type.
    pub type c_ulong = u64;

    /// C `long long` type.
    pub type c_longlong = i64;

    /// C `unsigned long long` type.
    pub type c_ulonglong = u64;

    /// C `ssize_t` type (typically defined in `<sys/types.h>` by POSIX).
    ///
    /// For 64-bit architectures like this one, the kernel defines it as
    /// `long`, i.e. it is an [`i64`].
    pub type c_ssize_t = isize;

    /// C `size_t` type (typically defined in `<stddef.h>`).
    ///
    /// For 64-bit architectures like this one, the kernel defines it as
    /// `unsigned long`, i.e. it is an [`u64`].
    pub type c_size_t = usize;
}

pub use c::*;