diff options
-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 |