-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReader.cpp
More file actions
73 lines (61 loc) · 1.22 KB
/
FileReader.cpp
File metadata and controls
73 lines (61 loc) · 1.22 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "FileReader.h"
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#pragma warning(disable:4996);
namespace HciExampleComon{
FileReader::FileReader()
{
buff_ = NULL;
buff_len_ = 0;
}
FileReader::~FileReader()
{
Free();
}
bool FileReader::Load(const char * pszLibName, int nExtraBytes)
{
FILE * fp = NULL;
fp = fopen(pszLibName, "rb");
if (fp == NULL)
return false;
fseek(fp,0,SEEK_END);
buff_len_=ftell(fp);
fseek(fp,0,SEEK_SET);
if (buff_len_ == 0)
{
fclose(fp);
return false;
}
buff_ = (unsigned char*)malloc(buff_len_ + nExtraBytes);
if (buff_ == NULL)
{
fclose(fp);
return false;
}
fread( buff_, 1, buff_len_, fp);
if (ferror(fp) != 0)
{
fclose(fp);
free(buff_);
buff_ = NULL;
return false;
}
fclose(fp);
if (nExtraBytes != 0)
{
memset(buff_ + buff_len_, 0, nExtraBytes);
buff_len_ += nExtraBytes;
}
return true;
}
void FileReader::Free()
{
if (buff_ != NULL)
{
free(buff_);
buff_ = NULL;
}
buff_len_ = 0;
}
}