Commit 3f711f4a authored by Victor Stinner's avatar Victor Stinner

_Py_wreadlink() uses _Py_char2wchar() to decode the result, to support

surrogate characters.
parent 9d396399
...@@ -307,6 +307,7 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) ...@@ -307,6 +307,7 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
{ {
char *cpath; char *cpath;
char cbuf[PATH_MAX]; char cbuf[PATH_MAX];
wchar_t *wbuf;
int res; int res;
size_t r1; size_t r1;
...@@ -324,11 +325,15 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) ...@@ -324,11 +325,15 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
return -1; return -1;
} }
cbuf[res] = '\0'; /* buf will be null terminated */ cbuf[res] = '\0'; /* buf will be null terminated */
r1 = mbstowcs(buf, cbuf, bufsiz); wbuf = _Py_char2wchar(cbuf);
if (r1 == -1) { r1 = wcslen(wbuf);
if (bufsiz <= r1) {
PyMem_Free(wbuf);
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
wcsncpy(buf, wbuf, bufsiz);
PyMem_Free(wbuf);
return (int)r1; return (int)r1;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment