summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-14 12:37:19 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-14 12:37:19 (GMT)
commitf4061dac607d9bc2b3af0b72da5e8917428d869e (patch)
tree601762fc2c6049419644c74fef5ba544c9ecf381 /Python
parent22a351aabfaf8a9136ad148ceecddb55a9874f1f (diff)
downloadcpython-f4061dac607d9bc2b3af0b72da5e8917428d869e.zip
cpython-f4061dac607d9bc2b3af0b72da5e8917428d869e.tar.gz
cpython-f4061dac607d9bc2b3af0b72da5e8917428d869e.tar.bz2
_Py_wgetcwd() decodes the path using _Py_char2wchar() to support surrogates
Diffstat (limited to 'Python')
-rw-r--r--Python/fileutils.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 9423cb0..564e2c0 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -364,7 +364,8 @@ _Py_wrealpath(const wchar_t *path,
}
#endif
-/* Get the current directory. Decode the path from the locale encoding. */
+/* Get the current directory. size is the buffer size in wide characters
+ including the null character. Decode the path from the locale encoding. */
wchar_t*
_Py_wgetcwd(wchar_t *buf, size_t size)
@@ -373,12 +374,19 @@ _Py_wgetcwd(wchar_t *buf, size_t size)
return _wgetcwd(buf, size);
#else
char fname[PATH_MAX];
+ wchar_t *wname;
+
if (getcwd(fname, PATH_MAX) == NULL)
return NULL;
- if (mbstowcs(buf, fname, size) >= size) {
- errno = ERANGE;
+ wname = _Py_char2wchar(fname);
+ if (wname == NULL)
+ return NULL;
+ if (size <= wcslen(wname)) {
+ PyMem_Free(wname);
return NULL;
}
+ wcsncpy(buf, wname, size);
+ PyMem_Free(wname);
return buf;
#endif
}