Files
aboba/tmpls.c
2025-06-09 22:12:17 +02:00

47 lines
1006 B
C

#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)
{
for (size_t i = 0; i < shlen(tmpls); i++) {
close(tmpls[i].value);
}
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);
}
}