Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
mmap_struct.cpp
Go to the documentation of this file.
2
3#include <fc/filesystem.hpp>
4
5#include <string.h>
6#include <fstream>
7#include <algorithm>
8
9namespace fc
10{
11 namespace detail
12 {
13 size_t mmap_struct_base::size()const { return _mapped_region->get_size(); }
15 {
16 _mapped_region->flush();
17 }
18
19 void mmap_struct_base::open( const fc::path& file, size_t s, bool create )
20 {
21 if( !fc::exists( file ) || fc::file_size(file) != s )
22 {
23 std::ofstream out( file.generic_string().c_str() );
24 char buffer[1024];
25 memset( buffer, 0, sizeof(buffer) );
26
27 size_t bytes_left = s;
28 while( bytes_left > 0 )
29 {
30 size_t to_write = std::min<size_t>(bytes_left, sizeof(buffer) );
31 out.write( buffer, to_write );
32 bytes_left -= to_write;
33 }
34 }
35
36 std::string filePath = file.to_native_ansi_path();
37
38 _file_mapping.reset( new fc::file_mapping( filePath.c_str(), fc::read_write ) );
40 }
41 } // namespace fc
42
43} // namespace fc
void open(const fc::path &file, size_t s, bool create)
std::unique_ptr< fc::mapped_region > _mapped_region
std::unique_ptr< fc::file_mapping > _file_mapping
wraps boost::filesystem::path to provide platform independent path manipulation.
namespace sysio::chain
Definition authority.cpp:3
@ read_write
bool exists(const path &p)
uint64_t file_size(const path &p)
char * s
memset(pInfo->slotDescription, ' ', 64)