summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blog.c18
-rw-r--r--blog.h2
2 files changed, 15 insertions, 5 deletions
diff --git a/blog.c b/blog.c
index 5ff100b..2685eb2 100644
--- a/blog.c
+++ b/blog.c
@@ -9,6 +9,17 @@
#include <unistd.h>
#include "blog.h"
+int current_year(void)
+{
+ static int year = 0;
+ if (year == 0) {
+ time_t t = time(NULL);
+ struct tm *tm = localtime(&t);
+ year = tm->tm_year + 1900;
+ }
+ return year;
+}
+
int handle_post(void)
{
read_post_data();
@@ -60,14 +71,13 @@ int handle_post(void)
if (write(newpost, body, strlen(body)) != strlen(body)) {
return 1;
}
- dprintf(newpost, HTML_TAIL, tm->tm_year + 1900);
+ dprintf(newpost, HTML_TAIL, current_year());
close(newpost);
close(blogdir);
add_to_index(uri, title);
-
printf("Status: 302 Found\r\n");
printf("Location: http%s://%s/%s\r\n\r\n", getenv("HTTPS") ? "s" : "", getenv("HTTP_HOST"), uri);
return 0;
@@ -93,9 +103,7 @@ int main(void)
puts("<input type=\"submit\">");
puts("</form>");
- time_t t = time(NULL);
- struct tm *tm = localtime(&t);
- printf(HTML_TAIL, tm->tm_year + 1900);
+ printf(HTML_TAIL, current_year());
return 0;
}
diff --git a/blog.h b/blog.h
index d61d670..590c18b 100644
--- a/blog.h
+++ b/blog.h
@@ -29,4 +29,6 @@ int show_entry(const char *path);
void add_to_index(const char *path, const char *title);
+int current_year(void);
+
#endif