feat(ltm): add file data support

This commit is contained in:
Jef Roosens 2023-12-16 22:15:21 +01:00
parent c26c8cf18a
commit f37cfc30af
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
7 changed files with 86 additions and 4 deletions

34
ltm/example/test.c Normal file
View file

@ -0,0 +1,34 @@
#include <stdio.h>
#include <sys/stat.h>
#include "ltm/template.h"
const char *s = "<body><pre><code>\n"
"{{ paste }}\n"
"</code></pre></body>";
int main() {
ltm_template *template;
ltm_template_compile(&template, s);
ltm_instance *instance;
ltm_template_instantiate(&instance, template);
struct stat sb;
stat("Makefile", &sb);
FILE *f = fopen("Makefile", "rb");
ltm_instance_block_add_var(instance, "paste", ltm_instance_block_type_file_owned, f, sb.st_size);
char buf[1024];
size_t written = 0;
while (ltm_instance_write(&written, buf, 1024, instance) != ltm_err_done) {
printf("%.*s", (int)written, buf);
}
printf("%.*s", (int)written, buf);
ltm_instance_free(instance);
ltm_template_free(template);
}