diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-07-26 22:23:30 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-07-26 22:23:30 +0200 |
commit | defb396ee51c80d2df1c7bbc58dbefd0c6a0b165 (patch) | |
tree | 4af8d88b10a57cc5c8e18147c6fe0696c2f33867 /src/blogc-make/atom.c | |
parent | 69caadbe08b27188ac0ab3bd0e49bf3ee4f8244c (diff) | |
download | blogc-defb396ee51c80d2df1c7bbc58dbefd0c6a0b165.tar.gz blogc-defb396ee51c80d2df1c7bbc58dbefd0c6a0b165.tar.bz2 blogc-defb396ee51c80d2df1c7bbc58dbefd0c6a0b165.zip |
make: added atom_dump helper rule
Diffstat (limited to 'src/blogc-make/atom.c')
-rw-r--r-- | src/blogc-make/atom.c | 41 |
1 files changed, 29 insertions, 12 deletions
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)); |