You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
931 B
Rust
43 lines
931 B
Rust
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<File>, offset: usize) -> Result<usize, Error> {
|
|
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)
|
|
}
|