Create a new `FdGuard`. Open a file at `path` and store the open file descriptor
(path: &CStr)
| 26 | /// |
| 27 | /// Open a file at `path` and store the open file descriptor |
| 28 | fn new(path: &CStr) -> Result<Self, ShmError> { |
| 29 | // SAFETY: `path` is a valid C string. |
| 30 | let fd = unsafe { libc::open(path.as_ptr(), libc::O_RDONLY) }; |
| 31 | if fd < 0 { |
| 32 | return syserror!(format!("Faild to open file at {:?}", path)); |
| 33 | } |
| 34 | |
| 35 | Ok(FdGuard(fd)) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | impl Drop for FdGuard { |