libc/
lib.rs

1//! libc - Raw FFI bindings to platforms' system libraries
2#![crate_name = "libc"]
3#![crate_type = "rlib"]
4#![allow(
5    renamed_and_removed_lints, // Keep this order.
6    unknown_lints, // Keep this order.
7    nonstandard_style,
8    overflowing_literals,
9    unused_macros,
10    unused_macro_rules,
11)]
12#![warn(
13    missing_copy_implementations,
14    missing_debug_implementations,
15    safe_packed_borrows
16)]
17// Prepare for a future upgrade
18#![warn(rust_2024_compatibility)]
19// Things missing for 2024 that are blocked on MSRV or breakage
20#![allow(
21    missing_unsafe_on_extern,
22    edition_2024_expr_fragment_specifier,
23    // Allowed globally, the warning is enabled in individual modules as we work through them
24    unsafe_op_in_unsafe_fn
25)]
26#![cfg_attr(libc_deny_warnings, deny(warnings))]
27// Attributes needed when building as part of the standard library
28#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]
29#![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))]
30// DIFF(1.0): The thread local references that raise this lint were removed in 1.0
31#![cfg_attr(feature = "rustc-dep-of-std", allow(static_mut_refs))]
32#![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)]
33#![cfg_attr(feature = "rustc-dep-of-std", no_core)]
34
35#[macro_use]
36mod macros;
37mod new;
38
39cfg_if! {
40    if #[cfg(feature = "rustc-dep-of-std")] {
41        extern crate rustc_std_workspace_core as core;
42    }
43}
44
45pub use core::ffi::c_void;
46
47#[allow(unused_imports)] // needed while the module is empty on some platforms
48pub use new::*;
49
50cfg_if! {
51    if #[cfg(windows)] {
52        mod primitives;
53        pub use crate::primitives::*;
54
55        mod windows;
56        pub use crate::windows::*;
57
58        prelude!();
59    } else if #[cfg(target_os = "fuchsia")] {
60        mod primitives;
61        pub use crate::primitives::*;
62
63        mod fuchsia;
64        pub use crate::fuchsia::*;
65
66        prelude!();
67    } else if #[cfg(target_os = "switch")] {
68        mod primitives;
69        pub use primitives::*;
70
71        mod switch;
72        pub use switch::*;
73
74        prelude!();
75    } else if #[cfg(target_os = "psp")] {
76        mod primitives;
77        pub use primitives::*;
78
79        mod psp;
80        pub use crate::psp::*;
81
82        prelude!();
83    } else if #[cfg(target_os = "vxworks")] {
84        mod primitives;
85        pub use crate::primitives::*;
86
87        mod vxworks;
88        pub use crate::vxworks::*;
89
90        prelude!();
91    } else if #[cfg(target_os = "qurt")] {
92        mod primitives;
93        pub use crate::primitives::*;
94
95        mod qurt;
96        pub use crate::qurt::*;
97
98        prelude!();
99    } else if #[cfg(target_os = "solid_asp3")] {
100        mod primitives;
101        pub use crate::primitives::*;
102
103        mod solid;
104        pub use crate::solid::*;
105
106        prelude!();
107    } else if #[cfg(unix)] {
108        mod primitives;
109        pub use crate::primitives::*;
110
111        mod unix;
112        pub use crate::unix::*;
113
114        mod types {
    //! Platform-agnostic support types.
    use core::mem::MaybeUninit;
    use crate::prelude::*;
    /// A transparent wrapper over `MaybeUninit<T>` to represent uninitialized padding
    /// while providing `Default`.
    #[allow(unused)]
    #[repr(transparent)]
    pub(crate) struct Padding<T: Copy>(MaybeUninit<T>);
    #[automatically_derived]
    #[allow(unused)]
    impl<T: ::core::clone::Clone + Copy> ::core::clone::Clone for Padding<T> {
        #[inline]
        fn clone(&self) -> Padding<T> {
            Padding(::core::clone::Clone::clone(&self.0))
        }
    }
    #[automatically_derived]
    #[allow(unused)]
    impl<T: ::core::marker::Copy + Copy> ::core::marker::Copy for Padding<T> {
    }
    impl<T: Copy> Default for Padding<T> {
        fn default() -> Self { Self(MaybeUninit::zeroed()) }
    }
    impl<T: Copy> Padding<T> {
        /// Const constructor for uninitialized padding in const contexts.
        #[allow(unused)]
        pub(crate) const fn uninit() -> Self { Self(MaybeUninit::uninit()) }
    }
    impl<T: Copy> fmt::Debug for Padding<T> {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            let full_name = core::any::type_name::<Self>();
            let prefix_len = full_name.find("Padding").unwrap();
            f.pad(&full_name[prefix_len..])
        }
    }
    #[allow(unused)]
    pub(crate) type CEnumRepr = c_uint;
}
/// Frequently-used types that are available on all platforms
///
/// We need to reexport the core types so this works with `rust-dep-of-std`.
mod prelude {
    #[allow(unused_imports)]
    pub(crate) use core::clone::Clone;
    #[allow(unused_imports)]
    pub(crate) use core::default::Default;
    #[allow(unused_imports)]
    pub(crate) use core::marker::{Copy, Send, Sync};
    #[allow(unused_imports)]
    pub(crate) use core::option::Option;
    #[allow(unused_imports)]
    pub(crate) use core::prelude::v1::derive;
    #[allow(unused_imports)]
    pub(crate) use core::{cfg, fmt, hash, iter, mem, ptr};
    #[allow(unused_imports)]
    pub(crate) use fmt::Debug;
    #[allow(unused_imports)]
    pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};
    #[allow(unused_imports)]
    pub(crate) use crate::types::{CEnumRepr, Padding};
    #[allow(unused_imports)]
    pub(crate) use crate::{
        c_char, c_double, c_float, c_int, c_long, c_longlong, c_short,
        c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort, c_void, intptr_t,
        size_t, ssize_t, uintptr_t,
    };
}prelude!();
115    } else if #[cfg(target_os = "hermit")] {
116        mod primitives;
117        pub use crate::primitives::*;
118
119        mod hermit;
120        pub use crate::hermit::*;
121
122        prelude!();
123    } else if #[cfg(target_os = "teeos")] {
124        mod primitives;
125        pub use primitives::*;
126
127        mod teeos;
128        pub use teeos::*;
129
130        prelude!();
131    } else if #[cfg(target_os = "trusty")] {
132        mod primitives;
133        pub use crate::primitives::*;
134
135        mod trusty;
136        pub use crate::trusty::*;
137
138        prelude!();
139    } else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
140        mod primitives;
141        pub use crate::primitives::*;
142
143        mod sgx;
144        pub use crate::sgx::*;
145
146        prelude!();
147    } else if #[cfg(any(target_env = "wasi", target_os = "wasi"))] {
148        mod primitives;
149        pub use crate::primitives::*;
150
151        mod wasi;
152        pub use crate::wasi::*;
153
154        prelude!();
155    } else if #[cfg(target_os = "xous")] {
156        mod primitives;
157        pub use crate::primitives::*;
158
159        mod xous;
160        pub use crate::xous::*;
161
162        prelude!();
163    } else {
164        // non-supported targets: empty...
165    }
166}