rs_ctypes/
lib.rs

1// Copyright 2020-Present (c) Raja Lehtihet & Wael El Oraiby
2//
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
5//
6// 1. Redistributions of source code must retain the above copyright notice,
7// this list of conditions and the following disclaimer.
8//
9// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12//
13// 3. Neither the name of the copyright holder nor the names of its contributors
14// may be used to endorse or promote products derived from this software without
15// specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27// POSSIBILITY OF SUCH DAMAGE.
28#![no_std]
29#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
30#[allow(improper_ctypes)]
31
32pub type c_char = i8;
33pub type c_schar = i8;
34pub type c_uchar = u8;
35pub type c_short = i16;
36pub type c_ushort = u16;
37pub type c_int = i32;
38pub type c_uint = u32;
39
40#[cfg(any(target_pointer_width = "32", windows))]
41pub type c_long = i32;
42#[cfg(any(target_pointer_width = "32", windows))]
43pub type c_ulong = u32;
44
45#[cfg(all(target_pointer_width = "64", not(windows)))]
46pub type c_long = i64;
47#[cfg(all(target_pointer_width = "64", not(windows)))]
48pub type c_ulong = u64;
49
50pub type c_longlong = i64;
51pub type c_ulonglong = u64;
52pub type c_float = f32;
53pub type c_double = f64;
54
55pub use core::ffi::c_void;
56#[cfg(test)]
57mod tests {
58    use super::*;
59    #[test]
60    fn check_sizes() {
61        assert_eq!(::core::mem::size_of::<c_char>(), 1);
62        assert_eq!(::core::mem::size_of::<c_schar>(), 1);
63        assert_eq!(::core::mem::size_of::<c_uchar>(), 1);
64        assert_eq!(::core::mem::size_of::<c_short>(), 2);
65        assert_eq!(::core::mem::size_of::<c_ushort>(), 2);
66        assert_eq!(::core::mem::size_of::<c_int>(), 4);
67        assert_eq!(::core::mem::size_of::<c_uint>(), 4);
68        assert_eq!(::core::mem::size_of::<c_longlong>(), 8);
69        assert_eq!(::core::mem::size_of::<c_ulonglong>(), 8);
70    }
71
72    #[test]
73    #[cfg(windows)]
74    fn check_long_size() {
75        assert_eq!(::core::mem::size_of::<c_long>(), 4);
76        assert_eq!(::core::mem::size_of::<c_ulong>(), 4);
77    }
78
79    #[test]
80    #[cfg(not(windows))]
81    fn check_long_size() {
82        assert_eq!(::core::mem::size_of::<c_long>(), 8);
83        assert_eq!(::core::mem::size_of::<c_ulong>(), 8);
84    }
85
86}