Commit 03a8a56f authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-38353: Add subfunctions to getpath.c (GH-16572)

Following symbolic links is now limited to 40 attempts, just to
prevent loops.

Add subfunctions:

* Add resolve_symlinks()
* Add calculate_argv0_path_framework()
* Add calculate_which()
* Add calculate_program_macos()

Fix also _Py_wreadlink(): readlink() result type is Py_ssize_t, not
int.
parent e982d8b6
This diff is collapsed.
......@@ -1668,8 +1668,9 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t buflen)
{
char *cpath;
char cbuf[MAXPATHLEN];
size_t cbuf_len = Py_ARRAY_LENGTH(cbuf);
wchar_t *wbuf;
int res;
Py_ssize_t res;
size_t r1;
cpath = _Py_EncodeLocaleRaw(path, NULL);
......@@ -1677,11 +1678,12 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t buflen)
errno = EINVAL;
return -1;
}
res = (int)readlink(cpath, cbuf, Py_ARRAY_LENGTH(cbuf));
res = readlink(cpath, cbuf, cbuf_len);
PyMem_RawFree(cpath);
if (res == -1)
if (res == -1) {
return -1;
if (res == Py_ARRAY_LENGTH(cbuf)) {
}
if ((size_t)res == cbuf_len) {
errno = EINVAL;
return -1;
}
......
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