mstak_util/
lib.rs

1//! Utilities around `libc`.
2
3#![no_std]
4
5mod heap;
6mod mmap;
7mod validate;
8
9use core::ffi::CStr;
10pub use heap::Heap;
11pub use mmap::Mmap;
12pub use validate::validate;
13
14/// Reads a file size at a path.
15pub fn read_file_size(path: &CStr) -> usize {
16    unsafe {
17        let file = libc::fopen(path.as_ptr(), c"rb" as *const _ as _);
18        libc::fseek(file, 0, libc::SEEK_END);
19        let size = libc::ftell(file) as _;
20        libc::fclose(file);
21        size
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn file_size() {
31        assert!(read_file_size(c"src/lib.rs") > 0);
32    }
33}