#include #include "gebs/gebs.h" #include "incbin/incbin.h" #include "stb/stb_ds.h" #include "baked.h" INCBIN(gpp1, "./gpp1"); INCBIN(home_html, "./tmpls/home.html"); INCBIN(page_missing_html, "./tmpls/page-missing.html"); INCBIN(template_blog_html, "./tmpls/template-blog.html"); INCBIN(blog_html, "./tmpls/blog.html"); INCBIN(simple_min_css, "./etc/simple.min.css"); INCBIN(favicon_ico, "./etc/favicon.ico"); INCBIN(hotreload_js, "./etc/hotreload.js"); INCBIN(blog_welcome_md, "./blog/welcome.md"); INCBIN(blog_weird_page_md, "./blog/weird-page.md"); INCBIN(blog_curious_case_of_gebs_md, "./blog/curious-case-of-gebs.md"); 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.html", home_html_data, home_html_size); add_baked_resource("page-missing.html", page_missing_html_data, page_missing_html_size); add_baked_resource("template-blog.html", template_blog_html_data, template_blog_html_size); add_baked_resource("blog.html", blog_html_data, blog_html_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); add_baked_resource("blog-welcome.md", blog_welcome_md_data, blog_welcome_md_size); add_baked_resource("blog-weird-page.md", blog_weird_page_md_data, blog_weird_page_md_size); add_baked_resource("blog-curious-case-of-gebs.md", blog_curious_case_of_gebs_md_data, blog_curious_case_of_gebs_md_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; } void baked_resource_each(void (*f)(Baked_Resource *resource)) { for (size_t i = 0; i < shlen(baked_resources); i++) { f(&baked_resources[i]); } }