blob: 1b7ac33685fdd5cd4e958b6a95577c0c7d6c3dc6 (
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
32
|
#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;
}
|