Commit fd8a7235 authored by josé bollo's avatar josé bollo

Improves and fix 'mustach' function

Change-Id: I85fb3e2f884803c143c688497bb816849161943c Signed-off-by: josé bollo's avatarJosé Bollo <jobol@nonadev.net>
parent 88ae9f75
......@@ -201,21 +201,29 @@ int mustach(const char *template, struct mustach_itf *itf, void *closure, char *
{
int rc;
FILE *file;
size_t s;
*result = NULL;
if (size == NULL)
size = &s;
file = open_memstream(result, size);
if (file == NULL) {
rc = MUSTACH_ERROR_SYSTEM;
errno = ENOMEM;
} else {
*result = NULL;
rc = fmustach(template, itf, closure, file);
if (rc == 0)
fwrite(&rc, 1, 1, file); /* adds terminating null */
/* adds terminating null */
rc = fputc(0, file) ? MUSTACH_ERROR_SYSTEM : 0;
fclose(file);
if (rc < 0)
if (rc >= 0)
/* removes terminating null of the length */
(*size)--;
else {
free(*result);
else
(*size)--; /* removes terminating null of the length */
*result = NULL;
*size = 0;
}
}
return rc;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment