diff options
Diffstat (limited to 'platform/elf/osal.c')
| -rw-r--r-- | platform/elf/osal.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/platform/elf/osal.c b/platform/elf/osal.c new file mode 100644 index 0000000..414cd80 --- /dev/null +++ b/platform/elf/osal.c @@ -0,0 +1,57 @@ +#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 exitc(int c) +{ + exit(c); +} |
