comparison 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
comparison
equal deleted inserted replaced
65158:a62c4d5cdf6c 65161:071f1f7af522
1659 1659
1660 #ifdef HAVE_REALPATH 1660 #ifdef HAVE_REALPATH
1661 static wchar_t* 1661 static wchar_t*
1662 _wrealpath(const wchar_t *path, wchar_t *resolved_path) 1662 _wrealpath(const wchar_t *path, wchar_t *resolved_path)
1663 { 1663 {
1664 char cpath[PATH_MAX]; 1664 char *cpath;
1665 char cresolved_path[PATH_MAX]; 1665 char cresolved_path[PATH_MAX];
1666 char *res; 1666 char *res;
1667 size_t r; 1667 size_t r;
1668 r = wcstombs(cpath, path, PATH_MAX); 1668 cpath = _Py_wchar2char(path);
1669 if (r == (size_t)-1 || r >= PATH_MAX) { 1669 if (cpath == NULL) {
1670 errno = EINVAL; 1670 errno = EINVAL;
1671 return NULL; 1671 return NULL;
1672 } 1672 }
1673 res = realpath(cpath, cresolved_path); 1673 res = realpath(cpath, cresolved_path);
1674 PyMem_Free(cpath);
1674 if (res == NULL) 1675 if (res == NULL)
1675 return NULL; 1676 return NULL;
1676 r = mbstowcs(resolved_path, cresolved_path, PATH_MAX); 1677 r = mbstowcs(resolved_path, cresolved_path, PATH_MAX);
1677 if (r == (size_t)-1 || r >= PATH_MAX) { 1678 if (r == (size_t)-1 || r >= PATH_MAX) {
1678 errno = EINVAL; 1679 errno = EINVAL;