diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-07-18 19:37:23 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-07-18 19:37:23 -0400 |
commit | f87be61844fed4988ed90863854b19d047297a37 (patch) | |
tree | 7dc96d60b9cf94364d3e945d79362ff3acbe63c6 | |
parent | d0889f96707eb9bc27b3454269d4a7f3ccd35505 (diff) |
add current_year() function for use in address
-rw-r--r-- | blog.c | 18 | ||||
-rw-r--r-- | blog.h | 2 |
2 files changed, 15 insertions, 5 deletions
@@ -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; } @@ -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 |