From 4b1a1568bff02fcae90371670d1678bd7fb0b0bd Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Sun, 4 Mar 2018 08:09:13 -0800 Subject: [PATCH] add rawfile.rs --- platform/src/rawfile.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 platform/src/rawfile.rs diff --git a/platform/src/rawfile.rs b/platform/src/rawfile.rs new file mode 100644 index 0000000000..d4ee4bee60 --- /dev/null +++ b/platform/src/rawfile.rs @@ -0,0 +1,27 @@ +use core::ops::Deref; + +pub struct RawFile(usize); + +impl RawFile { + pub fn open>(path: T, flags: usize) -> Result { + open(path, flags).map(RawFile) + } + + pub fn dup(&self, buf: &[u8]) -> Result { + 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 + } +}