summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorhobbs <hobbs>2006-08-30 17:53:28 (GMT)
committerhobbs <hobbs>2006-08-30 17:53:28 (GMT)
commit8891df0a7cf7aee5549b2f76b48c067443a97100 (patch)
tree65ee12900264b5b45f14ab0f151626bc41460fb0 /win
parent8f481c22e737471e3dc5211eec9d4296f8f7da9f (diff)
downloadtcl-8891df0a7cf7aee5549b2f76b48c067443a97100.zip
tcl-8891df0a7cf7aee5549b2f76b48c067443a97100.tar.gz
tcl-8891df0a7cf7aee5549b2f76b48c067443a97100.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 5d2175c..90c13f7 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.30.2.4 2005/06/23 15:05:22 kennykb Exp $
+ * RCS: @(#) $Id: tclWinChan.c,v 1.30.2.5 2006/08/30 17:53:28 hobbs Exp $
*/
#include "tclWinInt.h"
@@ -100,8 +100,8 @@ static void FileWatchProc _ANSI_ARGS_((ClientData instanceData,
int mask));
static void FileThreadActionProc _ANSI_ARGS_ ((
ClientData instanceData, int action));
+static DWORD FileGetType _ANSI_ARGS_((HANDLE handle));
-
/*
* This structure describes the channel type structure for file based IO.
*/
@@ -784,9 +784,8 @@ TclpOpenFileChannel(interp, pathPtr, mode, permissions)
{
Tcl_Channel channel = 0;
int channelPermissions;
- DWORD accessMode, createMode, shareMode, flags, consoleParams, type;
+ DWORD accessMode, createMode, shareMode, flags;
CONST TCHAR *nativeName;
- DCB dcb;
HANDLE handle;
char channelName[16 + TCL_INTEGER_SPACE];
TclFile readFile = NULL;
@@ -885,29 +884,9 @@ TclpOpenFileChannel(interp, pathPtr, mode, permissions)
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.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
@@ -993,8 +972,6 @@ Tcl_MakeFileChannel(rawHandle, mode)
Tcl_Channel channel = NULL;
HANDLE handle = (HANDLE) rawHandle;
HANDLE dupedHandle;
- DCB dcb;
- DWORD consoleParams, type;
TclFile readFile = NULL;
TclFile writeFile = NULL;
BOOL result;
@@ -1003,30 +980,7 @@ Tcl_MakeFileChannel(rawHandle, mode)
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.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);
@@ -1430,3 +1384,50 @@ FileThreadActionProc (instanceData, action)
}
}
}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * FileGetType --
+ *
+ * Given a file handle, return its type
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+DWORD
+FileGetType(handle)
+ HANDLE handle; /* Opened file handle */
+{
+ DWORD type;
+ DWORD consoleParams;
+ DCB dcb;
+
+ 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())) {
+ if (GetConsoleMode(handle, &consoleParams)) {
+ type = FILE_TYPE_CONSOLE;
+ } else {
+ dcb.DCBlength = sizeof( DCB ) ;
+ if (GetCommState(handle, &dcb)) {
+ type = FILE_TYPE_SERIAL;
+ }
+ }
+ }
+
+ return type;
+}