]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
_Py_wreadlink() uses _Py_char2wchar() to decode the result, to support
authorVictor Stinner <victor.stinner@haypocalc.com>
Sat, 16 Oct 2010 22:47:37 +0000 (22:47 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sat, 16 Oct 2010 22:47:37 +0000 (22:47 +0000)
surrogate characters.

Python/fileutils.c

index 076f510debd07a77cf081939b8fe55408f4383b0..cfafd865c54d222906b9092b0f4db84322954fd6 100644 (file)
@@ -307,6 +307,7 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
 {
     char *cpath;
     char cbuf[PATH_MAX];
+    wchar_t *wbuf;
     int res;
     size_t r1;
 
@@ -324,11 +325,15 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
         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