summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2020-12-25 15:47:08 +0100
committerjaseg <git@jaseg.net>2020-12-25 15:47:08 +0100
commitb6480279fb2ca0003f05f9f884f7bbd8a7d3768d (patch)
treeca9bd437595f8d7c103e7e6773a2d361966a218b
parente6103e70bea8e228a6318c1c67f89e406be7c409 (diff)
downloadlolcat-b6480279fb2ca0003f05f9f884f7bbd8a7d3768d.tar.gz
lolcat-b6480279fb2ca0003f05f9f884f7bbd8a7d3768d.tar.bz2
lolcat-b6480279fb2ca0003f05f9f884f7bbd8a7d3768d.zip
Add fallback for locale-setting on systems without C.UTF-8 locale
-rwxr-xr-xlolcat.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lolcat.c b/lolcat.c
index 449abcc..518212e 100755
--- a/lolcat.c
+++ b/lolcat.c
@@ -156,10 +156,13 @@ int main(int argc, char** argv)
}
char* env_lang = getenv("LANG");
- if (force_locale && env_lang && !strstr(env_lang, "UTF-8"))
- setlocale(LC_ALL, "C.UTF-8");
- else
+ if (force_locale && env_lang && !strstr(env_lang, "UTF-8")) {
+ if (!setlocale(LC_ALL, "C.UTF-8")) { /* C.UTF-8 may not be available on all platforms */
+ setlocale(LC_ALL, ""); /* Let's hope for the best */
+ }
+ } else {
setlocale(LC_ALL, "");
+ }
i = 0;
for (char** filename = inputs; filename < inputs_end; filename++) {
@@ -215,7 +218,7 @@ int main(int argc, char** argv)
putwchar(c);
- if (escape_state == 2)
+ if (escape_state == 2) /* implies "colors" */
wprintf(L"\033[38;5;%hhum", codes[(rand_offset + cc) % ARRAY_SIZE(codes)]);
}