diff options
author | Jan Dubois <jand@activestate.com> | 2009-12-16 15:42:19 -0800 |
---|---|---|
committer | Jan Dubois <jand@activestate.com> | 2009-12-16 15:46:34 -0800 |
commit | 827da6a38269ebe059fe8acab0772f00c88704bf (patch) | |
tree | 1154337fa550b5fff0eeeb4acddadd19da36d8c5 /win32/perlhost.h | |
parent | ab106183f6f6440236f5be52e2a171a63882946a (diff) | |
download | perl-827da6a38269ebe059fe8acab0772f00c88704bf.tar.gz |
-t should only return TRUE for file handles connected to a TTY
The Microsoft C version of isatty() returns TRUE for all
character mode devices, including the /dev/null style "nul"
device and printers like "lpt1".
The included test has only been tested on Windows and Linux;
the device names for OS/2 and VMS are just best guesses...
Diffstat (limited to 'win32/perlhost.h')
-rw-r--r-- | win32/perlhost.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/win32/perlhost.h b/win32/perlhost.h index 7464c7a99f..36a716a846 100644 --- a/win32/perlhost.h +++ b/win32/perlhost.h @@ -1004,7 +1004,22 @@ PerlLIOIOCtl(struct IPerlLIO* piPerl, int i, unsigned int u, char *data) int PerlLIOIsatty(struct IPerlLIO* piPerl, int fd) { - return isatty(fd); + /* The Microsoft isatty() function returns true for *all* + * character mode devices, including "nul". Our implementation + * should only return true if the handle has a console buffer. + */ + DWORD mode; + HANDLE fh = (HANDLE)_get_osfhandle(fd); + if (fh == (HANDLE)-1) { + /* errno is already set to EBADF */ + return 0; + } + + if (GetConsoleMode(fh, &mode)) + return 1; + + errno = ENOTTY; + return 0; } int |