From a9af10ec42efa9d68573a5238ae5acade877b38a Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 15 Jul 2014 19:47:15 +1000 Subject: [PATCH] io: give fd_ref a flags argument --- io.cpp | 12 ++++++------ io.hpp | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/io.cpp b/io.cpp index a0fd3ce5..ccd7ac03 100644 --- a/io.cpp +++ b/io.cpp @@ -38,7 +38,7 @@ using namespace util; //---------------------------------------------------------------------------- std::unique_ptr util::slurp (const boost::filesystem::path& path) { - fd_ref fd(path); + fd_ref fd(path, O_RDONLY); // Calculate the total file size off_t size = lseek (fd, 0, SEEK_END); @@ -77,7 +77,7 @@ util::write (const boost::filesystem::path &path, const char *data, size_t len) CHECK_SOFT (len > 0); CHECK_HARD (data); - fd_ref fd (path); + fd_ref fd (path, O_WRONLY); const char *cursor = data; size_t remaining = len; @@ -100,11 +100,11 @@ fd_ref::fd_ref (int _fd): } -fd_ref::fd_ref (const boost::filesystem::path &path): +fd_ref::fd_ref (const boost::filesystem::path &path, int flags): #ifdef PLATFORM_WIN32 - fd (open (path.string ().c_str (), O_RDONLY | O_BINARY)) + fd (open (path.native ().c_str (), flags | O_BINARY)) #else - fd (open (path.string ().c_str (), O_RDONLY)) + fd (open (path.native ().c_str (), flags)) #endif { if (fd < 0) @@ -183,7 +183,7 @@ util::set_cwd (const boost::filesystem::path &path) { mapped_file::mapped_file (const boost::filesystem::path &_path): - m_fd (open (_path.native ().c_str (), O_RDWR)) + m_fd (_path, O_RDWR) { load_fd (); } diff --git a/io.hpp b/io.hpp index bd262044..8db2c273 100644 --- a/io.hpp +++ b/io.hpp @@ -46,13 +46,15 @@ namespace util { void write (const boost::filesystem::path &, const char *data, size_t len); + + ///------------------------------------------------------------------------ /// A simple RAII wrapper for file descriptors struct fd_ref { public: int fd; explicit fd_ref (int _fd); - explicit fd_ref (const boost::filesystem::path &); + explicit fd_ref (const boost::filesystem::path&, int flags); ~fd_ref (); operator int (void) const;