Embed templates

This commit is contained in:
kamkow1
2025-06-09 22:10:49 +02:00
parent ac48e49ecc
commit a8c5d7817d
8 changed files with 84 additions and 4 deletions

43
tmpls.c Normal file
View File

@ -0,0 +1,43 @@
#include <sys/mman.h>
#include <fcntl.h>
#include "gebs/gebs.h"
#include "stb/stb_ds.h"
#include "tmpls.h"
#include "baked.h"
Template *tmpls = NULL;
void create_tmpl(char *name, const unsigned char *data, size_t size)
{
int fd = memfd_create(name, 0);
if (fd < 0) {
LOGE("Could not create file for template %s. Aborting...\n", name);
abort();
}
write(fd, data, size);
shput(tmpls, name, fd);
}
void tmpls_init(void)
{
create_tmpl(TMPL_HOME, tmpl_home_data, tmpl_home_size);
create_tmpl(TMPL_PAGE_MISSING, tmpl_page_missing_data, tmpl_page_missing_size);
}
void tmpls_deinit(void)
{
shfree(tmpls);
}
void tmpl_get_path_by_key(char *key, char *buf, size_t size)
{
// Check first since we can't have a default value here
if (shgeti(tmpls, key) != -1) {
int fd = shget(tmpls, key);
snprintf(buf, size, "/proc/%d/fd/%d", getpid(), fd);
}
}