forked from ngaut/goTorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileOp.c
63 lines (48 loc) · 1008 Bytes
/
fileOp.c
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
#include "fileOp.h"
#include <stdio.h>
#include <fcntl.h>
#define _FILE_OFFSET_BITS 64
void ShowMessage(char* str)
{
printf("%s\n", str);
MessageBoxA(NULL, str, "", MB_OK);
}
int ReadAt(int fd, void* buf, int len, __int64 offset){
int n = _lseeki64(fd, offset, SEEK_SET);
if (n == -1)
{
printf("_lseeki64 errno %d\n", errno);
ShowMessage("oops _lseeki64 failed");
}
n = _read(fd, buf, len);
//printf("ReadAt %I64d\n", offset);
if (n <= 0)
{
printf("errno %d\n", errno);
ShowMessage("oops");
}
return n;
}
int WriteAt(int fd, void* buf, int len, __int64 offset){
int n = _lseeki64(fd, offset, SEEK_SET);
if (n == -1)
{
printf("_lseeki64 errno %d\n", errno);
ShowMessage("oops");
}
n = _write(fd, buf, len);
//printf("WriteAt %I64d\n", offset);
if (n <= 0)
{
printf("errno %d\n", errno);
ShowMessage("oops");
}
return n;
}
int Open(const char* fname, int oflag){
return _open(fname, oflag);
}
void Close(int fd){
ShowMessage("close file");
_close(fd);
}