Support MAKE_TERMOUT and MAKE_TERMERR on MS-Windows.
authorEli Zaretskii <eliz@gnu.org>
Mon, 15 Sep 2014 16:51:41 +0000 (19:51 +0300)
committerEli Zaretskii <eliz@gnu.org>
Mon, 15 Sep 2014 16:51:41 +0000 (19:51 +0300)
* w32/compat/posixfcn.c (isatty, ttyname): New functions.
* config.h.W32.template (HAVE_TTYNAME): Define.  Add a prototype
for ttyname.

config.h.W32.template
w32/compat/posixfcn.c

index 849a8550b4088acb800e97bbd09e26ffb1b7f794..07bb626c6d0f02c3033be3ec80dc49410cc44ace 100644 (file)
@@ -296,7 +296,8 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #define HAVE_ISATTY 1
 
 /* Define to 1 if you have the `ttyname' function. */
-/* #undef HAVE_TTYNAME */
+#define HAVE_TTYNAME 1
+char *ttyname (int);
 
 /* Define to 1 if 'n_un.n_name' is a member of 'struct nlist'. */
 /* #undef HAVE_STRUCT_NLIST_N_UN_N_NAME */
index 1d852f5fc6a95a7be23eea220df5e09e358fa0f7..946f16b2509d292c4027439dada3a0a68f11373f 100644 (file)
@@ -454,3 +454,33 @@ dlclose (void *handle)
 
 #endif  /* MAKE_LOAD */
 
+
+/* MS runtime's isatty returns non-zero for any character device,
+   including the null device, which is not what we want.  */
+int
+isatty (int fd)
+{
+  HANDLE fh = (HANDLE) _get_osfhandle (fd);
+  DWORD con_mode;
+
+  if (fh == INVALID_HANDLE_VALUE)
+    {
+      errno = EBADF;
+      return 0;
+    }
+  if (GetConsoleMode (fh, &con_mode))
+    return 1;
+
+  errno = ENOTTY;
+  return 0;
+}
+
+char *
+ttyname (int fd)
+{
+  /* This "knows" that Make only asks about stdout and stderr.  A more
+     sophisticated implementation should test whether FD is open for
+     input or output.  We can do that by looking at the mode returned
+     by GetConsoleMode.  */
+  return "CONOUT$";
+}