-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_op_test.cpp
More file actions
51 lines (44 loc) · 1.4 KB
/
Copy pathfile_op_test.cpp
File metadata and controls
51 lines (44 loc) · 1.4 KB
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
#include "file_op.h"
using namespace std;
using namespace qiniu;
int main(void) {
const char* fileName = "file_op.txt";
largefile::FileOperation* fileOP = new largefile::FileOperation(fileName, O_CREAT | O_RDWR | O_LARGEFILE);
int fd = fileOP->open_file();
if (fd < 0) {
fprintf(stderr, "open file %s failed, reason: %s\n", fileName, strerror(-fd));
exit(-1);
}
else
printf("open file successfully\n");
char buffer[65];
memset(buffer, '8', 64);
int ret = fileOP->pWrite_file(buffer, 64, 128);
if (ret < 0) {
if (ret == largefile::EXIT_DISK_OPER_INCOMPLETE)
fprintf(stderr, "write file: read length is less than required.");
else
fprintf(stderr, "pwrite file %s failed. Reason: %s\n", fileName, strerror(-ret));
}
memset(buffer, 0, 64);
ret = fileOP->pRead_file(buffer, 64, 128);
if (ret < 0) {
if (ret == largefile::EXIT_DISK_OPER_INCOMPLETE)
fprintf(stderr, "pRead file: read length is less than required.");
else
fprintf(stderr, "pread file %s failed, reason: %s\n", fileName, strerror(-ret));
}
else {
buffer[64] = '\0';
printf("read: %s\n", buffer);
}
memset(buffer, '2', 64);
ret = fileOP->write_file(buffer, 64);
if (ret < 0) {
if (ret == largefile::EXIT_DISK_OPER_INCOMPLETE)
fprintf(stderr, "pwrite file: read length is less than required.");
else
fprintf(stderr, "pwrite file %s failed. Reason: %s\n", fileName, strerror(-ret));
}
fileOP->close_file();
}