Bug Summary

File:atom.c
Warning:line 58, column 11
Value stored to 'foo' during its initialization is never read

Annotated Source Code

1/*
2 * blogc: A blog compiler.
3 * Copyright (C) 2014-2017 Rafael G. Martins <rafael@rafaelmartins.eng.br>
4 *
5 * This program can be distributed under the terms of the BSD License.
6 * See the file LICENSE.
7 */
8
9#include <stdlib.h>
10#include <string.h>
11#include <errno(*__errno_location ()).h>
12#include <unistd.h>
13#include "../common/error.h"
14#include "../common/utils.h"
15#include "settings.h"
16#include "atom.h"
17
18static const char atom_template[] =
19 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
20 "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"
21 " <title type=\"text\">{{ SITE_TITLE }}{%% ifdef FILTER_TAG %%} - "
22 "{{ FILTER_TAG }}{%% endif %%}</title>\n"
23 " <id>{{ BASE_URL }}/%s{%% ifdef FILTER_TAG %%}/{{ FILTER_TAG }}"
24 "{%% endif %%}%s</id>\n"
25 " <updated>{{ DATE_FIRST_FORMATTED }}</updated>\n"
26 " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/\" />\n"
27 " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/%s{%% ifdef FILTER_TAG %%}"
28 "/{{ FILTER_TAG }}{%% endif %%}%s\" rel=\"self\" />\n"
29 " <author>\n"
30 " <name>{{ AUTHOR_NAME }}</name>\n"
31 " <email>{{ AUTHOR_EMAIL }}</email>\n"
32 " </author>\n"
33 " <subtitle type=\"text\">{{ SITE_TAGLINE }}</subtitle>\n"
34 " {%% block listing %%}\n"
35 " <entry>\n"
36 " <title type=\"text\">{{ TITLE }}</title>\n"
37 " <id>{{ BASE_URL }}/%s/{{ FILENAME }}/</id>\n"
38 " <updated>{{ DATE_FORMATTED }}</updated>\n"
39 " <published>{{ DATE_FORMATTED }}</published>\n"
40 " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/%s/{{ FILENAME }}/\" />\n"
41 " <author>\n"
42 " <name>{{ AUTHOR_NAME }}</name>\n"
43 " <email>{{ AUTHOR_EMAIL }}</email>\n"
44 " </author>\n"
45 " <content type=\"html\"><![CDATA[{{ CONTENT }}]]></content>\n"
46 " </entry>\n"
47 " {%% endblock %%}\n"
48 "</feed>\n";
49
50
51char*
52bm_atom_deploy(bm_settings_t *settings, bc_error_t **err)
53{
54 if (err == NULL((void*)0) || *err != NULL((void*)0))
55 return NULL((void*)0);
56
57 // FIXME: remove this line, intentional for temporary testing
58 void *foo = bc_malloc(10);
Value stored to 'foo' during its initialization is never read
59
60 // this is not really portable
61 char fname[] = "/tmp/blogc-make_XXXXXX";
62 int fd;
63 if (-1 == (fd = mkstemp(fname))) {
64 *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM,
65 "Failed to create temporary atom template: %s", strerror(errno(*__errno_location ())));
66 return NULL((void*)0);
67 }
68
69 const char *atom_prefix = bc_trie_lookup(settings->settings, "atom_prefix");
70 const char *atom_ext = bc_trie_lookup(settings->settings, "atom_ext");
71 const char *post_prefix = bc_trie_lookup(settings->settings, "post_prefix");
72
73 char *content = bc_strdup_printf(atom_template, atom_prefix, atom_ext,
74 atom_prefix, atom_ext, post_prefix, post_prefix);
75
76 if (-1 == write(fd, content, strlen(content))) {
77 *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM,
78 "Failed to write to temporary atom template: %s", strerror(errno(*__errno_location ())));
79 free(content);
80 close(fd);
81 unlink(fname);
82 return NULL((void*)0);
83 }
84
85 free(content);
86 close(fd);
87
88 return bc_strdup(fname);
89}
90
91
92void
93bm_atom_destroy(const char *fname)
94{
95 unlink(fname);
96}