io: remove our wrapper flag types
This commit is contained in:
parent
9bbcfa6e63
commit
80158b7343
2
io.cpp
2
io.cpp
@ -216,5 +216,5 @@ path_error::path_error (const boost::filesystem::path &_path):
|
|||||||
const char*
|
const char*
|
||||||
path_error::path (void) const noexcept
|
path_error::path (void) const noexcept
|
||||||
{
|
{
|
||||||
return m_path.c_str ();
|
return m_path.string ().c_str ();
|
||||||
}
|
}
|
||||||
|
2
io.hpp
2
io.hpp
@ -21,6 +21,8 @@
|
|||||||
#include "platform.hpp"
|
#include "platform.hpp"
|
||||||
#include "nocopy.hpp"
|
#include "nocopy.hpp"
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
48
io_win32.cpp
48
io_win32.cpp
@ -14,10 +14,10 @@
|
|||||||
* Copyright 2014 Danny Robson <danny@nerdcruft.net>
|
* Copyright 2014 Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "io_win32.hpp"
|
#include "./io_win32.hpp"
|
||||||
|
|
||||||
#include "debug.hpp"
|
#include "./debug.hpp"
|
||||||
#include "except.hpp"
|
#include "./except.hpp"
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
@ -26,38 +26,40 @@ using util::detail::win32::mapped_file;
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
static DWORD
|
static DWORD
|
||||||
access_to_flags (util::access_t a) {
|
fflags_to_native (int flags) {
|
||||||
switch (a) {
|
switch (flags) {
|
||||||
case util::ACCESS_READ:
|
case O_RDONLY: return GENERIC_READ;
|
||||||
return GENERIC_READ;
|
case O_WRONLY: return GENERIC_WRITE;
|
||||||
|
case O_RDWR: return GENERIC_READ | GENERIC_WRITE;
|
||||||
case util::ACCESS_WRITE:
|
|
||||||
return GENERIC_WRITE;
|
|
||||||
|
|
||||||
default:
|
|
||||||
unreachable ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unreachable ();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
mapped_file::mapped_file (const boost::filesystem::path &path,
|
mapped_file::mapped_file (const boost::filesystem::path &path,
|
||||||
access_t access):
|
int fflags,
|
||||||
|
int mflags):
|
||||||
m_data (nullptr, UnmapViewOfFile)
|
m_data (nullptr, UnmapViewOfFile)
|
||||||
{
|
{
|
||||||
m_file.reset (CreateFile (path.string ().c_str (),
|
m_file.reset (
|
||||||
access_to_flags (access),
|
CreateFile (
|
||||||
access == ACCESS_READ ? FILE_SHARE_READ : 0,
|
path.string ().c_str (),
|
||||||
nullptr,
|
fflags_to_native (fflags),
|
||||||
OPEN_EXISTING,
|
fflags & O_RDONLY ? FILE_SHARE_READ : 0,
|
||||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
|
nullptr,
|
||||||
0));
|
OPEN_EXISTING,
|
||||||
|
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if (m_file == INVALID_HANDLE_VALUE)
|
if (m_file == INVALID_HANDLE_VALUE)
|
||||||
win32_error::throw_code ();
|
win32_error::throw_code ();
|
||||||
|
|
||||||
m_mapping.reset (CreateFileMapping (m_file,
|
m_mapping.reset (CreateFileMapping (m_file,
|
||||||
nullptr,
|
nullptr,
|
||||||
access == ACCESS_READ ? PAGE_READONLY : PAGE_READWRITE,
|
access == O_RDONLY ? PAGE_READONLY : PAGE_READWRITE,
|
||||||
0, 0,
|
0, 0,
|
||||||
nullptr));
|
nullptr));
|
||||||
|
|
||||||
@ -65,7 +67,7 @@ mapped_file::mapped_file (const boost::filesystem::path &path,
|
|||||||
win32_error::throw_code ();
|
win32_error::throw_code ();
|
||||||
|
|
||||||
auto view = MapViewOfFile (m_mapping,
|
auto view = MapViewOfFile (m_mapping,
|
||||||
access == ACCESS_READ ? FILE_MAP_READ : FILE_MAP_WRITE,
|
access == O_RDONLY ? FILE_MAP_READ : FILE_MAP_WRITE,
|
||||||
0, 0,
|
0, 0,
|
||||||
0);
|
0);
|
||||||
if (view == nullptr)
|
if (view == nullptr)
|
||||||
|
13
io_win32.hpp
13
io_win32.hpp
@ -22,13 +22,24 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
namespace detail { namespace win32 {
|
namespace detail { namespace win32 {
|
||||||
|
enum {
|
||||||
|
PROT_NONE = 0,
|
||||||
|
PROT_READ = 1 << 0,
|
||||||
|
PROT_EXEC = 1 << 1,
|
||||||
|
PROT_WRITE = 1 << 2
|
||||||
|
};
|
||||||
|
|
||||||
class mapped_file {
|
class mapped_file {
|
||||||
public:
|
public:
|
||||||
mapped_file (const boost::filesystem::path &path,
|
mapped_file (const boost::filesystem::path &path,
|
||||||
access_t access = ACCESS_READ);
|
int fflags = O_RDONLY | O_BINARY,
|
||||||
|
int mflags = PROT_READ);
|
||||||
|
|
||||||
mapped_file (const mapped_file&) = delete;
|
mapped_file (const mapped_file&) = delete;
|
||||||
mapped_file& operator= (const mapped_file&) = delete;
|
mapped_file& operator= (const mapped_file&) = delete;
|
||||||
|
Loading…
Reference in New Issue
Block a user