c_gull/
lib.rs

1#![doc = include_str!("../README.md")]
2#![feature(sync_unsafe_cell)]
3#![cfg_attr(not(feature = "std"), no_std)]
4// Don't warn if `try_into()` is fallible on some targets.
5#![allow(unreachable_patterns)]
6// Don't warn if `try_into()` is fallible on some targets.
7#![allow(irrefutable_let_patterns)]
8
9#[cfg(feature = "std")]
10extern crate alloc;
11#[allow(unused_extern_crates)]
12extern crate c_scape;
13
14// Re-export the c_scape crate's API, which includes the libc API. This allows
15// users to depend on the c-scape crate in place of libc.
16pub use c_scape::*;
17
18#[macro_use]
19mod use_libc;
20
21#[cfg(feature = "std")]
22mod nss;
23#[cfg(feature = "std")]
24mod resolve;
25#[cfg(feature = "std")]
26mod sysconf;
27#[cfg(feature = "std")]
28mod system;
29#[cfg(feature = "std")]
30mod termios_;
31#[cfg(feature = "std")]
32mod time;
33#[cfg(feature = "std")]
34#[cfg(not(target_env = "musl"))]
35mod utmp;
36
37#[cfg(feature = "std")]
38#[cold]
39#[no_mangle]
40unsafe extern "C" fn __assert_fail(
41    expr: *const c_char,
42    file: *const c_char,
43    line: c_int,
44    func: *const c_char,
45) -> ! {
46    use std::ffi::CStr;
47    //libc!(libc::__assert_fail(expr, file, line, func));
48
49    eprintln!(
50        "Assertion failed: {:?} ({:?}:{}: {:?})",
51        CStr::from_ptr(expr),
52        CStr::from_ptr(file),
53        line,
54        CStr::from_ptr(func)
55    );
56    std::process::abort();
57}
58
59// utilities
60
61/// Convert a rustix `Result` into an `Option` with the error stored
62/// in `errno`.
63#[cfg(feature = "std")]
64fn convert_res<T>(result: Result<T, rustix::io::Errno>) -> Option<T> {
65    use errno::{set_errno, Errno};
66    result
67        .map_err(|err| set_errno(Errno(err.raw_os_error())))
68        .ok()
69}