diff options
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 402b7caa3f..3ac67505f0 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -57,6 +57,8 @@ #include <sys/vfs.h> #include <linux/magic.h> #include <limits.h> +#include <langinfo.h> +#include <locale.h> #include "macro.h" #include "util.h" @@ -6115,3 +6117,26 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, } return NULL; } + +bool is_locale_utf8(void) { + const char *set; + static int cached_answer = -1; + + if (cached_answer >= 0) + goto out; + + if (!setlocale(LC_ALL, "")) { + cached_answer = true; + goto out; + } + + set = nl_langinfo(CODESET); + if (!set) { + cached_answer = true; + goto out; + } + + cached_answer = streq(set, "UTF-8"); +out: + return (bool)cached_answer; +} |