Mercurial > cpython-lru_cache-weakref
diff Python/fileutils.c @ 65312:a27fc0ff3678
_Py_wgetcwd() decodes the path using _Py_char2wchar() to support surrogates
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Thu, 14 Oct 2010 12:37:19 +0000 |
| parents | 1c4774b4e98a |
| children | cc1d8a2db348 |
line wrap: on
line diff
--- a/Python/fileutils.c Thu Oct 14 12:04:34 2010 +0000 +++ b/Python/fileutils.c Thu Oct 14 12:37:19 2010 +0000 @@ -364,7 +364,8 @@ } #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 @@ 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 }
