-
Notifications
You must be signed in to change notification settings - Fork 3
/
tinyx86.c
55 lines (48 loc) · 971 Bytes
/
tinyx86.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
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <tinyx86.h>
#include <unistd.h>
tinyx86_file_t tinyx86_file_open(const char* path, char* flags)
{
tinyx86_file_t file = fopen(path, flags);
return file;
}
int tinyx86_file_close(tinyx86_file_t file)
{
int ret = fclose(file);
if (ret) {
return -errno;
}
return 0;
}
ssize_t tinyx86_file_read(tinyx86_file_t file, uint8_t* buffer, size_t size)
{
size_t ret = fread(buffer, 1, size, file);
if (ret < size) {
if (ferror(file)) {
return -errno;
}
}
return ret;
}
size_t tinyx86_file_size(tinyx86_file_t file)
{
size_t start = ftell(file);
fseek(file, 0, SEEK_END);
size_t size = ftell(file);
fseek(file, start, SEEK_SET);
return size;
}
void* tinyx86_malloc(size_t size)
{
return malloc(size);
}
void tinyx86_free(void* addr)
{
return free(addr);
}
void tinyx86_exit(int code)
{
exit(code);
}