c_gull/
lib.rs

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
#![doc = include_str!("../README.md")]
#![feature(sync_unsafe_cell)]
#![feature(strict_provenance)]
#![deny(fuzzy_provenance_casts, lossy_provenance_casts)]
#![cfg_attr(not(feature = "std"), no_std)]
// Don't warn if `try_into()` is fallible on some targets.
#![allow(unreachable_patterns)]
// Don't warn if `try_into()` is fallible on some targets.
#![allow(irrefutable_let_patterns)]

#[cfg(feature = "std")]
extern crate alloc;
#[allow(unused_extern_crates)]
extern crate c_scape;

// Re-export the c_scape crate's API, which includes the libc API. This allows
// users to depend on the c-scape crate in place of libc.
pub use c_scape::*;

#[macro_use]
mod use_libc;

#[cfg(feature = "std")]
mod nss;
#[cfg(feature = "std")]
mod resolve;
#[cfg(feature = "std")]
mod sysconf;
#[cfg(feature = "std")]
mod system;
#[cfg(feature = "std")]
mod termios_;
#[cfg(feature = "std")]
mod time;
#[cfg(feature = "std")]
mod utmp;

#[cfg(feature = "std")]
#[cold]
#[no_mangle]
unsafe extern "C" fn __assert_fail(
    expr: *const c_char,
    file: *const c_char,
    line: c_int,
    func: *const c_char,
) -> ! {
    use std::ffi::CStr;
    //libc!(libc::__assert_fail(expr, file, line, func));

    eprintln!(
        "Assertion failed: {:?} ({:?}:{}: {:?})",
        CStr::from_ptr(expr),
        CStr::from_ptr(file),
        line,
        CStr::from_ptr(func)
    );
    std::process::abort();
}

// utilities

/// Convert a rustix `Result` into an `Option` with the error stored
/// in `errno`.
#[cfg(feature = "std")]
fn convert_res<T>(result: Result<T, rustix::io::Errno>) -> Option<T> {
    use errno::{set_errno, Errno};
    result
        .map_err(|err| set_errno(Errno(err.raw_os_error())))
        .ok()
}