Skip to main content

mbedtls_sys/
types.rs

1/* Copyright (c) Fortanix, Inc.
2 *
3 * Licensed under the GNU General Public License, version 2 <LICENSE-GPL or
4 * https://www.gnu.org/licenses/gpl-2.0.html> or the Apache License, Version
5 * 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your
6 * option. This file may not be copied, modified, or distributed except
7 * according to those terms. */
8
9#![allow(non_camel_case_types)]
10
11pub type int8_t = i8;
12pub type int16_t = i16;
13pub type int32_t = i32;
14pub type int64_t = i64;
15pub type uint8_t = u8;
16pub type uint16_t = u16;
17pub type uint32_t = u32;
18pub type uint64_t = u64;
19pub type size_t = usize;
20pub type ssize_t = isize;
21pub type intptr_t = isize;
22pub type uintptr_t = usize;
23pub type ptrdiff_t = isize;
24
25#[cfg(feature = "std")]
26pub use std::os::raw as raw_types;
27
28#[cfg(not(feature = "std"))]
29pub mod raw_types {
30    // From libstd/os/raw.rs
31    cfg_if! {
32        if #[cfg(any(
33            target_os = "android",
34            target_os = "emscripten",
35            all(
36                target_os = "linux",
37                any(
38                    target_arch = "aarch64",
39                    target_arch = "arm",
40                    target_arch = "powerpc",
41                    target_arch = "powerpc64"
42                )
43            )
44        ))] {
45            pub type c_char = u8;
46        } else {
47            pub type c_char = i8;
48        }
49    }
50    pub type c_schar = i8;
51    pub type c_uchar = u8;
52    pub type c_short = i16;
53    pub type c_ushort = u16;
54    pub type c_int = i32;
55    pub type c_uint = u32;
56    cfg_if! {
57        if #[cfg(any(target_pointer_width = "32", windows))] {
58            pub type c_long = i32;
59            pub type c_ulong = u32;
60        } else {
61            pub type c_long = i64;
62            pub type c_ulong = u64;
63        }
64    }
65    pub type c_longlong = i64;
66    pub type c_ulonglong = u64;
67    pub type c_float = f32;
68    pub type c_double = f64;
69
70    #[repr(u8)]
71    pub enum c_void {
72        #[doc(hidden)]
73        __variant1,
74        #[doc(hidden)]
75        __variant2,
76    }
77}
78
79#[cfg(any(all(unix, not(target_env = "fortanixvme")), windows))]
80extern crate libc;
81
82#[cfg(std_component = "fs")]
83pub use self::libc::FILE;
84
85cfg_if! {
86    if #[cfg(time_component = "custom")] {
87        pub type time_t = raw_types::c_longlong;
88        #[repr(C)]
89        pub struct tm {
90            pub tm_sec:   i32,            /* Seconds.        [0-60] (1 leap second) */
91            pub tm_min:   i32,            /* Minutes.        [0-59] */
92            pub tm_hour:  i32,            /* Hours.          [0-23] */
93            pub tm_mday:  i32,            /* Day.            [1-31] */
94            pub tm_mon:   i32,            /* Month.          [0-11] */
95            pub tm_year:  i32,            /* Year          - 1900.  */
96            pub tm_wday:  i32,            /* Day of week.    [0-6]  */
97            pub tm_yday:  i32,            /* Days in year.   [0-365]*/
98            pub tm_isdst: i32,
99        }
100    } else if #[cfg(time_component = "libc")] {
101        pub use self::libc::{tm, time_t};
102    }
103}
104
105#[cfg(threading_component = "pthread")]
106pub use self::libc::pthread_mutex_t;
107
108#[cfg(feature = "zlib")]
109extern crate libz_sys;
110#[cfg(feature = "zlib")]
111pub use self::libz_sys::z_stream;
112
113#[cfg(feature = "pkcs11")]
114const ERROR: _PKCS11_NOT_SUPPORTED_ = ();