From defb396ee51c80d2df1c7bbc58dbefd0c6a0b165 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 26 Jul 2018 22:23:30 +0200 Subject: make: added atom_dump helper rule --- src/blogc-make/atom.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'src/blogc-make/atom.c') diff --git a/src/blogc-make/atom.c b/src/blogc-make/atom.c index 9dde35e..207b718 100644 --- a/src/blogc-make/atom.c +++ b/src/blogc-make/atom.c @@ -48,20 +48,11 @@ static const char atom_template[] = char* -bm_atom_deploy(bm_settings_t *settings, bc_error_t **err) +bm_atom_generate(bm_settings_t *settings) { - if (settings == NULL || err == NULL || *err != NULL) + if (settings == NULL) return NULL; - // this is not really portable - char fname[] = "/tmp/blogc-make_XXXXXX"; - int fd; - if (-1 == (fd = mkstemp(fname))) { - *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM, - "Failed to create temporary atom template: %s", strerror(errno)); - return NULL; - } - const char *atom_prefix = bc_trie_lookup(settings->settings, "atom_prefix"); const char *atom_ext = bc_trie_lookup(settings->settings, "atom_ext"); const char *post_prefix = bc_trie_lookup(settings->settings, "post_prefix"); @@ -93,13 +84,39 @@ bm_atom_deploy(bm_settings_t *settings, bc_error_t **err) entry_id = bc_strdup(post_url); } - char *content = bc_strdup_printf(atom_template, atom_url->str, atom_url->str, + char *rv = bc_strdup_printf(atom_template, atom_url->str, atom_url->str, entry_id, post_url); bc_string_free(atom_url, true); free(post_url); free(entry_id); + return rv; +} + + +char* +bm_atom_deploy(bm_settings_t *settings, bc_error_t **err) +{ + if (settings == NULL || err == NULL || *err != NULL) + return NULL; + + // this is not really portable + char fname[] = "/tmp/blogc-make_XXXXXX"; + int fd; + if (-1 == (fd = mkstemp(fname))) { + *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM, + "Failed to create temporary atom template: %s", strerror(errno)); + return NULL; + } + + char *content = bm_atom_generate(settings); + if (content == NULL) { + close(fd); + unlink(fname); + return NULL; + } + if (-1 == write(fd, content, strlen(content))) { *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM, "Failed to write to temporary atom template: %s", strerror(errno)); -- cgit v1.2.3-18-g5258