#![cfg_attr(not(test), no_std)]
#![allow(clippy::len_zero)] #![allow(clippy::manual_range_contains)] #![allow(clippy::needless_range_loop)] #![allow(clippy::too_many_arguments)] #![allow(clippy::collapsible_if)] #![allow(clippy::redundant_closure)] #![allow(clippy::single_match)] #![allow(clippy::match_single_binding)] #![allow(clippy::unnecessary_cast)] #![allow(clippy::manual_c_str_literals)] #![allow(clippy::missing_safety_doc)] #![allow(clippy::if_same_then_else)] #![allow(clippy::manual_strip)] #![allow(clippy::manual_div_ceil)] #![allow(clippy::needless_return)] #![allow(clippy::wrong_self_convention)] #![allow(clippy::same_item_push)] #![allow(clippy::not_unsafe_ptr_arg_deref)] #![allow(clippy::explicit_auto_deref)] #![allow(clippy::manual_clamp)] #![allow(clippy::let_and_return)] #![allow(clippy::needless_borrow)] #![allow(clippy::op_ref)] #![allow(clippy::needless_pub_self)] #![allow(clippy::manual_pattern_char_comparison)] #![allow(clippy::implicit_saturating_sub)] #![allow(clippy::identity_op)] #![allow(clippy::while_let_loop)] #![allow(clippy::slow_vector_initialization)] #![allow(clippy::match_overlapping_arm)] #![allow(clippy::manual_rotate)] #![allow(clippy::manual_map)] #![allow(clippy::manual_contains)] #![allow(clippy::iter_out_of_bounds)] #![allow(clippy::doc_overindented_list_items)]
#![allow(dead_code)] #![allow(unused_assignments)] #![allow(unreachable_patterns)] #![allow(unused_variables)]
#[cfg(feature = "alloc")]
extern crate alloc;
pub mod io;
pub mod applets;
pub mod sys;
#[cfg(test)]
pub mod test_utils;
pub type AppletFn = fn(i32, *const *const u8) -> i32;
pub fn is_applet(name: &[u8]) -> bool {
applets::find_applet(name).is_some()
}
pub fn run_applet(name: &[u8], argc: i32, argv: *const *const u8) -> i32 {
match applets::find_applet(name) {
Some(f) => f(argc, argv),
None => {
io::write_str(2, b"armybox: applet not found: ");
io::write_all(2, name);
io::write_str(2, b"\n");
127
}
}
}
pub const fn applet_count() -> usize {
applets::APPLET_COUNT
}
#[cfg(all(not(test), not(feature = "std")))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
io::write_str(2, b"armybox: panic!\n");
unsafe { libc::_exit(1); }
}
#[cfg(all(not(test), not(feature = "std"), feature = "alloc"))]
mod allocator {
use core::alloc::{GlobalAlloc, Layout};
pub struct LibcAllocator;
unsafe impl GlobalAlloc for LibcAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
unsafe { libc::malloc(layout.size()) as *mut u8 }
}
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
unsafe { libc::free(ptr as *mut libc::c_void) }
}
unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, new_size: usize) -> *mut u8 {
unsafe { libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8 }
}
}
#[global_allocator]
static ALLOCATOR: LibcAllocator = LibcAllocator;
}