#include "sys.h" #include "types.h" #include #include #include #include #include void info(const char *fmt, ...) { va_list args; va_start(args, fmt); printf("info: "); vprintf(fmt, args); printf("\n"); va_end(args); } void die(const char *fmt, ...) { va_list args; va_start(args, fmt); fprintf(stderr, "error: "); vfprintf(stderr, fmt, args); printf("\n"); va_end(args); _exit(1); } void *read_entire_file(const char *filename) { void *result = 0; FILE *file = fopen(filename, "rb"); if (!file) return result; fseek(file, 0, SEEK_END); long size = ftell(file); fseek(file, 0, SEEK_SET); result = malloc(size + 1); fread(result, size, 1, file); fclose(file); *((u8 *)result + size) = '\0'; return result; } const char *get_bin_dir(void) { char path[512]; i64 len = readlink("/proc/self/exe", path, 512 - 1); if (len <= 0) return 0; path[len] = '\0'; char *dir = strrchr(path, '/'); len = dir - path; dir = malloc(len + 1); memmove(dir, path, len); dir[len] = '\0'; return dir; }