From 93a4e3f741a8e37967915fd8b51f651992662d76 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Sat, 28 Dec 2019 01:56:15 +1030 Subject: implement gettime() --- pages.c | 18 ++++++++++++------ pages.h | 3 ++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pages.c b/pages.c index b6c396a..d9e2e8f 100644 --- a/pages.c +++ b/pages.c @@ -307,6 +307,7 @@ replaceinpage(const char *outfile, const char *toreplace, struct fileorstring *s * replace 'toreplace' in file 'outfile' taking 'infile' as input * return 1 on success, 0 on failure */ + long substrpos = -1; substrpos = findstring(frontpage_index_output, toreplace); @@ -329,9 +330,16 @@ replaceinpage(const char *outfile, const char *toreplace, struct fileorstring *s } char -*gettime() +*gettime(char *buffer, size_t size) { - return "10/10/2019"; + /* + * put the current date into a buffer and return it + */ + + time_t t = time(NULL); + struct tm tm = *localtime(&t); + snprintf(buffer, size, "%d/%d/%d", tm.tm_mday, tm.tm_mon+1, tm.tm_year + 1900); + return buffer; } int @@ -357,10 +365,11 @@ frontpage(int flags) return 0; } + char date[255]; struct fileorstring index = {frontpage_index, NULL}; struct fileorstring title = {NULL, frontpage_title}; struct fileorstring info = {NULL, frontpage_info}; - struct fileorstring time = {NULL, gettime()}; + struct fileorstring time = {NULL, gettime(date, 255)}; if (!replaceinpage(frontpage_index_output, content_string, &index) || !replaceinpage(frontpage_index_output, title_string, &title) || !replaceinpage(frontpage_index_output, info_string, &info) || @@ -369,9 +378,6 @@ frontpage(int flags) fprintf(stderr, "unable to generate frontpage\n"); return 0; } - //remove("title.tmp"); - //remove("date.tmp"); - //remove("info.tmp"); return 1; } diff --git a/pages.h b/pages.h index 3c34d98..5beb835 100644 --- a/pages.h +++ b/pages.h @@ -20,6 +20,7 @@ #include #include #include +#include struct fileorstring { @@ -33,7 +34,7 @@ long findstring(const char *file, const char *str); int deletebytes(const char *file, long offset, size_t bytes); int writeatbyte(const char *dest, struct fileorstring *source, long offset); int replaceinpage(const char *outfile, const char *toreplace, struct fileorstring *source); -char *gettime(); +char *gettime(char *buffer, size_t size); int createtmpfile(const char *name, const char *content, size_t size); /* generators (to be put into the pages array) */ -- cgit v1.2.3