feat(ltm): add file data support
This commit is contained in:
parent
c26c8cf18a
commit
f37cfc30af
7 changed files with 86 additions and 4 deletions
34
ltm/example/test.c
Normal file
34
ltm/example/test.c
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue