mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
closes bpo-36161: Use thread-safe ttyname_r instead of ttyname. (GH-14868)
Signed-off-by: Antonio Gutierrez <chibby0ne@gmail.com>
This commit is contained in:
parent
e8bedbddad
commit
594e2edfb5
2 changed files with 16 additions and 4 deletions
|
@ -0,0 +1 @@
|
||||||
|
In :mod:`posix`, use ``ttyname_r`` instead of ``ttyname`` for thread safety.
|
|
@ -2774,13 +2774,24 @@ static PyObject *
|
||||||
os_ttyname_impl(PyObject *module, int fd)
|
os_ttyname_impl(PyObject *module, int fd)
|
||||||
/*[clinic end generated code: output=c424d2e9d1cd636a input=9ff5a58b08115c55]*/
|
/*[clinic end generated code: output=c424d2e9d1cd636a input=9ff5a58b08115c55]*/
|
||||||
{
|
{
|
||||||
char *ret;
|
|
||||||
|
|
||||||
ret = ttyname(fd);
|
long size = sysconf(_SC_TTY_NAME_MAX);
|
||||||
if (ret == NULL) {
|
if (size == -1) {
|
||||||
return posix_error();
|
return posix_error();
|
||||||
}
|
}
|
||||||
return PyUnicode_DecodeFSDefault(ret);
|
char *buffer = (char *)PyMem_RawMalloc(size);
|
||||||
|
if (buffer == NULL) {
|
||||||
|
return PyErr_NoMemory();
|
||||||
|
}
|
||||||
|
int ret = ttyname_r(fd, buffer, size);
|
||||||
|
if (ret != 0) {
|
||||||
|
PyMem_RawFree(buffer);
|
||||||
|
errno = ret;
|
||||||
|
return posix_error();
|
||||||
|
}
|
||||||
|
PyObject *res = PyUnicode_DecodeFSDefault(buffer);
|
||||||
|
PyMem_RawFree(buffer);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue