diff options
author | nicm <nicm> | 2016-03-05 16:08:38 +0000 |
---|---|---|
committer | nicm <nicm> | 2016-03-05 16:08:38 +0000 |
commit | 0d6de44a37755f0e5046c04e19e4506a6d59e750 (patch) | |
tree | 769b5f5c99bf66eba5c29c3e0eb9d9c846a6f417 /tmux.c | |
parent | c38e0a4bbc722865f934db1282ca6f086874f530 (diff) | |
download | rtmux-0d6de44a37755f0e5046c04e19e4506a6d59e750.tar.gz rtmux-0d6de44a37755f0e5046c04e19e4506a6d59e750.tar.bz2 rtmux-0d6de44a37755f0e5046c04e19e4506a6d59e750.zip |
If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.
Diffstat (limited to 'tmux.c')
-rw-r--r-- | tmux.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -24,6 +24,7 @@ #include <event.h> #include <fcntl.h> #include <getopt.h> +#include <langinfo.h> #include <locale.h> #include <paths.h> #include <pwd.h> @@ -188,10 +189,14 @@ main(int argc, char **argv) const char *s; int opt, flags, keys; - if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) - setlocale(LC_CTYPE, ""); - if (wcwidth(0xfffd) != 1) - errx(1, "no UTF-8 locale; please set LC_CTYPE"); + if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) { + if (setlocale(LC_CTYPE, "") == NULL) + errx(1, "invalid LC_ALL, LC_CTYPE or LANG"); + s = nl_langinfo(CODESET); + if (strcasecmp(s, "UTF-8") != 0 && + strcasecmp(s, "UTF8") != 0) + errx(1, "need UTF-8 locale (LC_CTYPE) but have %s", s); + } setlocale(LC_TIME, ""); tzset(); |