Browse Source

add rawfile.rs

Paul Sajna 7 years ago
parent
commit
4b1a1568bf
1 changed files with 27 additions and 0 deletions
  1. 27 0
      platform/src/rawfile.rs

+ 27 - 0
platform/src/rawfile.rs

@@ -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
+    }
+}