diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-04-10 04:38:49 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-04-10 18:00:14 +0200 |
commit | 8b6c71206d32b11683e5e7cebc9acb467ba01b38 (patch) | |
tree | 62c81c0d8fa9fdc1f8027ba4cce0fd123395f684 /util.c | |
parent | bbd671356647d9d2c7d6c2c0401e907e169c7576 (diff) |
util: introduce format_timestamp()
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -1258,6 +1258,24 @@ bool chars_intersect(const char *a, const char *b) { return false; } +char *format_timestamp(char *buf, size_t l, usec_t t) { + struct tm tm; + time_t sec; + + assert(buf); + assert(l > 0); + + if (t <= 0) + return NULL; + + sec = (time_t) t / USEC_PER_SEC; + + if (strftime(buf, l, "%a, %d %b %Y %H:%M:%S %z", localtime_r(&sec, &tm)) <= 0) + return NULL; + + return buf; +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime", |