summaryrefslogtreecommitdiff
path: root/platform/elf/osal.c
blob: 2630b97e40920252d0ea7100a9f0f8370eddaafd (plain)
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
#include <platform/osal.h>

#include <stdlib.h>
#include <stdio.h>

#include <stdarg.h>

#include <assert.h>

void *mem_alloc(size_t s)
{
	return malloc(s);
}

void mem_free(void *p)
{
	free(p);
}

struct file open_file(const char *path, int flags)
{
	assert(path != NULL);
	
	FILE *file;

	if (flags & FILE_READ) {
		file = fopen(path, "rb");
	} else {
		printf("Read option not specified for file read!");
		exit(1);
	}

	fseek(file, 0, SEEK_END);
	long fsize = ftell(file);
	fseek(file, 0, SEEK_SET);

	char *content = malloc(fsize + 1);
	fread(content, fsize, 1, file);
	fclose(file);

	content[fsize] = 0;

	return (struct file) {.path=path, .buffer=content, .size=fsize};
}

void print(const char *fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	vprintf(fmt, args);
	va_end(args);
}

void printv(const char *fmt, va_list l)
{
	vprintf(fmt, l);
}

void exitc(int c)
{
	exit(c);
}