From c2f1df1d4af0c7e633528cb4c8caa79ef04b0b5a Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Thu, 10 Mar 2016 18:17:39 -0800 Subject: fix handling of non-ASCII chars in C locale The relevant standards allow the mbtowc/mbrtowc functions to reject non-ASCII characters (i.e., chars with the high bit set) when the locale is C or POSIX. The BSD libraries (e.g., on OS X) don't do this but the GNU libraries (e.g., on Linux) do. Like most programs we need the C/POSIX locales to allow arbitrary bytes. So explicitly check if we're in a single-byte locale (which would also include ISO-8859 variants) and simply pass-thru the chars without encoding or decoding. Fixes #2802. --- src/env.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/env.cpp') diff --git a/src/env.cpp b/src/env.cpp index c24280bc..56c9deb0 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -377,14 +377,13 @@ static void setup_path() int env_set_pwd() { - wchar_t dir_path[4096]; - wchar_t *res = wgetcwd(dir_path, 4096); - if (!res) + wcstring res = wgetcwd(); + if (res.empty()) { debug(0, _(L"Could not determine current working directory. Is your locale set correctly?")); return 0; } - env_set(L"PWD", dir_path, ENV_EXPORT | ENV_GLOBAL); + env_set(L"PWD", res.c_str(), ENV_EXPORT | ENV_GLOBAL); return 1; } -- cgit v1.2.3