Add utils function to format current time as a string
authorDavid Goulet <dgoulet@efficios.com>
Fri, 28 Jun 2013 14:39:30 +0000 (10:39 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 28 Jun 2013 14:39:30 +0000 (10:39 -0400)
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/common/utils.c
src/common/utils.h

index d0f050c0ff14d12e79f4f36d2e7adddb807e341d..cfb6555a1d65fc061eb20c2c69326a91175f97ec 100644 (file)
@@ -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;
+}
index 70dc4b7aa41670279c9da2fd04282ed05fcc779c..06aef4f1a33417b80e18672240ee500c648e5ce6 100644 (file)
@@ -41,5 +41,6 @@ int utils_rotate_stream_file(char *path_name, char *file_name, uint64_t size,
 int utils_parse_size_suffix(char *str, uint64_t *size);
 int utils_get_count_order_u32(uint32_t x);
 char *utils_get_home_dir(void);
+size_t utils_get_current_time_str(const char *format, char *dst, size_t len);
 
 #endif /* _COMMON_UTILS_H */
This page took 0.027539 seconds and 5 git commands to generate.