X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=cfb6555a1d65fc061eb20c2c69326a91175f97ec;hb=41ad701255719d65645effd849c06b506b6b38d4;hp=ecac5381f061fb65c89bda64de0ad86e5be37f6f;hpb=07b86b528dc279d59cdf16e6cb946c144fe773f2;p=lttng-tools.git diff --git a/src/common/utils.c b/src/common/utils.c index ecac5381f..cfb6555a1 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -441,6 +441,7 @@ static void regex_print_error(int errcode, regex_t *regex) * * @return 0 on success, -1 on failure. */ +LTTNG_HIDDEN int utils_parse_size_suffix(char *str, uint64_t *size) { regex_t regex; @@ -586,6 +587,7 @@ int utils_get_count_order_u32(uint32_t x) * Obtain the value of LTTNG_HOME environment variable, if exists. * Otherwise returns the value of HOME. */ +LTTNG_HIDDEN char *utils_get_home_dir(void) { char *val = NULL; @@ -595,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; +}