aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/wutil.cpp
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-03-10 18:17:39 -0800
committerGravatar Kurtis Rader <krader@skepticism.us>2016-03-20 18:47:38 -0700
commitc2f1df1d4af0c7e633528cb4c8caa79ef04b0b5a (patch)
tree0776e975779488cb842c09a5d79d193cb7cf9fdc /src/wutil.cpp
parentfb0921249f4584e68699e336be249a655b9c8ede (diff)
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.
Diffstat (limited to 'src/wutil.cpp')
-rw-r--r--src/wutil.cpp27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/wutil.cpp b/src/wutil.cpp
index a3a51dac..2ff358bc 100644
--- a/src/wutil.cpp
+++ b/src/wutil.cpp
@@ -145,30 +145,23 @@ bool wreaddir_for_dirs(DIR *dir, wcstring *out_name)
}
-wchar_t *wgetcwd(wchar_t *buff, size_t sz)
+const wcstring wgetcwd()
{
- char *buffc = (char *)malloc(sz*MAX_UTF8_BYTES);
- char *res;
- wchar_t *ret = 0;
+ wcstring retval;
- if (!buffc)
+ char *res = getcwd(NULL, 0);
+ if (res)
{
- errno = ENOMEM;
- return 0;
+ retval = str2wcstring(res);
+ free(res);
}
-
- res = getcwd(buffc, sz*MAX_UTF8_BYTES);
- if (res)
+ else
{
- if ((size_t)-1 != mbstowcs(buff, buffc, sizeof(wchar_t) * sz))
- {
- ret = buff;
- }
+ debug(0, _(L"getcwd() failed with errno %d/%s"), errno, strerror(errno));
+ retval = wcstring();
}
- free(buffc);
-
- return ret;
+ return retval;
}
int wchdir(const wcstring &dir)