stak_util/
lib.rs

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