summaryrefslogtreecommitdiff
path: root/prb_linux.h
diff options
context:
space:
mode:
Diffstat (limited to 'prb_linux.h')
-rw-r--r--prb_linux.h90
1 files changed, 0 insertions, 90 deletions
diff --git a/prb_linux.h b/prb_linux.h
deleted file mode 100644
index 64485d6..0000000
--- a/prb_linux.h
+++ /dev/null
@@ -1,90 +0,0 @@
-#include <sys/mman.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-
-void *sys_alloc(u64 length)
-{
- assert(length);
- void *result = mmap(0, length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
- return result;
-}
-
-void sys_free(void *memory, u64 length)
-{
- assert(memory);
- assert(length);
- munmap(memory, length);
-}
-
-void die(const char *error_string, ...)
-{
- va_list args;
- va_start(args, error_string);
- fprintf(stderr, "error: ");
- vfprintf(stderr, error_string, args);
- fprintf(stderr, "\n");
- va_end(args);
- _exit(1);
-}
-
-void info(const char *format, ...)
-{
- va_list args;
- va_start(args, format);
- printf("info: ");
- vprintf(format, args);
- printf("\n");
- va_end(args);
-}
-
-u64 sys_read_file(arena_t *arena, char **buffer, const char *filename)
-{
- FILE *file = fopen(filename, "rb");
- if (!file)
- return 0;
-
- if (fseek(file, 0, SEEK_END) == -1)
- goto error;
- long len = ftell(file);
- if (!len || (len == -1))
- goto error;
- if (fseek(file, 0, SEEK_SET) == -1)
- goto error;
-
- *buffer = push_arena(arena, len + 1);
- if (!fread(*buffer, 1, len, file)) {
- pop_arena(arena, len + 1);
- *buffer = 0;
- goto error;
- }
- (*buffer)[len] = 0;
- fclose(file);
-
- return len;
-error:
- fclose(file);
- *buffer = 0;
- return 0;
-}
-
-char *sys_getbindir(arena_t *arena)
-{
- char path[MAX_PATH];
- i64 len = readlink("/proc/self/exe", path, MAX_PATH - 1);
- if (len <= 0)
- return 0;
-
- path[len] = 0;
-
- char *dir = strrchr(path, '/');
- assert(dir);
- assert(dir > path);
-
- len = dir - path;
- dir = push_arena(arena, len + 1);
- prb_memmove(dir, path, len);
- dir[len] = 0;
-
- return dir;
-}