From 74ae3aefe81a26afb32e15a326db04c03d1275a8 Mon Sep 17 00:00:00 2001 From: jjgarcia Date: Mon, 10 Jan 2005 16:12:56 +0000 Subject: [PATCH] A tty might be open in io mode --- src/c/file.d | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/c/file.d b/src/c/file.d index ee4129e5a..d3455c810 100644 --- a/src/c/file.d +++ b/src/c/file.d @@ -23,6 +23,7 @@ #include #include +#include #include #include "ecl-inl.h" #include "internal.h" @@ -1794,7 +1795,42 @@ flisten(FILE *fp) return (c > 0)? ECL_LISTEN_AVAILABLE : ECL_LISTEN_NO_CHAR; } #endif /* FIONREAD */ +#else + if (isatty(fileno(fp))) { + /* console input */ + HANDLE hnd = _get_osfhandle(_fileno(fp)); + DWORD n; + if (!GetNumberOfConsoleInputEvents(hnd, &n)) + FElibc_error("GetNumberOfConsoleInputEvents() returned an error value", 0); + if (n > 0) { + PINPUT_RECORD buf = (PINPUT_RECORD)malloc(n*sizeof(INPUT_RECORD)); + DWORD nr; + if (!PeekConsoleInput(hnd, buf, n, &nr)) { + free(buf); + FElibc_error("PeekConsoleInput() returned an error value", 0); + } + for (n=0; n old_pos ? ECL_LISTEN_AVAILABLE : ECL_LISTEN_EOF); + } return !ECL_LISTEN_AVAILABLE; } @@ -2607,15 +2643,18 @@ cl_interactive_stream_p(cl_object strm) #endif if (t != t_stream) FEtype_error_stream(strm); + if (strm->stream.closed) + FEclosed_stream(strm); switch(strm->stream.mode) { case smm_synonym: strm = symbol_value(strm->stream.object0); goto BEGIN; case smm_input: + case smm_io: #ifdef HAVE_ISATTY /* Here we should check for the type of file descriptor, * and whether it is connected to a tty. */ - output = Cnil; + output = isatty(fileno(strm->stream.file))? Ct : Cnil; #endif break; default:;