diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2020-10-24 18:26:40 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2020-10-24 18:26:40 +0200 |
commit | 4ba484be6ef6e1f759fdb6dbde056592143cbd14 (patch) | |
tree | 0dc9ec3162d6278fe28a726495d1986742c5a795 /utils.c | |
parent | 749a4b2eda0b3b2d7a796530bb64fdfb4b5f3df4 (diff) |
time/timestamp refactoring
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -3,6 +3,7 @@ #include <string.h> #include <sys/types.h> #include <sys/socket.h> +#include <time.h> #include <unistd.h> #include "utils.h" @@ -82,3 +83,26 @@ int hostname_to_address(char const * const host, char const * const port, struct return 0; } + +void strftime_local(double time_in_secs, char * const out, size_t out_size) +{ + time_t t = (time_t)time_in_secs; + struct tm r; + + if (localtime_r(&t, &r) == NULL) + { + out[0] = '\0'; + return; + } + + if (out_size > TIMESTAMP_STRLEN) + { + out_size = TIMESTAMP_STRLEN; + } + + if (strftime(out, out_size, "%a, %d %b %Y %T %z", &r) <= 0) + { + out[0] = '\0'; + return; + } +} |