diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index 664513c9ad..433e31ac90 100644 --- a/src/common.c +++ b/src/common.c @@ -1199,3 +1199,22 @@ void log_set(FILE *file) { logfile = file; } + +/* This is very similar to ctime() but it does not force a newline. + */ +char *simple_ctime(const time_t *t, char out[SIMPLE_CTIME_BUF_SIZE]) +{ + struct tm tm; + + if (localtime_r(t, &tm) == NULL) + goto error; + + if (!strftime(out, SIMPLE_CTIME_BUF_SIZE, "%c", &tm)) + goto error; + + return out; + + error: + snprintf(out, SIMPLE_CTIME_BUF_SIZE, "[error]"); + return out; +} |