From 8b6c71206d32b11683e5e7cebc9acb467ba01b38 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 10 Apr 2010 04:38:49 +0200 Subject: util: introduce format_timestamp() --- util.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 29f48b08e3..52ca5e2563 100644 --- a/util.c +++ b/util.c @@ -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", -- cgit v1.2.3-54-g00ecf