mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
_wrealpath() and _Py_wreadlink() support surrogates (PEP 383)
Use _Py_wchar2char() to support surrogate characters in the input path.
This commit is contained in:
parent
afa88b5dac
commit
7ae7c87b05
2 changed files with 10 additions and 6 deletions
|
@ -179,15 +179,18 @@ _wgetcwd(wchar_t *buf, size_t size)
|
||||||
int
|
int
|
||||||
_Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
|
_Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
|
||||||
{
|
{
|
||||||
|
char *cpath;
|
||||||
char cbuf[PATH_MAX];
|
char cbuf[PATH_MAX];
|
||||||
char cpath[PATH_MAX];
|
|
||||||
int res;
|
int res;
|
||||||
size_t r1 = wcstombs(cpath, path, PATH_MAX);
|
size_t r1;
|
||||||
if (r1 == (size_t)-1 || r1 >= PATH_MAX) {
|
|
||||||
|
cpath = _Py_wchar2char(path);
|
||||||
|
if (cpath == NULL) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
res = (int)readlink(cpath, cbuf, PATH_MAX);
|
res = (int)readlink(cpath, cbuf, PATH_MAX);
|
||||||
|
PyMem_Free(cpath);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return -1;
|
return -1;
|
||||||
if (res == PATH_MAX) {
|
if (res == PATH_MAX) {
|
||||||
|
|
|
@ -1661,16 +1661,17 @@ makeargvobject(int argc, wchar_t **argv)
|
||||||
static wchar_t*
|
static wchar_t*
|
||||||
_wrealpath(const wchar_t *path, wchar_t *resolved_path)
|
_wrealpath(const wchar_t *path, wchar_t *resolved_path)
|
||||||
{
|
{
|
||||||
char cpath[PATH_MAX];
|
char *cpath;
|
||||||
char cresolved_path[PATH_MAX];
|
char cresolved_path[PATH_MAX];
|
||||||
char *res;
|
char *res;
|
||||||
size_t r;
|
size_t r;
|
||||||
r = wcstombs(cpath, path, PATH_MAX);
|
cpath = _Py_wchar2char(path);
|
||||||
if (r == (size_t)-1 || r >= PATH_MAX) {
|
if (cpath == NULL) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
res = realpath(cpath, cresolved_path);
|
res = realpath(cpath, cresolved_path);
|
||||||
|
PyMem_Free(cpath);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
r = mbstowcs(resolved_path, cresolved_path, PATH_MAX);
|
r = mbstowcs(resolved_path, cresolved_path, PATH_MAX);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue