Mercurial > cpython-lru_cache-weakref
diff Python/fileutils.c @ 65409:e1dc9861b43f
_Py_wreadlink() uses _Py_char2wchar() to decode the result, to support
surrogate characters.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sat, 16 Oct 2010 22:47:37 +0000 |
| parents | cc1d8a2db348 |
| children | 6dcba93d6262 |
line wrap: on
line diff
--- a/Python/fileutils.c Sat Oct 16 21:54:59 2010 +0000 +++ b/Python/fileutils.c Sat Oct 16 22:47:37 2010 +0000 @@ -307,6 +307,7 @@ { char *cpath; char cbuf[PATH_MAX]; + wchar_t *wbuf; int res; size_t r1; @@ -324,11 +325,15 @@ return -1; } cbuf[res] = '\0'; /* buf will be null terminated */ - r1 = mbstowcs(buf, cbuf, bufsiz); - if (r1 == -1) { + wbuf = _Py_char2wchar(cbuf); + r1 = wcslen(wbuf); + if (bufsiz <= r1) { + PyMem_Free(wbuf); errno = EINVAL; return -1; } + wcsncpy(buf, wbuf, bufsiz); + PyMem_Free(wbuf); return (int)r1; } #endif
