X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=util.c;h=52ca5e25631a9e56f8fd5e27df7c63d777b6d50a;hp=29f48b08e3b918991350caa2794682a239b7ca5e;hb=013b87c09199926434583e8bb54ac6cb4b835eb5;hpb=bbd671356647d9d2c7d6c2c0401e907e169c7576 diff --git a/util.c b/util.c index 29f48b08e..52ca5e256 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",