#include "TZR_resource.h" #include "drain.h" #include #include int TZR_ReloadResource(TZR_Uint id) { TZR_Resource *const res = TZR_GetResourcePointer(id); if (res->path == NULL) { TZR_Log("resource path of %u is NULL", id); return -1; } FILE *const fp = fopen(res->path, "rb"); if (fp == NULL) { TZR_Log("%s: %s", res->path, strerror(errno)); return -1; } size_t size; char *const data = drain(fp, &size); fclose(fp); if (data == NULL) return -1; TZR_Resource new_res; memcpy(&new_res, res, sizeof(TZR_Resource)); const int load_rv = TZR_DirectResourceLoad(&new_res, data, size); free(data); if (load_rv) return -1; TZR_DestroyResource(res, 0); memcpy(res, &new_res, sizeof(TZR_Resource)); return 0; }