summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
authorJan Dubois <jand@activestate.com>2009-12-17 11:15:38 -0800
committerJan Dubois <jand@activestate.com>2009-12-17 11:15:38 -0800
commit4342f4d6df6a7dfa22a470aa21e54a5622c009f3 (patch)
tree8e5d5672edc1178924ae3ed6b863b9eb888a4762 /win32/win32.c
parent827da6a38269ebe059fe8acab0772f00c88704bf (diff)
downloadperl-4342f4d6df6a7dfa22a470aa21e54a5622c009f3.tar.gz
Implement win32_isatty()
Commit 827da6a38 added a custom isatty() implementation in win32/perlhost.h, but that code will only be used when perl is compiled with -DPERL_IMPLICIT_SYS. This change makes sure that the custom implementation will be used on Windows for all choices of build options.
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index b9eea70535..b33f732a82 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3509,6 +3509,27 @@ win32_eof(int fd)
}
DllExport int
+win32_isatty(int 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;
+}
+
+DllExport int
win32_dup(int fd)
{
return dup(fd);