Skip to content
Snippets Groups Projects
Commit 285d1b05 authored by stratact's avatar stratact
Browse files

Implement `RawFile::open()` and add `*_raw_df()` convenience methods

parent 7ca5fac2
No related branches found
No related tags found
No related merge requests found
...@@ -4,8 +4,11 @@ use sys::{open, dup, close}; ...@@ -4,8 +4,11 @@ use sys::{open, dup, close};
pub struct RawFile(usize); pub struct RawFile(usize);
impl RawFile { impl RawFile {
pub fn open<T: AsRef<[u8]>>(path: T, flags: usize) -> Result<RawFile, ()> { pub fn open<T: AsRef<[u8]>>(path: T, flags: usize, mode: usize) -> Result<RawFile, ()> {
open(path, flags).map(RawFile) match open(path.as_ref()[0] as *const i8, flags as i32, mode as u16) {
0 => Err(()),
n => Ok(RawFile(n as usize))
}
} }
pub fn dup(&self, _buf: &[u8]) -> Result<RawFile, ()> { pub fn dup(&self, _buf: &[u8]) -> Result<RawFile, ()> {
...@@ -14,6 +17,14 @@ impl RawFile { ...@@ -14,6 +17,14 @@ impl RawFile {
n => Ok(RawFile(n as usize)) n => Ok(RawFile(n as usize))
} }
} }
pub fn as_raw_fd(&self) -> usize {
self.0
}
pub fn into_raw_fd(self) -> usize {
self.0
}
} }
impl Drop for RawFile { impl Drop for RawFile {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment