add rawfile.rs

This commit is contained in:
Paul Sajna
2018-03-04 08:09:13 -08:00
parent 0157f7fcea
commit 4b1a1568bf
+27
View File
@@ -0,0 +1,27 @@
use core::ops::Deref;
pub struct RawFile(usize);
impl RawFile {
pub fn open<T: AsRef<[u8]>>(path: T, flags: usize) -> Result<RawFile> {
open(path, flags).map(RawFile)
}
pub fn dup(&self, buf: &[u8]) -> Result<RawFile> {
dup(self.0, buf).map(RawFile)
}
}
impl Drop for RawFile {
fn drop(&mut self) {
let _ = close(self.0);
}
}
impl Deref for RawFile {
type Target = usize;
fn deref(&self) -> &usize {
&self.0
}
}