-
Notifications
You must be signed in to change notification settings - Fork 1
/
KT_BinIO.cpp
69 lines (58 loc) · 1.02 KB
/
KT_BinIO.cpp
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
68
69
#include "KT_BinIO.h"
uint32_t KT_BinIO::Read(char *pszInput)
{
FILE *f;
f = fopen(pszInput, "rb");
if (f == NULL)
{
return 0;
}
fseek(f, 0, SEEK_END);
uint32_t lSize;
lSize = ftell(f);
rewind(f);
if (fread(pReadBuff, 1, lSize, f) != lSize)
{
fclose(f);
return 0;
}
fclose(f);
return 1;
}
uint32_t KT_BinIO::Write(char *pszOutput)
{
FILE *f;
f = fopen(pszOutput, "wb");
if (f == NULL)
{
return 0;
}
if (!fwrite(pWriteBuff, u32Size, 1, f))
{
fclose(f);
return 0;
}
fclose(f);
return 1;
}
uint32_t KT_BinIO::InitBuffer()
{
pReadBuff = (uint8_t *)malloc(u32Size);
if (pReadBuff == NULL)
{
return 0;
}
memset(pReadBuff, 0xFF, u32Size);
pWriteBuff = (uint8_t *)malloc(u32Size);
if (pWriteBuff == NULL)
{
return 0;
}
memset(pWriteBuff, 0xFF, u32Size);
return 1;
}
void KT_BinIO::FreeBuffer()
{
free(pReadBuff);
free(pWriteBuff);
}