Skip to content

Commit

Permalink
Implement loading PRAM without mmap (read-only)
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Nov 24, 2024
1 parent cb4882f commit 80f724f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions core/src/mac/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,29 @@ impl RtcData {
}

#[cfg(not(feature = "mmap"))]
pub(super) fn load_pram(_filename: &str) -> Option<Vec<u8>> {
None
pub(super) fn load_pram(filename: &str) -> Option<Vec<u8>> {
use std::fs;
use std::path::Path;

if !Path::new(filename).exists() {
// File not found
return None;
}

let pram = match fs::read(filename) {
Ok(d) => d,
Err(e) => {
error!("Failed to open file: {}", e);
return None;
}
};

if pram.len() != PRAM_SIZE {
error!("Cannot load PRAM {}: not {} bytes", filename, PRAM_SIZE);
return None;
}

Some(pram)
}

#[cfg(feature = "mmap")]
Expand Down

0 comments on commit 80f724f

Please sign in to comment.