#include "TZR_resource.h" #include "TZR_globals.h" #include "drain.h" #include #include TZR_Uint TZR_LoadResourceTyped(TZR_ResourceType type, const char *path) { for (TZR_Uint i = 0; i < ___tzr_resources_size; i++) if (___tzr_resources[i].type == type && strcmp(___tzr_resources[i].path, path) == 0) return i + 1; FILE *const fp = fopen(path, "rb"); if (fp == NULL) { perror(path); return 0; } size_t size; char *const data = drain(fp, &size); fclose(fp); if (data == NULL) return 0; const TZR_Uint id = TZR_LoadResourceFromMemory(type, data, size); free(data); if (id == 0) return 0; TZR_Resource *const res = TZR_GetResourcePointer(id); const size_t path_len = strlen(path); struct stat st = {0}; (void)stat(path, &st); res->path = malloc(path_len + 1); res->mtime = 0; if (res->path == NULL) perror("TZR_LoadResourceTyped"); else strcpy(res->path, path); return id; }