Line data Source code
1 : //
2 : // Author: Vladimir Migashko <migashko@gmail.com>, (C) 2012
3 : //
4 : // Copyright: See COPYING file that comes with this distribution
5 : //
6 :
7 : #ifndef VSET_VSET_BUFFER_PERSISTENT_FILE_AD_OPEN_FILE_HPP
8 : #define VSET_VSET_BUFFER_PERSISTENT_FILE_AD_OPEN_FILE_HPP
9 :
10 : #include <vset/buffer/tags.hpp>
11 : #include <vset/buffer/persistent/tags.hpp>
12 :
13 : #include <fcntl.h>
14 : #include <stdexcept>
15 : #include <errno.h>
16 :
17 : namespace vset { namespace buffer { namespace persistent{ namespace file{
18 :
19 12 : struct ad_open_file
20 : {
21 : template<typename T>
22 22 : void operator()( T& t )
23 : {
24 22 : if ( t.get_aspect().template get<_descriptor_>() != -1 )
25 : {
26 0 : t.get_aspect().template get<_close_file_>();
27 : }
28 :
29 22 : int d = ::open( t.get_aspect().template get<_file_name_>().c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );
30 22 : t.get_aspect().template get<_descriptor_>() = d;
31 22 : if (d == -1)
32 : {
33 0 : throw std::runtime_error(strerror(errno));
34 : }
35 22 : }
36 : };
37 :
38 : }}}}
39 :
40 : #endif
|