summaryrefslogtreecommitdiff
path: root/platform/elf/osal.c
diff options
context:
space:
mode:
author0x221E2026-06-14 14:00:58 +0200
committer0x221E2026-06-14 14:00:58 +0200
commit56796c08d6388ad0eb0539d166cd12964cfeb7e9 (patch)
tree0a478620c3f07a72719fd22c12cbed5aa077234e /platform/elf/osal.c
initial commit
Diffstat (limited to 'platform/elf/osal.c')
-rw-r--r--platform/elf/osal.c57
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);
+}