summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorhobbs <hobbs>2006-08-30 19:30:25 (GMT)
committerhobbs <hobbs>2006-08-30 19:30:25 (GMT)
commit31fb5db54ba6f9ae3e3cab1e3d5ff10df28d009a (patch)
treeccb7d18e67bc5ed9c10876412ec1276e990c2da0 /win
parent9550a587a2a440794916dfbe913ecbd438102012 (diff)
downloadtcl-31fb5db54ba6f9ae3e3cab1e3d5ff10df28d009a.zip
tcl-31fb5db54ba6f9ae3e3cab1e3d5ff10df28d009a.tar.gz
tcl-31fb5db54ba6f9ae3e3cab1e3d5ff10df28d009a.tar.bz2
* win/tclWinChan.c [Bug 819667] Improve logic for identifying COM
ports.
Diffstat (limited to 'win')
-rw-r--r--win/tclWinChan.c103
1 files changed, 52 insertions, 51 deletions
diff --git a/win/tclWinChan.c b/win/tclWinChan.c
index 7752d31..f07c192 100644
--- a/win/tclWinChan.c
+++ b/win/tclWinChan.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinChan.c,v 1.47 2006/03/27 18:08:51 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclWinChan.c,v 1.48 2006/08/30 19:30:25 hobbs Exp $
*/
#include "tclWinInt.h"
@@ -96,6 +96,7 @@ static void FileThreadActionProc(ClientData instanceData,
int action);
static int FileTruncateProc(ClientData instanceData,
Tcl_WideInt length);
+static DWORD FileGetType(HANDLE handle);
/*
* This structure describes the channel type structure for file based IO.
@@ -850,7 +851,7 @@ TclpOpenFileChannel(
{
Tcl_Channel channel = 0;
int channelPermissions = 0;
- DWORD accessMode = 0, createMode, shareMode, flags, consoleParams, type;
+ DWORD accessMode = 0, createMode, shareMode, flags;
CONST TCHAR *nativeName;
HANDLE handle;
char channelName[16 + TCL_INTEGER_SPACE];
@@ -948,30 +949,9 @@ TclpOpenFileChannel(
return NULL;
}
- type = GetFileType(handle);
-
- /*
- * If the file is a character device, we need to try to figure out whether
- * it is a serial port, a console, or something else. We test for the
- * console case first because this is more common.
- */
-
- if (type == FILE_TYPE_CHAR) {
- if (GetConsoleMode(handle, &consoleParams)) {
- type = FILE_TYPE_CONSOLE;
- } else {
- DCB dcb;
-
- dcb.DCBlength = sizeof(DCB);
- if (GetCommState(handle, &dcb)) {
- type = FILE_TYPE_SERIAL;
- }
- }
- }
-
channel = NULL;
- switch (type) {
+ switch (FileGetType(handle)) {
case FILE_TYPE_SERIAL:
/*
* Reopen channel for OVERLAPPED operation. Normally this shouldn't
@@ -1055,7 +1035,6 @@ Tcl_MakeFileChannel(
Tcl_Channel channel = NULL;
HANDLE handle = (HANDLE) rawHandle;
HANDLE dupedHandle;
- DWORD consoleParams, type;
TclFile readFile = NULL, writeFile = NULL;
BOOL result;
@@ -1063,32 +1042,7 @@ Tcl_MakeFileChannel(
return NULL;
}
- /*
- * GetFileType() returns FILE_TYPE_UNKNOWN for invalid handles.
- */
-
- type = GetFileType(handle);
-
- /*
- * If the file is a character device, we need to try to figure out whether
- * it is a serial port, a console, or something else. We test for the
- * console case first because this is more common.
- */
-
- if (type == FILE_TYPE_CHAR) {
- if (GetConsoleMode(handle, &consoleParams)) {
- type = FILE_TYPE_CONSOLE;
- } else {
- DCB dcb;
-
- dcb.DCBlength = sizeof(DCB);
- if (GetCommState(handle, &dcb)) {
- type = FILE_TYPE_SERIAL;
- }
- }
- }
-
- switch (type) {
+ switch (FileGetType(handle)) {
case FILE_TYPE_SERIAL:
channel = TclWinOpenSerialChannel(handle, channelName, mode);
break;
@@ -1490,6 +1444,53 @@ FileThreadActionProc(
}
/*
+ *----------------------------------------------------------------------
+ *
+ * FileGetType --
+ *
+ * Given a file handle, return its type
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+DWORD
+FileGetType(handle)
+ HANDLE handle; /* Opened file handle */
+{
+ DWORD type;
+
+ type = GetFileType(handle);
+
+ /*
+ * If the file is a character device, we need to try to figure out
+ * whether it is a serial port, a console, or something else. We
+ * test for the console case first because this is more common.
+ */
+
+ if ((type == FILE_TYPE_CHAR)
+ || ((type == FILE_TYPE_UNKNOWN) && !GetLastError())) {
+ DWORD consoleParams;
+ if (GetConsoleMode(handle, &consoleParams)) {
+ type = FILE_TYPE_CONSOLE;
+ } else {
+ DCB dcb;
+ dcb.DCBlength = sizeof(DCB);
+ if (GetCommState(handle, &dcb)) {
+ type = FILE_TYPE_SERIAL;
+ }
+ }
+ }
+
+ return type;
+}
+
+/*
* Local Variables:
* mode: c
* c-basic-offset: 4