-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFileUtil.h
executable file
·37 lines (33 loc) · 1.12 KB
/
FileUtil.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
#ifndef _CSTRINGFILE_H_
#define _CSTRINGFILE_H_
#include <windows.h>
class FileUtil {
private:
HANDLE m_file; // file handle
DWORD m_file_size; // file size
BYTE* m_buffer; // the buffer for reading
int m_buffer_size; // its size
int m_buffer_index; // current parsing position
int m_buffer_readed; // the size of the buffer read in memory
int m_buffer_line; // the counter of lines in a file
public:
FileUtil(const int nBufSize = 65536);
~FileUtil();
bool Open(LPCTSTR lpFileName, const DWORD dwAccess, const DWORD dwCreationFlags);
inline void Close() {
if (m_file != INVALID_HANDLE_VALUE) {
CloseHandle(m_file);
m_file = INVALID_HANDLE_VALUE;
}
m_file_size = 0;
}
inline DWORD Size() const {
return (m_file_size);
}
int Read(void* buffer, const DWORD length);
int Write(const void* buffer, const DWORD length);
void Reset();
int GetNextLine(char* line, const int maxsize);
};
//+------------------------------------------------------------------+
#endif // !_STRINGFILE_H_