-
Notifications
You must be signed in to change notification settings - Fork 75
/
fileio.h
67 lines (55 loc) · 1.19 KB
/
fileio.h
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
65
66
67
#ifndef FILEIO_H_
#define FILEIO_H_
#include <cstddef>
#ifdef _WIN32
#ifndef UNICODE
#define UNICODE
#endif // UNICODE
#ifndef _UNICODE
#define _UNICODE
#endif // _UNICODE
#include <Windows.h>
#else
#include <sys/stat.h>
#include <sys/types.h>
#endif // _WIN32
class File {
public:
#ifdef _WIN32
explicit File(const wchar_t* filepath);
#else
explicit File(const char* filepath);
#endif // _WIN32
~File() {
if (fp_ != nullptr)
UnMapFile(size_);
}
// Disallow copy and assign.
File(const File&) = delete;
File& operator=(const File&) = delete;
void* GetFilePointer() const {
return fp_;
}
unsigned int GetSize() const {
return size_;
}
bool IsOK() const {
return fp_ != nullptr;
}
void UnMapFile(size_t new_size);
private:
#ifdef _WIN32
HANDLE hFile_ = INVALID_HANDLE_VALUE;
HANDLE hMap_ = INVALID_HANDLE_VALUE;
#else
int fd_ = -1;
#endif // _WIN32
void* fp_ = nullptr;
size_t size_ = 0;
};
#ifdef _WIN32
void TraversePath(const wchar_t* dir, int Callback(const wchar_t* file_path));
#else
void TraversePath(const char* dir, int Callback(const char* file_path, const struct stat* sb, int typeflag));
#endif // _WIN32
#endif // FILEIO_H_