From 76959416bb4cc404434e73109d349ed366298d8a Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Mon, 17 Sep 2018 09:59:41 -0600
Subject: [PATCH] Add missing open flags

---
 src/header/netdb/linux.rs |  7 ++++++-
 src/platform/rawfile.rs   |  3 ++-
 src/platform/redox/mod.rs | 11 ++++++-----
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/header/netdb/linux.rs b/src/header/netdb/linux.rs
index 0d481d53..41d67303 100644
--- a/src/header/netdb/linux.rs
+++ b/src/header/netdb/linux.rs
@@ -1,11 +1,16 @@
 use alloc::string::String;
 use c_str::CString;
+use header::fcntl;
 use platform::rawfile::RawFile;
 use platform::rlb::RawLineBuffer;
 use platform::Line;
 
 pub fn get_dns_server() -> String {
-    let fd = match RawFile::open(&CString::new("/etc/resolv.conf").unwrap(), 0, 0) {
+    let fd = match RawFile::open(
+        &CString::new("/etc/resolv.conf").unwrap(),
+        fcntl::O_RDONLY,
+        0,
+    ) {
         Ok(fd) => fd,
         Err(_) => return String::new(), // TODO: better error handling
     };
diff --git a/src/platform/rawfile.rs b/src/platform/rawfile.rs
index 3e78c5e6..13014a71 100644
--- a/src/platform/rawfile.rs
+++ b/src/platform/rawfile.rs
@@ -3,6 +3,7 @@ use core::ops::Deref;
 
 use super::{types::*, Pal, Sys};
 use c_str::CStr;
+use header::fcntl;
 
 pub struct RawFile(c_int);
 
@@ -49,7 +50,7 @@ impl Deref for RawFile {
 }
 
 pub fn file_read_all(path: &CStr) -> Result<Vec<u8>, ()> {
-    let file = RawFile::open(path, 0, 0o644)?;
+    let file = RawFile::open(path, fcntl::O_RDONLY, 0)?;
 
     let mut buf = Vec::new();
     let mut len = 0;
diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs
index ef927dca..6b6c8942 100644
--- a/src/platform/redox/mod.rs
+++ b/src/platform/redox/mod.rs
@@ -12,6 +12,7 @@ use syscall::{self, Result};
 use c_str::{CStr, CString};
 use header::dirent::dirent;
 use header::errno::{EINVAL, ENOSYS};
+use header::fcntl;
 const MAP_ANON: c_int = 1;
 //use header::sys_mman::MAP_ANON;
 //use header::sys_resource::rusage;
@@ -54,7 +55,7 @@ pub struct Sys;
 
 impl Pal for Sys {
     fn access(path: &CStr, mode: c_int) -> c_int {
-        let fd = match RawFile::open(path, 0, 0) {
+        let fd = match RawFile::open(path, fcntl::O_PATH, 0) {
             Ok(fd) => fd,
             Err(_) => return -1,
         };
@@ -167,7 +168,7 @@ impl Pal for Sys {
     ) -> c_int {
         use alloc::Vec;
 
-        let fd = match RawFile::open(path, O_RDONLY as c_int, 0) {
+        let fd = match RawFile::open(path, fcntl::O_RDONLY, 0) {
             Ok(fd) => fd,
             Err(_) => return -1,
         };
@@ -205,7 +206,7 @@ impl Pal for Sys {
                         Ok(path) => path,
                         Err(_) => return -1,
                     };
-                    match RawFile::open(&path, O_RDONLY as c_int, 0) {
+                    match RawFile::open(&path, fcntl::O_RDONLY, 0) {
                         Ok(file) => {
                             interpreter_fd = *file;
                             _interpreter_path = Some(path);
@@ -634,7 +635,7 @@ impl Pal for Sys {
         }
 
         let event_path = unsafe { CStr::from_bytes_with_nul_unchecked(b"event:\0") };
-        let event_file = match RawFile::open(event_path, 0, 0) {
+        let event_file = match RawFile::open(event_path, fcntl::O_RDWR, 0) {
             Ok(file) => file,
             Err(_) => return -1,
         };
@@ -682,7 +683,7 @@ impl Pal for Sys {
                     format!("time:{}\0", syscall::CLOCK_MONOTONIC).into_bytes(),
                 )
             };
-            let timeout_file = match RawFile::open(&timeout_path, 0, 0) {
+            let timeout_file = match RawFile::open(&timeout_path, fcntl::O_RDWR, 0) {
                 Ok(file) => file,
                 Err(_) => return -1,
             };
-- 
GitLab