-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASM76.cpp
More file actions
59 lines (51 loc) · 1.78 KB
/
ASM76.cpp
File metadata and controls
59 lines (51 loc) · 1.78 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
//=============================================================================
// ■ ASM76/ASM76.cpp
//-----------------------------------------------------------------------------
// 全局变量与实用函数。
//=============================================================================
#include "ASM76.hpp"
namespace ASM76 {
//-------------------------------------------------------------------------
// ● 全局变量
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// ● 初始化
//-------------------------------------------------------------------------
void init() {
puts("Init ASM76 environment");
// nothing to do here now
}
//-------------------------------------------------------------------------
// ● 结束处理
//-------------------------------------------------------------------------
void VMterminate() {
puts("Terminate ASM76 environment");
}
//-------------------------------------------------------------------------
// ● 以二进制模式读入整个文件并返回其长度
// 如果不能正常读取,则返回-1。
// buf : 用于返回指向文件内容的指针(char*),请自行free之
//-------------------------------------------------------------------------
long slurp(const char* filename, char** buf) {
FILE* fp;
size_t fsz;
long off_end;
fp = fopen(filename, "rb");
if (!fp) return -1;
if (fseek(fp, 0L, SEEK_END)) return -1;
off_end = ftell(fp);
if (off_end < 0) return -1;
fsz = (size_t) off_end;
*buf = (char*) malloc(fsz);
rewind(fp);
if (fread(*buf, 1, fsz, fp) != fsz) {
free(*buf);
return -1;
}
if (fclose(fp) == EOF) {
free(*buf);
return -1;
}
return (long) fsz;
}
}