utils.hpp
864 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
/*
* File: utils.hpp
* Author: mlenart
*
* Created on 24 październik 2013, 17:56
*/
#ifndef UTILS_HPP
#define UTILS_HPP
#include <iostream>
#include <string>
void validate(const bool cond, const std::string& msg) {
if (!cond) {
std::cerr << msg << std::endl;
exit(1);
}
}
unsigned char* readFile(const char* fname) {
ifstream ifs;
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
ifs.open(fname, ios::in | ios::binary | ios::ate);
// if (ifs.is_open()) {
int size = ifs.tellg();
unsigned char* memblock = new unsigned char [size];
ifs.seekg(0, ios::beg);
ifs.read(reinterpret_cast<char*> (memblock), size);
ifs.close();
return memblock;
// }
// else {
// cerr << "Unable to open file " << fname << endl;
// }
}
#endif /* UTILS_HPP */