-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwritefile.h
More file actions
41 lines (32 loc) · 754 Bytes
/
writefile.h
File metadata and controls
41 lines (32 loc) · 754 Bytes
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
#pragma once
#ifndef WRITEFILE_H
#define WRITEFILE_H
#include <algorithm>
#include <string>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
class WriteFile
{
public:
WriteFile(std::string sFilePath);
~WriteFile();
WriteFile(const WriteFile &) = delete;
WriteFile & operator= (const WriteFile &) = delete;
void Append(const char * data, size_t writeSize);
void Flush();
void Sync();
void Close();
private:
void WriteUnbuffered(const char * data, size_t writeSize);
private:
static const size_t kWriteFileBufferSize = 65536;
int m_fd;
// m_buff[0, m_pos - 1] contains data to be written to m_fd.
char m_buff[kWriteFileBufferSize];
size_t m_pos;
};
#endif