diff options
author | Jan Dubois <jand@activestate.com> | 2009-12-17 11:15:38 -0800 |
---|---|---|
committer | Jan Dubois <jand@activestate.com> | 2009-12-17 11:15:38 -0800 |
commit | 4342f4d6df6a7dfa22a470aa21e54a5622c009f3 (patch) | |
tree | 8e5d5672edc1178924ae3ed6b863b9eb888a4762 /win32 | |
parent | 827da6a38269ebe059fe8acab0772f00c88704bf (diff) | |
download | perl-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')
-rw-r--r-- | win32/perlhost.h | 17 | ||||
-rw-r--r-- | win32/win32.c | 21 | ||||
-rw-r--r-- | win32/win32iop.h | 2 |
3 files changed, 24 insertions, 16 deletions
diff --git a/win32/perlhost.h b/win32/perlhost.h index 36a716a846..be7d61de02 100644 --- a/win32/perlhost.h +++ b/win32/perlhost.h @@ -1004,22 +1004,7 @@ PerlLIOIOCtl(struct IPerlLIO* piPerl, int i, unsigned int u, char *data) int PerlLIOIsatty(struct IPerlLIO* piPerl, 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; + return win32_isatty(fd); } int 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); diff --git a/win32/win32iop.h b/win32/win32iop.h index 7507408f00..9c59037c53 100644 --- a/win32/win32iop.h +++ b/win32/win32iop.h @@ -86,6 +86,7 @@ DllExport int win32_dup2(int h1, int h2); DllExport int win32_open(const char *path, int oflag,...); DllExport int win32_close(int fd); DllExport int win32_eof(int fd); +DllExport int win32_isatty(int fd); DllExport int win32_read(int fd, void *buf, unsigned int cnt); DllExport int win32_write(int fd, const void *buf, unsigned int cnt); DllExport int win32_spawnvp(int mode, const char *cmdname, @@ -252,6 +253,7 @@ END_EXTERN_C #define open win32_open #define close(fd) win32_close(fd) #define eof(fd) win32_eof(fd) +#define isatty(fd) win32_isatty(fd) #define read(fd,b,s) win32_read(fd,b,s) #define write(fd,b,s) win32_write(fd,b,s) #define _open_osfhandle win32_open_osfhandle |