diff options
author | Elliott Hughes <enh@google.com> | 2020-12-14 17:32:04 -0800 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-12-14 22:29:45 -0600 |
commit | bec202875d27950ed64ce54e6b9a10a9a2e5720e (patch) | |
tree | d9ee6fc74965ad0bba94d9ece152ac6d56ca4581 | |
parent | 640b1bea8b2ffafab024b5966f618a9de56a44f2 (diff) | |
download | toybox-bec202875d27950ed64ce54e6b9a10a9a2e5720e.tar.gz |
main.c: fix UTF-8 on macOS.
Unfortunately neither "C.UTF-8" nor "UTF-8" works on *both* OSes...
-rw-r--r-- | main.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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); } } |