Message398510
> We could also provide a better check in WindowsConsoleIO.isatty,
For isatty(), my concern is a false positive if the file is the "NUL" device, which should be an io.FileIO object. I suppose checking the file type in io._WindowsConsoleIO.isatty() could be useful in case the file descriptor gets reassigned to a non-console file (e.g. via os.close or os.dup2).
I'd prefer to implement the check in a common _Py_isatty() function that supports the optional errno values EBADF and ENOTTY [1]. For example:
int
_Py_isatty(int fd)
{
DWORD mode;
HANDLE handle = _Py_get_osfhandle_noraise(fd);
if (handle == INVALID_HANDLE_VALUE) {
errno = EBADF;
return 0;
}
switch (GetFileType(handle)) {
case FILE_TYPE_CHAR:
break;
case FILE_TYPE_DISK:
case FILE_TYPE_PIPE:
errno = ENOTTY;
return 0;
default:
errno = EBADF;
return 0;
}
if (!GetConsoleMode(handle, &mode) &&
GetLastError() != ERROR_ACCESS_DENIED) {
errno = ENOTTY;
return 0;
}
return 1;
}
---
[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/isatty.html |
|
Date |
User |
Action |
Args |
2021-07-29 19:15:41 | eryksun | set | recipients:
+ eryksun, paul.moore, tim.golden, matejcik, zach.ware, steve.dower |
2021-07-29 19:15:41 | eryksun | set | messageid: <1627586141.37.0.683340419086.issue44762@roundup.psfhosted.org> |
2021-07-29 19:15:41 | eryksun | link | issue44762 messages |
2021-07-29 19:15:41 | eryksun | create | |
|