Skip to main content

taproot_c_gull/
lib.rs

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