Tcl Source Code

Hex Artifact Content
Login

Artifact 4c69f5ea75cbfa11034868c3ce6327e4496d8509:

Attachment "tcl8.6.1-bug-2413550.diff" to ticket [2413550fff] added by oehhar 2014-02-14 08:01:23.
0000: 64 69 66 66 20 2d 72 75 20 74 63 6c 38 2e 36 2e  diff -ru tcl8.6.
0010: 31 2f 77 69 6e 2f 74 63 6c 57 69 6e 43 68 61 6e  1/win/tclWinChan
0020: 2e 63 20 74 63 6c 38 2e 36 2e 31 2d 62 75 67 2d  .c tcl8.6.1-bug-
0030: 32 34 31 33 35 35 30 2f 77 69 6e 2f 74 63 6c 57  2413550/win/tclW
0040: 69 6e 43 68 61 6e 2e 63 0a 2d 2d 2d 20 74 63 6c  inChan.c.--- tcl
0050: 38 2e 36 2e 31 2f 77 69 6e 2f 74 63 6c 57 69 6e  8.6.1/win/tclWin
0060: 43 68 61 6e 2e 63 09 32 30 31 33 2d 30 39 2d 31  Chan.c.2013-09-1
0070: 39 20 32 31 3a 30 34 3a 31 37 2e 30 30 30 30 30  9 21:04:17.00000
0080: 30 30 30 30 20 2b 30 32 30 30 0a 2b 2b 2b 20 74  0000 +0200.+++ t
0090: 63 6c 38 2e 36 2e 31 2d 62 75 67 2d 32 34 31 33  cl8.6.1-bug-2413
00a0: 35 35 30 2f 77 69 6e 2f 74 63 6c 57 69 6e 43 68  550/win/tclWinCh
00b0: 61 6e 2e 63 09 32 30 31 34 2d 30 32 2d 31 31 20  an.c.2014-02-11 
00c0: 30 38 3a 34 33 3a 32 33 2e 30 34 32 34 39 39 39  08:43:23.0424999
00d0: 30 30 20 2b 30 31 30 30 0a 40 40 20 2d 39 35 2c  00 +0100.@@ -95,
00e0: 36 20 2b 39 35 2c 37 20 40 40 0a 20 73 74 61 74  6 +95,7 @@. stat
00f0: 69 63 20 69 6e 74 09 09 46 69 6c 65 54 72 75 6e  ic int..FileTrun
0100: 63 61 74 65 50 72 6f 63 28 43 6c 69 65 6e 74 44  cateProc(ClientD
0110: 61 74 61 20 69 6e 73 74 61 6e 63 65 44 61 74 61  ata instanceData
0120: 2c 0a 20 09 09 09 20 20 20 20 54 63 6c 5f 57 69  ,. ...    Tcl_Wi
0130: 64 65 49 6e 74 20 6c 65 6e 67 74 68 29 3b 0a 20  deInt length);. 
0140: 73 74 61 74 69 63 20 44 57 4f 52 44 09 09 46 69  static DWORD..Fi
0150: 6c 65 47 65 74 54 79 70 65 28 48 41 4e 44 4c 45  leGetType(HANDLE
0160: 20 68 61 6e 64 6c 65 29 3b 0a 2b 73 74 61 74 69   handle);.+stati
0170: 63 20 69 6e 74 09 09 4e 61 74 69 76 65 49 73 43  c int..NativeIsC
0180: 6f 6d 50 6f 72 74 28 43 4f 4e 53 54 20 54 43 48  omPort(CONST TCH
0190: 41 52 20 2a 6e 61 74 69 76 65 4e 61 6d 65 29 3b  AR *nativeName);
01a0: 0a 20 0a 20 2f 2a 0a 20 20 2a 20 54 68 69 73 20  . . /*.  * This 
01b0: 73 74 72 75 63 74 75 72 65 20 64 65 73 63 72 69  structure descri
01c0: 62 65 73 20 74 68 65 20 63 68 61 6e 6e 65 6c 20  bes the channel 
01d0: 74 79 70 65 20 73 74 72 75 63 74 75 72 65 20 66  type structure f
01e0: 6f 72 20 66 69 6c 65 20 62 61 73 65 64 20 49 4f  or file based IO
01f0: 2e 0a 40 40 20 2d 39 30 32 2c 36 20 2b 39 30 33  ..@@ -902,6 +903
0200: 2c 33 36 20 40 40 0a 20 20 20 20 20 7d 0a 20 0a  ,36 @@.     }. .
0210: 20 20 20 20 20 2f 2a 0a 2b 20 20 20 20 20 2a 20       /*.+     * 
0220: 5b 32 34 31 33 35 35 30 5d 20 41 76 6f 69 64 20  [2413550] Avoid 
0230: 64 6f 75 62 6c 65 2d 6f 70 65 6e 20 6f 66 20 73  double-open of s
0240: 65 72 69 61 6c 20 70 6f 72 74 73 20 6f 6e 20 57  erial ports on W
0250: 69 6e 64 6f 77 73 0a 2b 20 20 20 20 20 2a 20 53  indows.+     * S
0260: 70 65 63 69 61 6c 20 68 61 6e 64 6c 69 6e 67 20  pecial handling 
0270: 66 6f 72 20 57 69 6e 64 6f 77 73 20 73 65 72 69  for Windows seri
0280: 61 6c 20 70 6f 72 74 73 20 62 79 20 61 20 22 6e  al ports by a "n
0290: 61 6d 65 2d 68 69 6e 74 22 0a 2b 20 20 20 20 20  ame-hint".+     
02a0: 2a 20 74 6f 20 64 69 72 65 63 74 6c 79 20 6f 70  * to directly op
02b0: 65 6e 20 69 74 20 77 69 74 68 20 74 68 65 20 4f  en it with the O
02c0: 56 45 52 4c 41 50 50 45 44 20 66 6c 61 67 20 73  VERLAPPED flag s
02d0: 65 74 2e 0a 2b 20 20 20 20 20 2a 2f 0a 2b 0a 2b  et..+     */.+.+
02e0: 20 20 20 20 69 66 28 20 4e 61 74 69 76 65 49 73      if( NativeIs
02f0: 43 6f 6d 50 6f 72 74 28 6e 61 74 69 76 65 4e 61  ComPort(nativeNa
0300: 6d 65 29 20 29 20 7b 0a 2b 09 0a 2b 09 66 6c 61  me) ) {.+..+.fla
0310: 67 73 20 3d 20 30 3b 0a 2b 0a 2b 09 68 61 6e 64  gs = 0;.+.+.hand
0320: 6c 65 20 3d 20 54 63 6c 57 69 6e 53 65 72 69 61  le = TclWinSeria
0330: 6c 4f 70 65 6e 28 49 4e 56 41 4c 49 44 5f 48 41  lOpen(INVALID_HA
0340: 4e 44 4c 45 5f 56 41 4c 55 45 2c 20 6e 61 74 69  NDLE_VALUE, nati
0350: 76 65 4e 61 6d 65 2c 20 61 63 63 65 73 73 4d 6f  veName, accessMo
0360: 64 65 29 3b 0a 2b 09 69 66 20 28 68 61 6e 64 6c  de);.+.if (handl
0370: 65 20 3d 3d 20 49 4e 56 41 4c 49 44 5f 48 41 4e  e == INVALID_HAN
0380: 44 4c 45 5f 56 41 4c 55 45 29 20 7b 0a 2b 09 20  DLE_VALUE) {.+. 
0390: 20 20 20 54 63 6c 57 69 6e 43 6f 6e 76 65 72 74     TclWinConvert
03a0: 45 72 72 6f 72 28 47 65 74 4c 61 73 74 45 72 72  Error(GetLastErr
03b0: 6f 72 28 29 29 3b 0a 2b 09 20 20 20 20 69 66 20  or());.+.    if 
03c0: 28 69 6e 74 65 72 70 20 21 3d 20 28 54 63 6c 5f  (interp != (Tcl_
03d0: 49 6e 74 65 72 70 20 2a 29 20 4e 55 4c 4c 29 20  Interp *) NULL) 
03e0: 7b 0a 2b 09 09 54 63 6c 5f 41 70 70 65 6e 64 52  {.+..Tcl_AppendR
03f0: 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 22 63  esult(interp, "c
0400: 6f 75 6c 64 6e 27 74 20 6f 70 65 6e 20 73 65 72  ouldn't open ser
0410: 69 61 6c 20 5c 22 22 2c 0a 2b 09 09 09 54 63 6c  ial \"",.+...Tcl
0420: 47 65 74 53 74 72 69 6e 67 28 70 61 74 68 50 74  GetString(pathPt
0430: 72 29 2c 20 22 5c 22 3a 20 22 2c 0a 2b 09 09 09  r), "\": ",.+...
0440: 54 63 6c 5f 50 6f 73 69 78 45 72 72 6f 72 28 69  Tcl_PosixError(i
0450: 6e 74 65 72 70 29 2c 20 4e 55 4c 4c 29 3b 0a 2b  nterp), NULL);.+
0460: 09 20 20 20 20 7d 0a 2b 09 20 20 20 20 72 65 74  .    }.+.    ret
0470: 75 72 6e 20 4e 55 4c 4c 3b 0a 2b 09 7d 0a 2b 0a  urn NULL;.+.}.+.
0480: 2b 09 2f 2a 0a 2b 09 2a 20 46 6f 72 20 6e 61 74  +./*.+.* For nat
0490: 69 76 65 6c 79 20 6e 61 6d 65 64 20 57 69 6e 64  ively named Wind
04a0: 6f 77 73 20 73 65 72 69 61 6c 20 70 6f 72 74 73  ows serial ports
04b0: 20 77 65 20 61 72 65 20 64 6f 6e 65 2e 0a 2b 09   we are done..+.
04c0: 2a 2f 0a 2b 09 63 68 61 6e 6e 65 6c 20 3d 20 54  */.+.channel = T
04d0: 63 6c 57 69 6e 4f 70 65 6e 53 65 72 69 61 6c 43  clWinOpenSerialC
04e0: 68 61 6e 6e 65 6c 28 68 61 6e 64 6c 65 2c 20 63  hannel(handle, c
04f0: 68 61 6e 6e 65 6c 4e 61 6d 65 2c 0a 2b 09 09 63  hannelName,.+..c
0500: 68 61 6e 6e 65 6c 50 65 72 6d 69 73 73 69 6f 6e  hannelPermission
0510: 73 29 3b 0a 2b 0a 2b 09 72 65 74 75 72 6e 20 63  s);.+.+.return c
0520: 68 61 6e 6e 65 6c 3b 0a 2b 20 20 20 20 7d 0a 2b  hannel;.+    }.+
0530: 0a 2b 20 20 20 20 2f 2a 0a 20 20 20 20 20 20 2a  .+    /*.      *
0540: 20 49 66 20 74 68 65 20 66 69 6c 65 20 69 73 20   If the file is 
0550: 62 65 69 6e 67 20 63 72 65 61 74 65 64 2c 20 67  being created, g
0560: 65 74 20 74 68 65 20 66 69 6c 65 20 61 74 74 72  et the file attr
0570: 69 62 75 74 65 73 20 66 72 6f 6d 20 74 68 65 0a  ibutes from the.
0580: 20 20 20 20 20 20 2a 20 70 65 72 6d 69 73 73 69        * permissi
0590: 6f 6e 73 20 61 72 67 75 6d 65 6e 74 2c 20 65 6c  ons argument, el
05a0: 73 65 20 75 73 65 20 74 68 65 20 65 78 69 73 74  se use the exist
05b0: 69 6e 67 20 66 69 6c 65 20 61 74 74 72 69 62 75  ing file attribu
05c0: 74 65 73 2e 0a 20 20 20 20 20 20 2a 2f 0a 40 40  tes..      */.@@
05d0: 20 2d 39 31 39 2c 37 20 2b 39 35 30 2c 37 20 40   -919,7 +950,7 @
05e0: 40 0a 20 09 7d 0a 20 20 20 20 20 7d 0a 20 0a 2d  @. .}.     }. .-
05f0: 20 20 20 20 2f 2a 0a 2b 20 20 20 20 20 2f 2a 0a      /*.+     /*.
0600: 20 20 20 20 20 20 2a 20 53 65 74 20 75 70 20 74        * Set up t
0610: 68 65 20 66 69 6c 65 20 73 68 61 72 69 6e 67 20  he file sharing 
0620: 6d 6f 64 65 2e 20 20 57 65 20 77 61 6e 74 20 74  mode.  We want t
0630: 6f 20 61 6c 6c 6f 77 20 73 69 6d 75 6c 74 61 6e  o allow simultan
0640: 65 6f 75 73 20 61 63 63 65 73 73 2e 0a 20 20 20  eous access..   
0650: 20 20 20 2a 2f 0a 20 0a 40 40 20 2d 39 35 32 2c     */. .@@ -952,
0660: 31 31 20 2b 39 38 33 2c 31 35 20 40 40 0a 20 20  11 +983,15 @@.  
0670: 20 20 20 73 77 69 74 63 68 20 28 46 69 6c 65 47     switch (FileG
0680: 65 74 54 79 70 65 28 68 61 6e 64 6c 65 29 29 20  etType(handle)) 
0690: 7b 0a 20 20 20 20 20 63 61 73 65 20 46 49 4c 45  {.     case FILE
06a0: 5f 54 59 50 45 5f 53 45 52 49 41 4c 3a 0a 20 09  _TYPE_SERIAL:. .
06b0: 2f 2a 0a 2b 09 20 2a 20 4e 61 74 69 76 65 6c 79  /*.+. * Natively
06c0: 20 6e 61 6d 65 64 20 73 65 72 69 61 6c 20 70 6f   named serial po
06d0: 72 74 73 20 22 63 6f 6d 31 2d 39 22 2c 20 22 5c  rts "com1-9", "\
06e0: 5c 5c 5c 2e 5c 5c 63 6f 6d 58 58 22 20 61 72 65  \\\.\\comXX" are
06f0: 20 0a 2b 09 20 2a 20 61 6c 72 65 61 64 79 20 64   .+. * already d
0700: 6f 6e 65 20 77 69 74 68 20 74 68 65 20 63 6f 64  one with the cod
0710: 65 20 61 62 6f 76 65 2e 0a 2b 09 20 2a 20 48 65  e above..+. * He
0720: 72 65 20 77 65 20 68 61 6e 64 6c 65 20 61 6c 6c  re we handle all
0730: 20 6f 74 68 65 72 20 73 65 72 69 61 6c 20 70 6f   other serial po
0740: 72 74 20 6e 61 6d 65 73 2e 0a 2b 09 20 2a 0a 20  rt names..+. *. 
0750: 09 20 2a 20 52 65 6f 70 65 6e 20 63 68 61 6e 6e  . * Reopen chann
0760: 65 6c 20 66 6f 72 20 4f 56 45 52 4c 41 50 50 45  el for OVERLAPPE
0770: 44 20 6f 70 65 72 61 74 69 6f 6e 2e 20 4e 6f 72  D operation. Nor
0780: 6d 61 6c 6c 79 20 74 68 69 73 20 73 68 6f 75 6c  mally this shoul
0790: 64 6e 27 74 0a 20 09 20 2a 20 66 61 69 6c 2c 20  dn't. . * fail, 
07a0: 62 65 63 61 75 73 65 20 74 68 65 20 63 68 61 6e  because the chan
07b0: 6e 65 6c 20 65 78 69 73 74 73 2e 0a 20 09 20 2a  nel exists.. . *
07c0: 2f 0a 20 0a 2d 09 68 61 6e 64 6c 65 20 3d 20 54  /. .-.handle = T
07d0: 63 6c 57 69 6e 53 65 72 69 61 6c 52 65 6f 70 65  clWinSerialReope
07e0: 6e 28 68 61 6e 64 6c 65 2c 20 6e 61 74 69 76 65  n(handle, native
07f0: 4e 61 6d 65 2c 20 61 63 63 65 73 73 4d 6f 64 65  Name, accessMode
0800: 29 3b 0a 2b 09 68 61 6e 64 6c 65 20 3d 20 54 63  );.+.handle = Tc
0810: 6c 57 69 6e 53 65 72 69 61 6c 4f 70 65 6e 28 68  lWinSerialOpen(h
0820: 61 6e 64 6c 65 2c 20 6e 61 74 69 76 65 4e 61 6d  andle, nativeNam
0830: 65 2c 20 61 63 63 65 73 73 4d 6f 64 65 29 3b 0a  e, accessMode);.
0840: 20 09 69 66 20 28 68 61 6e 64 6c 65 20 3d 3d 20   .if (handle == 
0850: 49 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56  INVALID_HANDLE_V
0860: 41 4c 55 45 29 20 7b 0a 20 09 20 20 20 20 54 63  ALUE) {. .    Tc
0870: 6c 57 69 6e 43 6f 6e 76 65 72 74 45 72 72 6f 72  lWinConvertError
0880: 28 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 29  (GetLastError())
0890: 3b 0a 20 09 20 20 20 20 69 66 20 28 69 6e 74 65  ;. .    if (inte
08a0: 72 70 20 21 3d 20 28 54 63 6c 5f 49 6e 74 65 72  rp != (Tcl_Inter
08b0: 70 20 2a 29 20 4e 55 4c 4c 29 20 7b 0a 40 40 20  p *) NULL) {.@@ 
08c0: 2d 31 34 39 37 2c 36 20 2b 31 35 33 32 2c 31 32  -1497,6 +1532,12
08d0: 32 20 40 40 0a 20 7d 0a 20 0c 0a 20 2f 2a 0a 2b  2 @@. }. .. /*.+
08e0: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   *--------------
08f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0900: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0910: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0920: 2d 2d 2d 2d 2d 2d 2d 2d 0a 2b 20 2a 0a 2b 20 2a  --------.+ *.+ *
0930: 20 4e 61 74 69 76 65 49 73 43 6f 6d 50 6f 72 74   NativeIsComPort
0940: 20 2d 2d 0a 2b 20 2a 0a 2b 20 2a 09 44 65 74 65   --.+ *.+ *.Dete
0950: 72 6d 69 6e 65 73 20 69 66 20 61 20 70 61 74 68  rmines if a path
0960: 20 72 65 66 65 72 73 20 74 6f 20 61 20 57 69 6e   refers to a Win
0970: 64 6f 77 73 20 73 65 72 69 61 6c 20 70 6f 72 74  dows serial port
0980: 2e 0a 2b 20 2a 09 41 20 73 69 6d 70 6c 65 20 61  ..+ *.A simple a
0990: 6e 64 20 65 66 66 69 63 69 65 6e 74 20 73 6f 6c  nd efficient sol
09a0: 75 74 69 6f 6e 20 69 73 20 74 6f 20 75 73 65 20  ution is to use 
09b0: 61 20 22 6e 61 6d 65 20 68 69 6e 74 22 20 74 6f  a "name hint" to
09c0: 20 64 65 74 65 63 74 20 0a 2b 20 2a 20 20 20 20   detect .+ *    
09d0: 20 20 43 4f 4d 20 70 6f 72 74 73 20 62 79 20 74    COM ports by t
09e0: 68 65 69 72 20 66 69 6c 65 6e 61 6d 65 20 69 6e  heir filename in
09f0: 73 74 65 61 64 20 6f 66 20 72 65 73 6f 72 74 69  stead of resorti
0a00: 6e 67 20 74 6f 20 61 20 73 79 73 63 61 6c 6c 20  ng to a syscall 
0a10: 0a 2b 20 2a 09 74 6f 20 64 65 74 65 63 74 20 73  .+ *.to detect s
0a20: 65 72 69 61 6c 6e 65 73 73 20 61 66 74 65 72 20  erialness after 
0a30: 74 68 65 20 66 61 63 74 2e 0a 2b 20 2a 09 54 68  the fact..+ *.Th
0a40: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 70 61 74 74  e following patt
0a50: 65 72 6e 73 20 63 6f 76 65 72 20 63 6f 6d 6d 6f  erns cover commo
0a60: 6e 20 73 65 72 69 61 6c 20 70 6f 72 74 20 6e 61  n serial port na
0a70: 6d 65 73 3a 0a 2b 20 2a 09 20 20 20 20 43 4f 4d  mes:.+ *.    COM
0a80: 5b 31 2d 39 5d 3a 3f 0a 2b 20 2a 09 20 20 20 20  [1-9]:?.+ *.    
0a90: 2f 2f 2e 2f 43 4f 4d 5b 30 2d 39 5d 2b 0a 2b 20  //./COM[0-9]+.+ 
0aa0: 2a 09 20 20 20 20 5c 5c 2e 5c 43 4f 4d 5b 30 2d  *.    \\.\COM[0-
0ab0: 39 5d 2b 0a 2b 20 2a 0a 2b 20 2a 20 52 65 73 75  9]+.+ *.+ * Resu
0ac0: 6c 74 73 3a 0a 2b 20 2a 09 31 20 3d 20 73 65 72  lts:.+ *.1 = ser
0ad0: 69 61 6c 20 70 6f 72 74 2c 20 30 20 3d 20 6e 6f  ial port, 0 = no
0ae0: 74 2e 0a 2b 20 2a 0a 2b 20 2a 2d 2d 2d 2d 2d 2d  t..+ *.+ *------
0af0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b30: 0a 2b 20 2a 2f 0a 2b 0a 2b 73 74 61 74 69 63 20  .+ */.+.+static 
0b40: 69 6e 74 0a 2b 4e 61 74 69 76 65 49 73 43 6f 6d  int.+NativeIsCom
0b50: 50 6f 72 74 28 0a 2b 20 20 20 20 63 6f 6e 73 74  Port(.+    const
0b60: 20 54 43 48 41 52 20 2a 6e 61 74 69 76 65 50 61   TCHAR *nativePa
0b70: 74 68 29 09 2f 2a 20 50 61 74 68 20 6f 66 20 66  th)./* Path of f
0b80: 69 6c 65 20 74 6f 20 61 63 63 65 73 73 2c 20 6e  ile to access, n
0b90: 61 74 69 76 65 20 65 6e 63 6f 64 69 6e 67 2e 20  ative encoding. 
0ba0: 2a 2f 0a 2b 7b 0a 2b 20 20 20 20 2f 2a 0a 2b 20  */.+{.+    /*.+ 
0bb0: 20 20 20 20 2a 20 55 73 65 20 77 69 64 65 2d 63      * Use wide-c
0bc0: 68 61 72 20 6f 72 20 70 6c 61 69 6e 20 63 68 61  har or plain cha
0bd0: 72 61 63 74 65 72 20 63 61 73 65 2d 69 6e 73 65  racter case-inse
0be0: 6e 73 69 74 69 76 65 20 63 6f 6d 70 61 72 69 73  nsitive comparis
0bf0: 6f 6e 0a 2b 20 20 20 20 20 2a 2f 0a 2b 20 20 20  on.+     */.+   
0c00: 20 69 66 20 28 31 29 20 7b 0a 2b 09 63 6f 6e 73   if (1) {.+.cons
0c10: 74 20 57 43 48 41 52 20 2a 70 20 3d 20 28 63 6f  t WCHAR *p = (co
0c20: 6e 73 74 20 57 43 48 41 52 20 2a 29 20 6e 61 74  nst WCHAR *) nat
0c30: 69 76 65 50 61 74 68 3b 0a 2b 09 69 6e 74 20 69  ivePath;.+.int i
0c40: 2c 20 6c 65 6e 20 3d 20 77 63 73 6c 65 6e 28 70  , len = wcslen(p
0c50: 29 3b 0a 2b 0a 2b 09 2f 2a 0a 2b 09 20 2a 20 31  );.+.+./*.+. * 1
0c60: 2e 20 4c 6f 6f 6b 20 66 6f 72 20 63 6f 6d 5b 31  . Look for com[1
0c70: 2d 39 5d 3a 3f 0a 2b 09 20 2a 2f 0a 2b 0a 2b 09  -9]:?.+. */.+.+.
0c80: 69 66 20 28 20 28 6c 65 6e 20 3e 3d 20 34 29 20  if ( (len >= 4) 
0c90: 26 26 20 28 6c 65 6e 20 3c 3d 20 35 29 20 0a 2b  && (len <= 5) .+
0ca0: 09 09 26 26 20 28 5f 77 63 73 6e 69 63 6d 70 28  ..&& (_wcsnicmp(
0cb0: 70 2c 20 4c 22 63 6f 6d 22 2c 20 33 29 20 3d 3d  p, L"com", 3) ==
0cc0: 20 30 29 20 29 20 7b 0a 2b 09 20 20 20 20 2f 2a   0) ) {.+.    /*
0cd0: 0a 2b 09 20 20 20 20 2a 20 54 68 65 20 34 74 68  .+.    * The 4th
0ce0: 20 63 68 61 72 61 63 74 65 72 20 6d 75 73 74 20   character must 
0cf0: 62 65 20 61 20 64 69 67 69 74 20 31 2e 2e 39 20  be a digit 1..9 
0d00: 6f 70 74 69 6f 6e 61 6c 6c 79 20 66 6f 6c 6c 6f  optionally follo
0d10: 77 65 64 20 62 79 20 61 20 22 3a 22 0a 2b 09 20  wed by a ":".+. 
0d20: 20 20 20 2a 2f 0a 2b 0a 2b 09 20 20 20 20 69 66     */.+.+.    if
0d30: 20 28 20 28 70 5b 33 5d 20 3c 20 4c 27 31 27 29   ( (p[3] < L'1')
0d40: 20 7c 7c 20 28 70 5b 33 5d 20 3e 20 4c 27 39 27   || (p[3] > L'9'
0d50: 29 20 29 20 7b 0a 2b 09 09 72 65 74 75 72 6e 20  ) ) {.+..return 
0d60: 30 3b 0a 2b 09 20 20 20 20 7d 0a 2b 09 20 20 20  0;.+.    }.+.   
0d70: 20 69 66 20 28 20 28 6c 65 6e 20 3d 3d 20 35 29   if ( (len == 5)
0d80: 20 26 26 20 28 70 5b 34 5d 20 21 3d 20 4c 27 3a   && (p[4] != L':
0d90: 27 29 20 29 20 7b 0a 2b 09 09 72 65 74 75 72 6e  ') ) {.+..return
0da0: 20 30 3b 0a 2b 09 20 20 20 20 7d 0a 2b 09 20 20   0;.+.    }.+.  
0db0: 20 20 72 65 74 75 72 6e 20 31 3b 0a 2b 09 7d 0a    return 1;.+.}.
0dc0: 2b 0a 2b 09 2f 2a 0a 2b 09 20 2a 20 32 2e 20 4c  +.+./*.+. * 2. L
0dd0: 6f 6f 6b 20 66 6f 72 20 2f 2f 2e 2f 63 6f 6d 5b  ook for //./com[
0de0: 30 2d 39 5d 2b 20 6f 72 20 5c 5c 2e 5c 63 6f 6d  0-9]+ or \\.\com
0df0: 5b 30 2d 39 5d 2b 0a 2b 09 20 2a 2f 0a 2b 0a 2b  [0-9]+.+. */.+.+
0e00: 09 69 66 20 28 20 28 6c 65 6e 20 3e 3d 20 38 29  .if ( (len >= 8)
0e10: 20 26 26 20 28 20 0a 2b 09 09 20 20 20 28 5f 77   && ( .+..   (_w
0e20: 63 73 6e 69 63 6d 70 28 70 2c 20 4c 22 2f 2f 2e  csnicmp(p, L"//.
0e30: 2f 63 6f 6d 22 2c 20 37 29 20 3d 3d 20 30 29 0a  /com", 7) == 0).
0e40: 2b 09 09 7c 7c 20 28 5f 77 63 73 6e 69 63 6d 70  +..|| (_wcsnicmp
0e50: 28 70 2c 20 4c 22 5c 5c 5c 5c 2e 5c 5c 63 6f 6d  (p, L"\\\\.\\com
0e60: 22 2c 20 37 29 20 3d 3d 20 30 29 20 29 20 29 0a  ", 7) == 0) ) ).
0e70: 2b 09 7b 0a 2b 09 20 20 20 20 2f 2a 0a 2b 09 20  +.{.+.    /*.+. 
0e80: 20 20 20 2a 20 43 68 61 72 61 74 65 72 73 20 38     * Charaters 8
0e90: 2e 2e 65 6e 64 20 6d 75 73 74 20 62 65 20 61 20  ..end must be a 
0ea0: 64 69 67 69 74 73 20 30 2e 2e 39 0a 2b 09 20 20  digits 0..9.+.  
0eb0: 20 20 2a 2f 0a 2b 0a 2b 09 20 20 20 20 66 6f 72    */.+.+.    for
0ec0: 20 28 20 69 3d 37 3b 20 69 3c 6c 65 6e 3b 20 69   ( i=7; i<len; i
0ed0: 2b 2b 20 29 20 7b 0a 2b 09 09 69 66 20 28 20 28  ++ ) {.+..if ( (
0ee0: 70 5b 69 5d 20 3c 20 27 30 27 29 20 7c 7c 20 28  p[i] < '0') || (
0ef0: 70 5b 69 5d 20 3e 20 27 39 27 29 20 29 20 7b 0a  p[i] > '9') ) {.
0f00: 2b 09 09 20 20 20 20 72 65 74 75 72 6e 20 30 3b  +..    return 0;
0f10: 0a 2b 09 09 7d 0a 2b 09 20 20 20 20 7d 0a 2b 09  .+..}.+.    }.+.
0f20: 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 2b 09      return 1;.+.
0f30: 7d 0a 2b 0a 2b 20 20 20 20 7d 20 65 6c 73 65 20  }.+.+    } else 
0f40: 7b 0a 2b 09 63 6f 6e 73 74 20 63 68 61 72 20 2a  {.+.const char *
0f50: 70 20 3d 20 28 63 6f 6e 73 74 20 63 68 61 72 20  p = (const char 
0f60: 2a 29 20 6e 61 74 69 76 65 50 61 74 68 3b 0a 2b  *) nativePath;.+
0f70: 09 69 6e 74 20 20 20 69 2c 20 6c 65 6e 20 3d 20  .int   i, len = 
0f80: 73 74 72 6c 65 6e 28 70 29 3b 0a 2b 0a 2b 09 2f  strlen(p);.+.+./
0f90: 2a 0a 2b 09 20 2a 20 31 2e 20 4c 6f 6f 6b 20 66  *.+. * 1. Look f
0fa0: 6f 72 20 63 6f 6d 5b 31 2d 39 5d 3a 3f 0a 2b 09  or com[1-9]:?.+.
0fb0: 20 2a 2f 0a 2b 0a 2b 09 69 66 20 28 20 28 6c 65   */.+.+.if ( (le
0fc0: 6e 20 3e 3d 20 34 29 20 26 26 20 28 6c 65 6e 20  n >= 4) && (len 
0fd0: 3c 3d 20 35 29 20 0a 2b 09 09 26 26 20 28 73 74  <= 5) .+..&& (st
0fe0: 72 6e 69 63 6d 70 28 70 2c 20 22 63 6f 6d 22 2c  rnicmp(p, "com",
0ff0: 20 33 29 20 3d 3d 20 30 29 20 29 20 7b 0a 2b 09   3) == 0) ) {.+.
1000: 20 20 20 20 2f 2a 0a 2b 09 20 20 20 20 2a 20 54      /*.+.    * T
1010: 68 65 20 34 74 68 20 63 68 61 72 61 63 74 65 72  he 4th character
1020: 20 6d 75 73 74 20 62 65 20 61 20 64 69 67 69 74   must be a digit
1030: 20 31 2e 2e 39 20 6f 70 74 69 6f 6e 61 6c 6c 79   1..9 optionally
1040: 20 66 6f 6c 6c 6f 77 65 64 20 62 79 20 61 20 22   followed by a "
1050: 3a 22 0a 2b 09 20 20 20 20 2a 2f 0a 2b 0a 2b 09  :".+.    */.+.+.
1060: 20 20 20 20 69 66 20 28 20 28 70 5b 33 5d 20 3c      if ( (p[3] <
1070: 20 27 31 27 29 20 7c 7c 20 28 70 5b 33 5d 20 3e   '1') || (p[3] >
1080: 20 27 39 27 29 20 29 20 7b 0a 2b 09 09 72 65 74   '9') ) {.+..ret
1090: 75 72 6e 20 30 3b 0a 2b 09 20 20 20 20 7d 0a 2b  urn 0;.+.    }.+
10a0: 09 20 20 20 20 69 66 20 28 20 28 6c 65 6e 20 3d  .    if ( (len =
10b0: 3d 20 35 29 20 26 26 20 28 70 5b 34 5d 20 21 3d  = 5) && (p[4] !=
10c0: 20 27 3a 27 29 20 29 20 7b 0a 2b 09 09 72 65 74   ':') ) {.+..ret
10d0: 75 72 6e 20 30 3b 0a 2b 09 20 20 20 20 7d 0a 2b  urn 0;.+.    }.+
10e0: 09 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 2b  .    return 1;.+
10f0: 09 7d 0a 2b 0a 2b 09 2f 2a 0a 2b 09 20 2a 20 32  .}.+.+./*.+. * 2
1100: 2e 20 4c 6f 6f 6b 20 66 6f 72 20 2f 2f 2e 2f 63  . Look for //./c
1110: 6f 6d 5b 30 2d 39 5d 2b 20 6f 72 20 5c 5c 2e 5c  om[0-9]+ or \\.\
1120: 63 6f 6d 5b 30 2d 39 5d 2b 0a 2b 09 20 2a 2f 0a  com[0-9]+.+. */.
1130: 2b 0a 2b 09 69 66 20 28 20 28 6c 65 6e 20 3e 3d  +.+.if ( (len >=
1140: 20 38 29 20 26 26 20 28 20 0a 2b 09 09 20 20 20   8) && ( .+..   
1150: 28 73 74 72 6e 69 63 6d 70 28 70 2c 20 22 2f 2f  (strnicmp(p, "//
1160: 2e 2f 63 6f 6d 22 2c 20 37 29 20 3d 3d 20 30 29  ./com", 7) == 0)
1170: 0a 2b 09 09 7c 7c 20 28 73 74 72 6e 69 63 6d 70  .+..|| (strnicmp
1180: 28 70 2c 20 22 5c 5c 5c 5c 2e 5c 5c 63 6f 6d 22  (p, "\\\\.\\com"
1190: 2c 20 37 29 20 3d 3d 20 30 29 20 29 20 29 0a 2b  , 7) == 0) ) ).+
11a0: 09 7b 0a 2b 09 20 20 20 20 2f 2a 0a 2b 09 20 20  .{.+.    /*.+.  
11b0: 20 20 2a 20 43 68 61 72 61 74 65 72 73 20 38 2e    * Charaters 8.
11c0: 2e 65 6e 64 20 6d 75 73 74 20 62 65 20 61 20 64  .end must be a d
11d0: 69 67 69 74 73 20 30 2e 2e 39 0a 2b 09 20 20 20  igits 0..9.+.   
11e0: 20 2a 2f 0a 2b 0a 2b 09 20 20 20 20 66 6f 72 20   */.+.+.    for 
11f0: 28 20 69 3d 37 3b 20 69 3c 6c 65 6e 3b 20 69 2b  ( i=7; i<len; i+
1200: 2b 20 29 20 7b 0a 2b 09 09 69 66 20 28 20 28 70  + ) {.+..if ( (p
1210: 5b 69 5d 20 3c 20 27 30 27 29 20 7c 7c 20 28 70  [i] < '0') || (p
1220: 5b 69 5d 20 3e 20 27 39 27 29 20 29 20 7b 0a 2b  [i] > '9') ) {.+
1230: 09 09 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a  ..    return 0;.
1240: 2b 09 09 7d 0a 2b 09 20 20 20 20 7d 0a 2b 09 20  +..}.+.    }.+. 
1250: 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 2b 09 7d     return 1;.+.}
1260: 0a 2b 20 20 20 20 7d 0a 2b 20 20 20 20 72 65 74  .+    }.+    ret
1270: 75 72 6e 20 30 3b 0a 2b 7d 0a 2b 0c 0a 2b 2f 2a  urn 0;.+}.+..+/*
1280: 0a 20 20 2a 20 4c 6f 63 61 6c 20 56 61 72 69 61  .  * Local Varia
1290: 62 6c 65 73 3a 0a 20 20 2a 20 6d 6f 64 65 3a 20  bles:.  * mode: 
12a0: 63 0a 20 20 2a 20 63 2d 62 61 73 69 63 2d 6f 66  c.  * c-basic-of
12b0: 66 73 65 74 3a 20 34 0a 64 69 66 66 20 2d 72 75  fset: 4.diff -ru
12c0: 20 74 63 6c 38 2e 36 2e 31 2f 77 69 6e 2f 74 63   tcl8.6.1/win/tc
12d0: 6c 57 69 6e 49 6e 74 2e 68 20 74 63 6c 38 2e 36  lWinInt.h tcl8.6
12e0: 2e 31 2d 62 75 67 2d 32 34 31 33 35 35 30 2f 77  .1-bug-2413550/w
12f0: 69 6e 2f 74 63 6c 57 69 6e 49 6e 74 2e 68 0a 2d  in/tclWinInt.h.-
1300: 2d 2d 20 74 63 6c 38 2e 36 2e 31 2f 77 69 6e 2f  -- tcl8.6.1/win/
1310: 74 63 6c 57 69 6e 49 6e 74 2e 68 09 32 30 31 33  tclWinInt.h.2013
1320: 2d 30 39 2d 31 39 20 32 31 3a 30 34 3a 31 37 2e  -09-19 21:04:17.
1330: 30 30 30 30 30 30 30 30 30 20 2b 30 32 30 30 0a  000000000 +0200.
1340: 2b 2b 2b 20 74 63 6c 38 2e 36 2e 31 2d 62 75 67  +++ tcl8.6.1-bug
1350: 2d 32 34 31 33 35 35 30 2f 77 69 6e 2f 74 63 6c  -2413550/win/tcl
1360: 57 69 6e 49 6e 74 2e 68 09 32 30 31 34 2d 30 32  WinInt.h.2014-02
1370: 2d 31 31 20 30 38 3a 34 33 3a 32 36 2e 31 38 30  -11 08:43:26.180
1380: 34 39 39 39 30 30 20 2b 30 31 30 30 0a 40 40 20  499900 +0100.@@ 
1390: 2d 34 39 2c 37 20 2b 34 39 2c 37 20 40 40 0a 20  -49,7 +49,7 @@. 
13a0: 09 09 09 20 20 20 20 69 6e 74 20 70 65 72 6d 69  ...    int permi
13b0: 73 73 69 6f 6e 73 2c 20 69 6e 74 20 61 70 70 65  ssions, int appe
13c0: 6e 64 4d 6f 64 65 29 3b 0a 20 4d 4f 44 55 4c 45  ndMode);. MODULE
13d0: 5f 53 43 4f 50 45 20 54 63 6c 5f 43 68 61 6e 6e  _SCOPE Tcl_Chann
13e0: 65 6c 20 54 63 6c 57 69 6e 4f 70 65 6e 53 65 72  el TclWinOpenSer
13f0: 69 61 6c 43 68 61 6e 6e 65 6c 28 48 41 4e 44 4c  ialChannel(HANDL
1400: 45 20 68 61 6e 64 6c 65 2c 0a 20 09 09 09 20 20  E handle,. ...  
1410: 20 20 63 68 61 72 20 2a 63 68 61 6e 6e 65 6c 4e    char *channelN
1420: 61 6d 65 2c 20 69 6e 74 20 70 65 72 6d 69 73 73  ame, int permiss
1430: 69 6f 6e 73 29 3b 0a 2d 4d 4f 44 55 4c 45 5f 53  ions);.-MODULE_S
1440: 43 4f 50 45 20 48 41 4e 44 4c 45 09 54 63 6c 57  COPE HANDLE.TclW
1450: 69 6e 53 65 72 69 61 6c 52 65 6f 70 65 6e 28 48  inSerialReopen(H
1460: 41 4e 44 4c 45 20 68 61 6e 64 6c 65 2c 20 63 6f  ANDLE handle, co
1470: 6e 73 74 20 54 43 48 41 52 20 2a 6e 61 6d 65 2c  nst TCHAR *name,
1480: 0a 2b 4d 4f 44 55 4c 45 5f 53 43 4f 50 45 20 48  .+MODULE_SCOPE H
1490: 41 4e 44 4c 45 09 54 63 6c 57 69 6e 53 65 72 69  ANDLE.TclWinSeri
14a0: 61 6c 4f 70 65 6e 28 48 41 4e 44 4c 45 20 68 61  alOpen(HANDLE ha
14b0: 6e 64 6c 65 2c 20 63 6f 6e 73 74 20 54 43 48 41  ndle, const TCHA
14c0: 52 20 2a 6e 61 6d 65 2c 0a 20 09 09 09 20 20 20  R *name,. ...   
14d0: 20 44 57 4f 52 44 20 61 63 63 65 73 73 29 3b 0a   DWORD access);.
14e0: 20 4d 4f 44 55 4c 45 5f 53 43 4f 50 45 20 69 6e   MODULE_SCOPE in
14f0: 74 09 54 63 6c 57 69 6e 53 79 6d 4c 69 6e 6b 43  t.TclWinSymLinkC
1500: 6f 70 79 44 69 72 65 63 74 6f 72 79 28 63 6f 6e  opyDirectory(con
1510: 73 74 20 54 43 48 41 52 20 2a 4c 69 6e 6b 4f 72  st TCHAR *LinkOr
1520: 69 67 69 6e 61 6c 2c 0a 20 09 09 09 20 20 20 20  iginal,. ...    
1530: 63 6f 6e 73 74 20 54 43 48 41 52 20 2a 4c 69 6e  const TCHAR *Lin
1540: 6b 43 6f 70 79 29 3b 0a 64 69 66 66 20 2d 72 75  kCopy);.diff -ru
1550: 20 74 63 6c 38 2e 36 2e 31 2f 77 69 6e 2f 74 63   tcl8.6.1/win/tc
1560: 6c 57 69 6e 53 65 72 69 61 6c 2e 63 20 74 63 6c  lWinSerial.c tcl
1570: 38 2e 36 2e 31 2d 62 75 67 2d 32 34 31 33 35 35  8.6.1-bug-241355
1580: 30 2f 77 69 6e 2f 74 63 6c 57 69 6e 53 65 72 69  0/win/tclWinSeri
1590: 61 6c 2e 63 0a 2d 2d 2d 20 74 63 6c 38 2e 36 2e  al.c.--- tcl8.6.
15a0: 31 2f 77 69 6e 2f 74 63 6c 57 69 6e 53 65 72 69  1/win/tclWinSeri
15b0: 61 6c 2e 63 09 32 30 31 33 2d 30 39 2d 31 39 20  al.c.2013-09-19 
15c0: 32 31 3a 30 34 3a 31 37 2e 30 30 30 30 30 30 30  21:04:17.0000000
15d0: 30 30 20 2b 30 32 30 30 0a 2b 2b 2b 20 74 63 6c  00 +0200.+++ tcl
15e0: 38 2e 36 2e 31 2d 62 75 67 2d 32 34 31 33 35 35  8.6.1-bug-241355
15f0: 30 2f 77 69 6e 2f 74 63 6c 57 69 6e 53 65 72 69  0/win/tclWinSeri
1600: 61 6c 2e 63 09 32 30 31 34 2d 30 32 2d 31 31 20  al.c.2014-02-11 
1610: 30 38 3a 34 33 3a 33 35 2e 36 39 31 34 39 39 39  08:43:35.6914999
1620: 30 30 20 2b 30 31 30 30 0a 40 40 20 2d 31 34 31  00 +0100.@@ -141
1630: 30 2c 32 33 20 2b 31 34 31 30 2c 32 32 20 40 40  0,23 +1410,22 @@
1640: 0a 20 2f 2a 0a 20 20 2a 2d 2d 2d 2d 2d 2d 2d 2d  . /*.  *--------
1650: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1660: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1670: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1680: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20  --------------. 
1690: 20 2a 0a 2d 20 2a 20 54 63 6c 57 69 6e 53 65 72   *.- * TclWinSer
16a0: 69 61 6c 52 65 6f 70 65 6e 20 2d 2d 0a 2b 20 2a  ialReopen --.+ *
16b0: 20 54 63 6c 57 69 6e 53 65 72 69 61 6c 4f 70 65   TclWinSerialOpe
16c0: 6e 20 2d 2d 0a 20 20 2a 0a 2d 20 2a 09 52 65 6f  n --.  *.- *.Reo
16d0: 70 65 6e 73 20 74 68 65 20 73 65 72 69 61 6c 20  pens the serial 
16e0: 70 6f 72 74 20 77 69 74 68 20 74 68 65 20 4f 56  port with the OV
16f0: 45 52 4c 41 50 50 45 44 20 46 4c 41 47 20 73 65  ERLAPPED FLAG se
1700: 74 0a 2b 20 2a 09 4f 70 65 6e 73 20 6f 72 20 52  t.+ *.Opens or R
1710: 65 6f 70 65 6e 73 20 74 68 65 20 73 65 72 69 61  eopens the seria
1720: 6c 20 70 6f 72 74 20 77 69 74 68 20 74 68 65 20  l port with the 
1730: 4f 56 45 52 4c 41 50 50 45 44 20 46 4c 41 47 20  OVERLAPPED FLAG 
1740: 73 65 74 0a 20 20 2a 0a 20 20 2a 20 52 65 73 75  set.  *.  * Resu
1750: 6c 74 73 3a 0a 2d 20 2a 09 52 65 74 75 72 6e 73  lts:.- *.Returns
1760: 20 74 68 65 20 6e 65 77 20 68 61 6e 64 6c 65 2c   the new handle,
1770: 20 6f 72 20 49 4e 56 41 4c 49 44 5f 48 41 4e 44   or INVALID_HAND
1780: 4c 45 5f 56 41 4c 55 45 2e 20 4e 6f 72 6d 61 6c  LE_VALUE. Normal
1790: 6c 79 20 74 68 65 72 65 0a 2d 20 2a 09 73 68 6f  ly there.- *.sho
17a0: 75 6c 64 6e 27 74 20 62 65 20 61 6e 79 20 65 72  uldn't be any er
17b0: 72 6f 72 2c 20 62 65 63 61 75 73 65 20 74 68 65  ror, because the
17c0: 20 73 61 6d 65 20 63 68 61 6e 6e 65 6c 20 68 61   same channel ha
17d0: 73 20 70 72 65 76 69 6f 75 73 6c 79 20 62 65 65  s previously bee
17e0: 6e 0a 2d 20 2a 09 73 75 63 63 65 65 73 66 75 6c  n.- *.succeesful
17f0: 6c 79 20 6f 70 65 6e 65 64 2e 0a 2b 20 2a 09 52  ly opened..+ *.R
1800: 65 74 75 72 6e 73 20 74 68 65 20 6e 65 77 20 68  eturns the new h
1810: 61 6e 64 6c 65 2c 20 6f 72 20 49 4e 56 41 4c 49  andle, or INVALI
1820: 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 45 2e 20  D_HANDLE_VALUE. 
1830: 0a 2b 20 2a 09 49 20 61 6e 20 65 78 69 73 74 69  .+ *.I an existi
1840: 6e 67 20 63 68 61 6e 6e 65 6c 20 69 73 20 73 70  ng channel is sp
1850: 65 63 69 66 69 65 64 20 69 74 20 69 73 20 63 6c  ecified it is cl
1860: 6f 73 65 64 20 61 6e 64 20 72 65 6f 70 65 6e 65  osed and reopene
1870: 64 2e 0a 20 20 2a 0a 20 20 2a 20 53 69 64 65 20  d..  *.  * Side 
1880: 65 66 66 65 63 74 73 3a 0a 2d 20 2a 09 4d 61 79  effects:.- *.May
1890: 20 63 6c 6f 73 65 20 74 68 65 20 6f 72 69 67 69   close the origi
18a0: 6e 61 6c 20 68 61 6e 64 6c 65 0a 2b 20 2a 09 4d  nal handle.+ *.M
18b0: 61 79 20 63 6c 6f 73 65 2f 72 65 6f 70 65 6e 20  ay close/reopen 
18c0: 74 68 65 20 6f 72 69 67 69 6e 61 6c 20 68 61 6e  the original han
18d0: 64 6c 65 0a 20 20 2a 0a 20 20 2a 2d 2d 2d 2d 2d  dle.  *.  *-----
18e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
18f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1900: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1910: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1920: 2d 0a 20 20 2a 2f 0a 20 0a 20 48 41 4e 44 4c 45  -.  */. . HANDLE
1930: 0a 2d 54 63 6c 57 69 6e 53 65 72 69 61 6c 52 65  .-TclWinSerialRe
1940: 6f 70 65 6e 28 0a 2b 54 63 6c 57 69 6e 53 65 72  open(.+TclWinSer
1950: 69 61 6c 4f 70 65 6e 28 0a 20 20 20 20 20 48 41  ialOpen(.     HA
1960: 4e 44 4c 45 20 68 61 6e 64 6c 65 2c 0a 20 20 20  NDLE handle,.   
1970: 20 20 63 6f 6e 73 74 20 54 43 48 41 52 20 2a 6e    const TCHAR *n
1980: 61 6d 65 2c 0a 20 20 20 20 20 44 57 4f 52 44 20  ame,.     DWORD 
1990: 61 63 63 65 73 73 29 0a 40 40 20 2d 31 34 33 34  access).@@ -1434
19a0: 2c 31 37 20 2b 31 34 33 33 2c 32 35 20 40 40 0a  ,17 +1433,25 @@.
19b0: 20 20 20 20 20 53 65 72 69 61 6c 49 6e 69 74 28       SerialInit(
19c0: 29 3b 0a 20 0a 20 20 20 20 20 2f 2a 0a 2d 20 20  );. .     /*.-  
19d0: 20 20 20 2a 20 4d 75 6c 74 69 74 68 72 65 61 64     * Multithread
19e0: 65 64 20 49 2f 4f 20 6e 65 65 64 73 20 74 68 65  ed I/O needs the
19f0: 20 6f 76 65 72 6c 61 70 70 65 64 20 66 6c 61 67   overlapped flag
1a00: 20 73 65 74 20 6f 74 68 65 72 77 69 73 65 0a 2d   set otherwise.-
1a10: 20 20 20 20 20 2a 20 43 6c 65 61 72 43 6f 6d 6d       * ClearComm
1a20: 45 72 72 6f 72 20 62 6c 6f 63 6b 73 20 75 6e 64  Error blocks und
1a30: 65 72 20 57 69 6e 64 6f 77 73 20 4e 54 2f 32 30  er Windows NT/20
1a40: 30 30 20 75 6e 74 69 6c 20 73 65 72 69 61 6c 20  00 until serial 
1a50: 6f 75 74 70 75 74 20 69 73 0a 2d 20 20 20 20 20  output is.-     
1a60: 2a 20 66 69 6e 69 73 68 65 64 0a 2b 20 20 20 20  * finished.+    
1a70: 20 2a 20 49 66 20 61 6e 20 6f 70 65 6e 20 63 68   * If an open ch
1a80: 61 6e 6e 65 6c 20 69 73 20 73 70 65 63 69 66 69  annel is specifi
1a90: 65 64 2c 20 63 6c 6f 73 65 20 69 74 0a 20 20 20  ed, close it.   
1aa0: 20 20 20 2a 2f 0a 20 0a 2d 20 20 20 20 69 66 20     */. .-    if 
1ab0: 28 43 6c 6f 73 65 48 61 6e 64 6c 65 28 68 61 6e  (CloseHandle(han
1ac0: 64 6c 65 29 20 3d 3d 20 46 41 4c 53 45 29 20 7b  dle) == FALSE) {
1ad0: 0a 2d 09 72 65 74 75 72 6e 20 49 4e 56 41 4c 49  .-.return INVALI
1ae0: 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 45 3b 0a  D_HANDLE_VALUE;.
1af0: 2b 09 69 66 20 28 20 68 61 6e 64 6c 65 20 21 3d  +.if ( handle !=
1b00: 20 49 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45 5f   INVALID_HANDLE_
1b10: 56 41 4c 55 45 20 29 20 7b 0a 2b 09 09 69 66 20  VALUE ) {.+..if 
1b20: 28 43 6c 6f 73 65 48 61 6e 64 6c 65 28 68 61 6e  (CloseHandle(han
1b30: 64 6c 65 29 20 3d 3d 20 46 41 4c 53 45 29 20 7b  dle) == FALSE) {
1b40: 0a 2b 09 09 09 72 65 74 75 72 6e 20 49 4e 56 41  .+...return INVA
1b50: 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 45  LID_HANDLE_VALUE
1b60: 3b 0a 2b 09 09 7d 0a 20 20 20 20 20 7d 0a 2b 09  ;.+..}.     }.+.
1b70: 0a 2b 09 20 2f 2a 0a 2b 09 2a 20 4d 75 6c 74 69  .+. /*.+.* Multi
1b80: 74 68 72 65 61 64 65 64 20 49 2f 4f 20 6e 65 65  threaded I/O nee
1b90: 64 73 20 74 68 65 20 6f 76 65 72 6c 61 70 70 65  ds the overlappe
1ba0: 64 20 66 6c 61 67 20 73 65 74 20 6f 74 68 65 72  d flag set other
1bb0: 77 69 73 65 0a 2b 09 2a 20 43 6c 65 61 72 43 6f  wise.+.* ClearCo
1bc0: 6d 6d 45 72 72 6f 72 20 62 6c 6f 63 6b 73 20 75  mmError blocks u
1bd0: 6e 64 65 72 20 57 69 6e 64 6f 77 73 20 4e 54 2f  nder Windows NT/
1be0: 32 30 30 30 20 75 6e 74 69 6c 20 73 65 72 69 61  2000 until seria
1bf0: 6c 20 6f 75 74 70 75 74 20 69 73 0a 2b 09 2a 20  l output is.+.* 
1c00: 66 69 6e 69 73 68 65 64 0a 2b 09 2a 2f 0a 2b 0a  finished.+.*/.+.
1c10: 20 20 20 20 20 68 61 6e 64 6c 65 20 3d 20 43 72       handle = Cr
1c20: 65 61 74 65 46 69 6c 65 28 6e 61 6d 65 2c 20 61  eateFile(name, a
1c30: 63 63 65 73 73 2c 20 30 2c 20 30 2c 20 4f 50 45  ccess, 0, 0, OPE
1c40: 4e 5f 45 58 49 53 54 49 4e 47 2c 0a 20 09 20 20  N_EXISTING,. .  
1c50: 20 20 46 49 4c 45 5f 46 4c 41 47 5f 4f 56 45 52    FILE_FLAG_OVER
1c60: 4c 41 50 50 45 44 2c 20 30 29 3b 0a 2d 20 20 20  LAPPED, 0);.-   
1c70: 20 72 65 74 75 72 6e 20 68 61 6e 64 6c 65 3b 0a   return handle;.
1c80: 2b 0a 2b 09 72 65 74 75 72 6e 20 68 61 6e 64 6c  +.+.return handl
1c90: 65 3b 0a 20 7d 0a 20 0c 0a 20 2f 2a 0a           e;. }. .. /*.