From: Jan Dubois Date: Thu, 17 Dec 2009 19:15:38 +0000 (-0800) Subject: Implement win32_isatty() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4342f4d6df6a7dfa22a470aa21e54a5622c009f3;p=p5sagit%2Fp5-mst-13.2.git 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. --- diff --git a/makedef.pl b/makedef.pl index 9e261e5..6409431 100644 --- a/makedef.pl +++ b/makedef.pl @@ -1284,6 +1284,7 @@ if ($PLATFORM =~ /^win(?:32|ce)$/) { win32_open win32_close win32_eof + win32_isatty win32_read win32_write win32_spawnvp diff --git a/win32/perlhost.h b/win32/perlhost.h index 36a716a..be7d61d 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 b9eea70..b33f732 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 7507408..9c59037 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