diff Python/sysmodule.c @ 65161:071f1f7af522

_wrealpath() and _Py_wreadlink() support surrogates (PEP 383) Use _Py_wchar2char() to support surrogate characters in the input path.
author Victor Stinner <victor.stinner@haypocalc.com>
date Thu, 07 Oct 2010 11:06:49 +0000
parents 62c58dc912e8
children 39014f0abc32
line wrap: on
line diff
--- a/Python/sysmodule.c	Thu Oct 07 01:12:19 2010 +0000
+++ b/Python/sysmodule.c	Thu Oct 07 11:06:49 2010 +0000
@@ -1661,16 +1661,17 @@
 static wchar_t*
 _wrealpath(const wchar_t *path, wchar_t *resolved_path)
 {
-    char cpath[PATH_MAX];
+    char *cpath;
     char cresolved_path[PATH_MAX];
     char *res;
     size_t r;
-    r = wcstombs(cpath, path, PATH_MAX);
-    if (r == (size_t)-1 || r >= PATH_MAX) {
+    cpath = _Py_wchar2char(path);
+    if (cpath == NULL) {
         errno = EINVAL;
         return NULL;
     }
     res = realpath(cpath, cresolved_path);
+    PyMem_Free(cpath);
     if (res == NULL)
         return NULL;
     r = mbstowcs(resolved_path, cresolved_path, PATH_MAX);