#![allow(non_camel_case_types)]
use cfg_if::cfg_if;
use std::ffi::CStr;
use std::os::raw::c_short;
use zerocopy::{FromBytes, FromZeroes};
pub mod x32;
pub mod x64;
pub const EMPTY: c_short = 0;
pub const RUN_LVL: c_short = 1;
pub const BOOT_TIME: c_short = 2;
pub const NEW_TIME: c_short = 3;
pub const OLD_TIME: c_short = 4;
pub const INIT_PROCESS: c_short = 5;
pub const LOGIN_PROCESS: c_short = 6;
pub const USER_PROCESS: c_short = 7;
pub const DEAD_PROCESS: c_short = 8;
pub const ACCOUNTING: c_short = 9;
pub const UT_LINESIZE: usize = 32;
pub const UT_NAMESIZE: usize = 32;
pub const UT_HOSTSIZE: usize = 256;
#[repr(C)]
#[derive(Clone, Copy, Debug, FromBytes, FromZeroes)]
pub struct exit_status {
pub e_termination: c_short,
pub e_exit: c_short,
}
cfg_if! {
if #[cfg(any(
target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm",
target_arch = "mips",
target_arch = "mips64",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "riscv32",
target_arch = "riscv64",
target_arch = "sparc",
target_arch = "sparc64",
))] {
pub use x32::*;
} else if #[cfg(any(
target_arch = "aarch64",
target_arch = "s390x",
))] {
pub use x64::*;
} else {
compile_error!("The target platform is not supported, please help us add it.");
}
}
fn cstr_from_bytes(bytes: &[u8]) -> &CStr {
match bytes.iter().position(|b| *b == 0) {
Some(pos) => unsafe { CStr::from_bytes_with_nul_unchecked(&bytes[..=pos]) },
None => unsafe { CStr::from_bytes_with_nul_unchecked("???\0".as_bytes()) },
}
}