aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-12-14 17:32:04 -0800
committerRob Landley <rob@landley.net>2020-12-14 22:29:45 -0600
commitbec202875d27950ed64ce54e6b9a10a9a2e5720e (patch)
treed9ee6fc74965ad0bba94d9ece152ac6d56ca4581 /main.c
parent640b1bea8b2ffafab024b5966f618a9de56a44f2 (diff)
downloadtoybox-bec202875d27950ed64ce54e6b9a10a9a2e5720e.tar.gz
main.c: fix UTF-8 on macOS.
Unfortunately neither "C.UTF-8" nor "UTF-8" works on *both* OSes...
Diffstat (limited to 'main.c')
-rw-r--r--main.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/main.c b/main.c
index a1817347..93822686 100644
--- a/main.c
+++ b/main.c
@@ -99,9 +99,11 @@ void toy_singleinit(struct toy_list *which, char *argv[])
toys.old_umask = umask(0);
if (!(which->flags & TOYFLAG_UMASK)) umask(toys.old_umask);
- // Try user's locale, falling back to C.UTF-8
+ // Try user's locale, falling back to C.UTF-8 for Linux or UTF-8 for Mac.
+ // (Neither locale name works on both OSes.)
setlocale(LC_CTYPE, "");
- if (strcmp("UTF-8", nl_langinfo(CODESET))) setlocale(LC_CTYPE, "C.UTF-8");
+ if (strcmp("UTF-8", nl_langinfo(CODESET)))
+ if (!setlocale(LC_CTYPE, "C.UTF-8")) setlocale(LC_CTYPE, "UTF-8");
setvbuf(stdout, 0, (which->flags & TOYFLAG_LINEBUF) ? _IOLBF : _IONBF, 0);
}
}