X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=cfb6555a1d65fc061eb20c2c69326a91175f97ec;hp=d0f050c0ff14d12e79f4f36d2e7adddb807e341d;hb=26fe59386444e0c932b5adcd5f9d6f9f114dd1e2;hpb=00a52467faf94a4f07cfcc2fe3c9590d9cff3872 diff --git a/src/common/utils.c b/src/common/utils.c index d0f050c0f..cfb6555a1 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -597,3 +597,30 @@ char *utils_get_home_dir(void) } return getenv(DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR); } + +/* + * With the given format, fill dst with the time of len maximum siz. + * + * Return amount of bytes set in the buffer or else 0 on error. + */ +LTTNG_HIDDEN +size_t utils_get_current_time_str(const char *format, char *dst, size_t len) +{ + size_t ret; + time_t rawtime; + struct tm *timeinfo; + + assert(format); + assert(dst); + + /* Get date and time for session path */ + time(&rawtime); + timeinfo = localtime(&rawtime); + ret = strftime(dst, len, format, timeinfo); + if (ret == 0) { + ERR("Unable to strftime with format %s at dst %p of len %lu", format, + dst, len); + } + + return ret; +}