-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfiledevice.hpp
50 lines (46 loc) · 1.59 KB
/
filedevice.hpp
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
// solid/system/filedevice.hpp
//
// Copyright (c) 2007, 2008 Valentin Palade (vipalade @ gmail . com)
//
// This file is part of SolidFrame framework.
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.
//
#pragma once
#include "seekabledevice.hpp"
#include <fcntl.h>
namespace solid {
//! Wrapper for a file descriptor
class FileDevice : public SeekableDevice {
public:
enum OpenMode {
ReadOnlyE = O_RDONLY, //!< Read only
WriteOnlyE = O_WRONLY, //!< Write only
ReadWriteE = O_RDWR, //!< Read write
TruncateE = O_TRUNC, //!< Truncate
AppendE = O_APPEND, //!< Append
CreateE = O_CREAT //!< Create
};
FileDevice();
//! returns the size of a file without opening it - using stat!
static int64_t size(const char* _fname);
//! Open a file using its name and open mode flags
bool open(const char* _fname, int _how);
//! Create a file using its name and open mode flags
bool create(const char* _fname, int _how);
//! Get the size of an opened file
/*!
Use FileDevice::size(const char*) to find the size of a file
without opening it
*/
int64_t size() const;
//! Check if a failed open opperation may succeed on retry
/*!
It uses errno so, it should be used imediatly after the open call.
It returns true in cases when the file could not be opened because
there were no available file descriptors or kernel memory.
*/
bool canRetryOpen() const;
};
} // namespace solid