-
Notifications
You must be signed in to change notification settings - Fork 1
/
mustach-cjson.c
26 lines (22 loc) · 946 Bytes
/
mustach-cjson.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
int mustach_process_cjson(const char *template, size_t length, const char *value, size_t buffer_length, int flags, FILE *file, char **err);
#if __has_include("mustach/mustach-cjson.h")
#include "mustach/mustach-cjson.h"
int mustach_process_cjson(const char *template, size_t length, const char *value, size_t buffer_length, int flags, FILE *file, char **err) {
cJSON *root;
int rc = MUSTACH_ERROR_USER(1);
if (!(root = cJSON_ParseWithLength(value, buffer_length))) { *err = (char *)cJSON_GetErrorPtr(); goto ret; }
rc = mustach_cJSON_file(template, length, root, flags, file);
cJSON_Delete(root);
ret:
fclose(file);
return rc;
}
#else
#include <mustach/mustach.h>
int mustach_process_cjson(const char *template, size_t length, const char *value, size_t buffer_length, int flags, FILE *file, char **err) {
*err = "!mustach_cjson";
fclose(file);
return MUSTACH_ERROR_USER(1);
}
#endif