diff options
-rw-r--r-- | pages.c | 18 | ||||
-rw-r--r-- | pages.h | 3 |
2 files changed, 14 insertions, 7 deletions
@@ -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; } @@ -20,6 +20,7 @@ #include <string.h> #include <unistd.h> #include <sys/stat.h> +#include <time.h> 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) */ |