59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
#include <sys/mman.h>
|
|
|
|
#include "gebs/gebs.h"
|
|
#include "incbin/incbin.h"
|
|
#include "stb/stb_ds.h"
|
|
|
|
#include "baked.h"
|
|
|
|
INCBIN(gpp1, "./gpp1");
|
|
|
|
INCBIN(home_t, "./tmpls/home.t");
|
|
INCBIN(page_missing_t, "./tmpls/page-missing.t");
|
|
|
|
INCBIN(simple_min_css, "./etc/simple.min.css");
|
|
INCBIN(favicon_ico, "./etc/favicon.ico");
|
|
INCBIN(hotreload_js, "./etc/hotreload.js");
|
|
|
|
Baked_Resource *baked_resources = NULL;
|
|
|
|
void add_baked_resource(char *key, const uchar *data, size_t size)
|
|
{
|
|
int fd = memfd_create(key, 0);
|
|
if (fd < 0) {
|
|
LOGE("Could not create resource %s. Aborting...\n", key);
|
|
abort();
|
|
}
|
|
write(fd, data, size);
|
|
shput(baked_resources, key, fd);
|
|
}
|
|
|
|
void init_baked_resources(void)
|
|
{
|
|
add_baked_resource("home.t", home_t_data, home_t_size);
|
|
add_baked_resource("page-missing.t", page_missing_t_data, page_missing_t_size);
|
|
add_baked_resource("gpp1", gpp1_data, gpp1_size);
|
|
add_baked_resource("simple.min.css", simple_min_css_data, simple_min_css_size);
|
|
add_baked_resource("favicon.ico", favicon_ico_data, favicon_ico_size);
|
|
add_baked_resource("hotreload.js", hotreload_js_data, hotreload_js_size);
|
|
}
|
|
|
|
void free_baked_resources(void)
|
|
{
|
|
for (size_t i = 0; i < shlen(baked_resources); i++) {
|
|
close(baked_resources[i].value);
|
|
}
|
|
shfree(baked_resources);
|
|
}
|
|
|
|
bool get_baked_resource_path(char *key, char *buf, size_t size)
|
|
{
|
|
if (shgeti(baked_resources, key) != -1) {
|
|
int fd = shget(baked_resources, key);
|
|
snprintf(buf, size, "/proc/%d/fd/%d", getpid(), fd);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|