Print UTF-8 SI suffix only when allowed by the locale
[lttng-tools.git] / src / common / time.c
index 5c5594584dc6ae37c59ab44625ca7ad9b8c9534d..5519e3ab4715240cfd1b27ef7701d36c1b737039 100644 (file)
 #include <limits.h>
 #include <errno.h>
 #include <pthread.h>
+#include <locale.h>
+#include <string.h>
+
+static bool utf8_output_supported;
+
+LTTNG_HIDDEN
+bool locale_supports_utf8(void)
+{
+       return utf8_output_supported;
+}
 
 LTTNG_HIDDEN
 int timespec_to_ms(struct timespec ts, unsigned long *ms)
@@ -57,3 +67,16 @@ struct timespec timespec_abs_diff(struct timespec t1, struct timespec t2)
        res.tv_nsec = diff % (uint64_t) NSEC_PER_SEC;
        return res;
 }
+
+static
+void __attribute__((constructor)) init_locale_utf8_support(void)
+{
+       const char *program_locale = setlocale(LC_ALL, NULL);
+       const char *lang = getenv("LANG");
+
+       if (program_locale && strstr(program_locale, "utf8")) {
+               utf8_output_supported = true;
+       } else if (strstr(lang, "utf8")) {
+               utf8_output_supported = true;
+       }
+}
This page took 0.024293 seconds and 5 git commands to generate.