forked from andreasbuhr/cppcoro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathread_write_file.cpp
More file actions
64 lines (57 loc) · 1.54 KB
/
Copy pathread_write_file.cpp
File metadata and controls
64 lines (57 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Lewis Baker
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#include <cppcoro/read_write_file.hpp>
#if CPPCORO_OS_WINNT
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
cppcoro::read_write_file cppcoro::read_write_file::open(
io_service& ioService,
const cppcoro::filesystem::path& path,
file_open_mode openMode,
file_share_mode shareMode,
file_buffering_mode bufferingMode)
{
return read_write_file(file::open(
GENERIC_READ | GENERIC_WRITE,
ioService,
path,
openMode,
shareMode,
bufferingMode));
}
cppcoro::read_write_file::read_write_file(
detail::win32::safe_handle&& fileHandle) noexcept
: file(std::move(fileHandle))
, readable_file(detail::win32::safe_handle{})
, writable_file(detail::win32::safe_handle{})
{
}
#elif CPPCORO_OS_LINUX
#include <fcntl.h>
cppcoro::read_write_file cppcoro::read_write_file::open(
io_service& ioService,
const std::filesystem::path& path,
file_open_mode openMode,
file_share_mode shareMode,
file_buffering_mode bufferingMode)
{
return read_write_file(file::open(
O_RDWR,
ioService,
path,
openMode,
shareMode,
bufferingMode));
}
cppcoro::read_write_file::read_write_file(
detail::linux::safe_file_data&& fileData) noexcept
: file(std::move(fileData))
, readable_file(detail::linux::safe_file_data{})
, writable_file(detail::linux::safe_file_data{})
{
}
#endif