Skip to content

Commit 6e056b1

Browse files
author
jan.nijtmans
committed
Simplify NativeIsComPort() implementation: native paths never end in ':', and never use forward slashes (any more), so no need to check for that.
1 parent 99ee3e8 commit 6e056b1

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

win/tclWinChan.c

+12-20
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ TclpOpenFileChannel(
971971
switch (FileGetType(handle)) {
972972
case FILE_TYPE_SERIAL:
973973
/*
974-
* Natively named serial ports "com1-9", "\\\\.\\comXX" are
974+
* Natively named serial ports "com1-9", "\\\\.\\comXX" are
975975
* already done with the code above.
976976
* Here we handle all other serial port names.
977977
*
@@ -1525,12 +1525,11 @@ FileGetType(
15251525
* NativeIsComPort --
15261526
*
15271527
* Determines if a path refers to a Windows serial port.
1528-
* A simple and efficient solution is to use a "name hint" to detect
1529-
* COM ports by their filename instead of resorting to a syscall
1528+
* A simple and efficient solution is to use a "name hint" to detect
1529+
* COM ports by their filename instead of resorting to a syscall
15301530
* to detect serialness after the fact.
15311531
* The following patterns cover common serial port names:
1532-
* COM[1-9]:?
1533-
* //./COM[0-9]+
1532+
* COM[1-9]
15341533
* \\.\COM[0-9]+
15351534
*
15361535
* Results:
@@ -1550,33 +1549,26 @@ NativeIsComPort(
15501549
* 1. Look for com[1-9]:?
15511550
*/
15521551

1553-
if ( (len >= 4) && (len <= 5)
1554-
&& (_wcsnicmp(p, L"com", 3) == 0) ) {
1552+
if ( (len == 4) && (_wcsnicmp(p, L"com", 3) == 0) ) {
15551553
/*
1556-
* The 4th character must be a digit 1..9 optionally followed by a ":"
1554+
* The 4th character must be a digit 1..9
15571555
*/
1558-
1556+
15591557
if ( (p[3] < L'1') || (p[3] > L'9') ) {
15601558
return 0;
15611559
}
1562-
if ( (len == 5) && (p[4] != L':') ) {
1563-
return 0;
1564-
}
15651560
return 1;
15661561
}
1567-
1562+
15681563
/*
1569-
* 2. Look for //./com[0-9]+ or \\.\com[0-9]+
1564+
* 2. Look for \\.\com[0-9]+
15701565
*/
1571-
1572-
if ( (len >= 8) && (
1573-
(_wcsnicmp(p, L"//./com", 7) == 0)
1574-
|| (_wcsnicmp(p, L"\\\\.\\com", 7) == 0) ) )
1575-
{
1566+
1567+
if ((len >= 8) && (_wcsnicmp(p, L"\\\\.\\com", 7) == 0)) {
15761568
/*
15771569
* Charaters 8..end must be a digits 0..9
15781570
*/
1579-
1571+
15801572
for ( i=7; i<len; i++ ) {
15811573
if ( (p[i] < '0') || (p[i] > '9') ) {
15821574
return 0;

0 commit comments

Comments
 (0)