blob: f87ee769ac97c5dd2d89f1f370265d12454f6fac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include "TZR_resource.h"
#include "drain.h"
#include <sys/stat.h>
int TZR_ReloadResource(TZR_Uint id)
{
TZR_Resource *const res = TZR_GetResourcePointer(id);
if (res->path == NULL) {
fprintf(stderr, "resource path of %u is NULL\n", id);
return -1;
}
FILE *const fp = fopen(res->path, "rb");
if (fp == NULL) {
perror(res->path);
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;
}
|