X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ftime.c;fp=src%2Fcommon%2Ftime.c;h=387db3e3273224ff7f0837f02725ce36bfc92976;hp=a01c16df5c44f024c00469beeaa014542c658c9f;hb=a113ee0dd7fdba285a379289d47351f6e39c51db;hpb=0731b11e5e0022379ca462b574743197c48cfa25 diff --git a/src/common/time.c b/src/common/time.c index a01c16df5..387db3e32 100644 --- a/src/common/time.c +++ b/src/common/time.c @@ -16,6 +16,7 @@ */ #include +#include #include #include #include @@ -68,6 +69,37 @@ struct timespec timespec_abs_diff(struct timespec t1, struct timespec t2) return res; } +LTTNG_HIDDEN +int time_t_to_ISO8601(char *dest, size_t dest_size, time_t time) +{ + int ret; + struct tm tm, *timeinfo; + + if (dest_size < ISO8601_LEN) { + ERR("Failed to format time to ISO8601 destination too small"); + ret = -1; + goto end; + } + + timeinfo = localtime_r(&time, &tm); + if (!timeinfo) { + PERROR("localtime"); + ret = -1; + goto end; + } + + ret = strftime(dest, dest_size, ISO8601_FORMAT, timeinfo); + if (ret == 0) { + ERR("Failed to format time to ISO8601"); + ret = -1; + goto end; + } + + ret = 0; +end: + return ret; +} + static void __attribute__((constructor)) init_locale_utf8_support(void) {