mod loadable; mod output; mod relocatable; mod section; mod symbol; use std::{ convert::TryInto, fs::File, io::{BufWriter, Seek, SeekFrom}, path::Path, }; pub use loadable::*; pub use output::*; pub use relocatable::*; pub use section::*; pub use symbol::*; use crate::error::Error; pub fn expand_path(path: &Path) -> Result<&str, Error> { use std::io::Error as IOError; use std::io::ErrorKind; path.to_str().ok_or_else(|| { let ioe = IOError::new(ErrorKind::Other, "Path expansion fail"); let boxed = Box::new(ioe); Error::IOError(boxed) }) } pub fn pad_to_next_page(writer: &mut BufWriter, offset: usize) -> Result { let page_size = page_size::get(); let padding = page_size - (offset % page_size); eprintln!("Padding from: {} with: {}", offset, padding); writer.seek(SeekFrom::Current(padding.try_into()?))?; Ok(padding) }