summaryrefslogtreecommitdiff
path: root/blog.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-07-18 19:37:23 -0400
committerJakob Kaivo <jkk@ung.org>2019-07-18 19:37:23 -0400
commitf87be61844fed4988ed90863854b19d047297a37 (patch)
tree7dc96d60b9cf94364d3e945d79362ff3acbe63c6 /blog.c
parentd0889f96707eb9bc27b3454269d4a7f3ccd35505 (diff)
add current_year() function for use in address
Diffstat (limited to 'blog.c')
-rw-r--r--blog.c18
1 files changed, 13 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;
}