From f7e02c57c848c495a77975b927a0f4076bf4822c Mon Sep 17 00:00:00 2001
From: nijtmans <nijtmans>
Date: Mon, 21 Dec 2009 23:25:39 +0000
Subject: Various CYGWIN-related fixes. In the win32 configure script, CYGWIN
 is still not enabled yet, but at least it is a step in the right direction.

---
 ChangeLog                  | 26 ++++++++++++++--
 generic/rege_dfa.c         | 22 ++++++-------
 generic/tcl.h              |  8 ++++-
 generic/tclEnv.c           | 19 ++++++-----
 generic/tclFileName.c      | 19 ++++++++---
 generic/tclOOInt.h         |  3 +-
 generic/tclPathObj.c       | 18 +++++++++--
 generic/tclPlatDecls.h     |  8 ++---
 generic/tclPort.h          | 12 ++++++-
 generic/tclThreadStorage.c |  4 +--
 tests/env.test             | 16 +++++-----
 unix/Makefile.in           | 78 +++++++++++++++++++++++-----------------------
 unix/configure             | 17 +++++++++-
 unix/dltest/.cvsignore     |  1 +
 unix/tcl.m4                | 14 +++++++++
 win/tclWinDde.c            | 11 +++----
 win/tclWinFile.c           | 18 +++++------
 win/tclWinPipe.c           |  6 ++--
 win/tclWinPort.h           |  5 ++-
 win/tclWinSock.c           |  6 ++--
 20 files changed, 204 insertions(+), 107 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6da4eb7..7817c07 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2009-12-21  Jan Nijtmans  <nijtmans@users.sf.net>
+
+    * generic/tclThreadStorage.c: Fix gcc warning, using gcc-4.3.4 on cygwin
+                                  warning: missing initializer
+    * generic/tclOOInt.h:         prevent conflict with DUPLICATE
+                                  definition in WINAPI's nb30.h
+    * generic/rege_dfa.c:         Fix macro conflict on CYGWIN: don't use "small".
+    * generic/tcl.h               Include <winsock2.h> before <stdio.h> on CYGWIN
+    * generic/tclPathObj.c
+    * generic/tclPort.h
+    * tests/env.test:             Don't unset WINDIR and TERM, it has a special meaning
+                                  on CYGWIN (both in UNIX and WIN32 mode!)
+    * generic/tclPlatDecls.h:     Include <tchar.h> through tclPlatDecls.h
+    * win/tclWinPort.h            stricmp -> strcasecmp
+    * win/tclWinDde.c             _wcsicmp -> wcscasecmp
+    * win/tclWinFile.c
+    * win/tclWinPipe.c
+    * win/tclWinSock.c
+    * unix/tcl.m4                 Add dynamic loading support to CYGWIN
+    * unix/configure (regenerated)
+    * unix/Makefile.in
+
 2009-12-19  Miguel Sofer  <msofer@users.sf.net>
 
 	* generic/tclBasic.c:	Fix for bad cmd resolution by coroutines
@@ -13,7 +35,7 @@
 2009-12-11  Jan Nijtmans  <nijtmans@users.sf.net>
 
 	* generic/tclTest.c:	Fix gcc warning: ignoring return value of
-	* unix/tclUnixNotify.c:	‘write’, declared with attribute
+	* unix/tclUnixNotify.c:	"write", declared with attribute
 	* unix/tclUnixPipe.c:	warn_unused_result.
 	* generic/tclInt.decls:	CONSTify functions TclpGetUserHome and
 	* generic/tclIntDecls.h:TclSetPreInitScript (TIP #27)
@@ -39,7 +61,7 @@
 	* generic/tclBasic.c:	Release TclPopCallFrame() from its
 	* generic/tclExecute.c:	tailcall-management duties
 	* generic/tclNamesp.c:
-		
+
 	* generic/tclBasic.c:	Moving TclBCArgumentRelease call from
 	* generic/tclExecute.c:	TclNRTailcallObjCmd to TEBC, so that the
 	pairing of the Enter and Release calls is clearer.
diff --git a/generic/rege_dfa.c b/generic/rege_dfa.c
index fbeae20..e233680 100644
--- a/generic/rege_dfa.c
+++ b/generic/rege_dfa.c
@@ -318,32 +318,32 @@ newdfa(
     struct vars *v,
     struct cnfa *cnfa,
     struct colormap *cm,
-    struct smalldfa *small)	/* preallocated space, may be NULL */
+    struct smalldfa *sml)	/* preallocated space, may be NULL */
 {
     struct dfa *d;
     size_t nss = cnfa->nstates * 2;
     int wordsper = (cnfa->nstates + UBITS - 1) / UBITS;
-    struct smalldfa *smallwas = small;
+    struct smalldfa *smallwas = sml;
 
     assert(cnfa != NULL && cnfa->nstates != 0);
 
     if (nss <= FEWSTATES && cnfa->ncolors <= FEWCOLORS) {
 	assert(wordsper == 1);
-	if (small == NULL) {
-	    small = (struct smalldfa *) MALLOC(sizeof(struct smalldfa));
-	    if (small == NULL) {
+	if (sml == NULL) {
+	    sml = (struct smalldfa *) MALLOC(sizeof(struct smalldfa));
+	    if (sml == NULL) {
 		ERR(REG_ESPACE);
 		return NULL;
 	    }
 	}
-	d = &small->dfa;
-	d->ssets = small->ssets;
-	d->statesarea = small->statesarea;
+	d = &sml->dfa;
+	d->ssets = sml->ssets;
+	d->statesarea = sml->statesarea;
 	d->work = &d->statesarea[nss];
-	d->outsarea = small->outsarea;
-	d->incarea = small->incarea;
+	d->outsarea = sml->outsarea;
+	d->incarea = sml->incarea;
 	d->cptsmalloced = 0;
-	d->mallocarea = (smallwas == NULL) ? (char *)small : NULL;
+	d->mallocarea = (smallwas == NULL) ? (char *)sml : NULL;
     } else {
 	d = (struct dfa *)MALLOC(sizeof(struct dfa));
 	if (d == NULL) {
diff --git a/generic/tcl.h b/generic/tcl.h
index a13b897..fb4cbdc 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -14,7 +14,7 @@
  * See the file "license.terms" for information on usage and redistribution of
  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
- * RCS: @(#) $Id: tcl.h,v 1.293 2009/11/30 23:10:38 nijtmans Exp $
+ * RCS: @(#) $Id: tcl.h,v 1.294 2009/12/21 23:25:39 nijtmans Exp $
  */
 
 #ifndef _TCL
@@ -129,6 +129,12 @@ extern "C" {
 #define TCL_DECLARE_MUTEX(name)
 #endif
 
+#if defined(__CYGWIN__) && defined(__WIN32__)
+/* Cygwin/win32 needs winsock2.h to be included BEFORE stdio.h,
+ * otherwise there will be symbol conflicts with sys/types.h! */
+#   include <winsock2.h>
+#endif
+
 /*
  * Tcl's public routine Tcl_FSSeek() uses the values SEEK_SET, SEEK_CUR, and
  * SEEK_END, all #define'd by stdio.h .
diff --git a/generic/tclEnv.c b/generic/tclEnv.c
index ac47ee9..40650de 100644
--- a/generic/tclEnv.c
+++ b/generic/tclEnv.c
@@ -12,7 +12,7 @@
  * See the file "license.terms" for information on usage and redistribution of
  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
- * RCS: @(#) $Id: tclEnv.c,v 1.39 2009/01/04 22:55:12 ferrieux Exp $
+ * RCS: @(#) $Id: tclEnv.c,v 1.40 2009/12/21 23:25:40 nijtmans Exp $
  */
 
 #include "tclInt.h"
@@ -45,8 +45,13 @@ static char *		EnvTraceProc(ClientData clientData, Tcl_Interp *interp,
 static void		ReplaceString(const char *oldStr, char *newStr);
 MODULE_SCOPE void	TclSetEnv(const char *name, const char *value);
 MODULE_SCOPE void	TclUnsetEnv(const char *name);
-#if defined(__CYGWIN__) && defined(__WIN32__)
-static void		TclCygwinPutenv(const char *string);
+
+#if defined(__CYGWIN__)
+/* On Cygwin, the environment is imported from the Cygwin DLL. */
+     DLLIMPORT extern int cygwin_posix_to_win32_path_list_buf_size(char *value);
+     DLLIMPORT extern void cygwin_posix_to_win32_path_list(char *buf, char *value);
+#    define putenv TclCygwinPutenv
+static void		TclCygwinPutenv(char *string);
 #endif
 
 /*
@@ -394,7 +399,7 @@ TclUnsetEnv(
      * that no = should be included, and Windows requires it.
      */
 
-#ifdef WIN32
+#if defined(__WIN32__) || defined(__CYGWIN__)
     string = ckalloc((unsigned) length+2);
     memcpy(string, name, (size_t) length);
     string[length] = '=';
@@ -688,7 +693,7 @@ TclFinalizeEnvironment(void)
     }
 }
 
-#if defined(__CYGWIN__) && defined(__WIN32__)
+#if defined(__CYGWIN__)
 
 #include <windows.h>
 
@@ -701,7 +706,7 @@ TclFinalizeEnvironment(void)
 
 static void
 TclCygwinPutenv(
-    const char *str)
+    char *str)
 {
     char *name, *value;
 
@@ -780,7 +785,7 @@ TclCygwinPutenv(
 	SetEnvironmentVariable(name, buf);
     }
 }
-#endif /* __CYGWIN__ && __WIN32__ */
+#endif /* __CYGWIN__ */
 
 /*
  * Local Variables:
diff --git a/generic/tclFileName.c b/generic/tclFileName.c
index 1070c42..664ba94 100644
--- a/generic/tclFileName.c
+++ b/generic/tclFileName.c
@@ -10,7 +10,7 @@
  * See the file "license.terms" for information on usage and redistribution of
  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
- * RCS: @(#) $Id: tclFileName.c,v 1.98 2009/08/21 19:06:06 dgp Exp $
+ * RCS: @(#) $Id: tclFileName.c,v 1.99 2009/12/21 23:25:40 nijtmans Exp $
  */
 
 #include "tclInt.h"
@@ -1331,8 +1331,8 @@ Tcl_GlobObjCmd(
 
     if (dir == PATH_GENERAL) {
 	int pathlength;
-	char *last;
-	char *first = Tcl_GetStringFromObj(pathOrDir,&pathlength);
+	const char *last;
+	const char *first = Tcl_GetStringFromObj(pathOrDir,&pathlength);
 
 	/*
 	 * Find the last path separator in the path
@@ -1433,7 +1433,7 @@ Tcl_GlobObjCmd(
 
 	while (--length >= 0) {
 	    int len;
-	    char *str;
+	    const char *str;
 
 	    Tcl_ListObjIndex(interp, typePtr, length, &look);
 	    str = Tcl_GetStringFromObj(look, &len);
@@ -2445,7 +2445,6 @@ DoGlob(
 
 #if defined(__CYGWIN__) && defined(__WIN32__)
 	    {
-		extern int cygwin_conv_to_win32_path(const char *, char *);
 		char winbuf[MAX_PATH+1];
 
 		cygwin_conv_to_win32_path(Tcl_DStringValue(&append), winbuf);
@@ -2463,6 +2462,16 @@ DoGlob(
 		    Tcl_DStringAppend(&append, ".", 1);
 		}
 	    }
+#if defined(__CYGWIN__) && !defined(__WIN32__)
+	    DLLIMPORT extern int cygwin_conv_to_posix_path(const char *, char *);
+	    {
+		char winbuf[MAXPATHLEN+1];
+
+		cygwin_conv_to_posix_path(Tcl_DStringValue(&append), winbuf);
+		Tcl_DStringFree(&append);
+		Tcl_DStringAppend(&append, winbuf, -1);
+	    }
+#endif /* __CYGWIN__ && __WIN32__ */
 	    break;
 	}
 
diff --git a/generic/tclOOInt.h b/generic/tclOOInt.h
index 17db3f1..86bc9d3 100644
--- a/generic/tclOOInt.h
+++ b/generic/tclOOInt.h
@@ -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: tclOOInt.h,v 1.12 2009/07/12 14:51:30 dkf Exp $
+ * RCS: @(#) $Id: tclOOInt.h,v 1.13 2009/12/21 23:25:39 nijtmans Exp $
  */
 
 #ifndef TCL_OO_INTERNAL_H
@@ -589,6 +589,7 @@ MODULE_SCOPE int	TclOOUpcatchCmd(ClientData ignored,
  * but all arguments are used multiple times and so must have no side effects.
  */
 
+#undef DUPLICATE /* prevent possible conflict with definition in WINAPI nb30.h */
 #define DUPLICATE(target,source,type) \
     do { \
 	register unsigned len = sizeof(type) * ((target).num=(source).num);\
diff --git a/generic/tclPathObj.c b/generic/tclPathObj.c
index 6d36fe4..610c05e 100644
--- a/generic/tclPathObj.c
+++ b/generic/tclPathObj.c
@@ -10,7 +10,7 @@
  * See the file "license.terms" for information on usage and redistribution of
  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
- * RCS: @(#) $Id: tclPathObj.c,v 1.84 2009/10/27 20:31:08 dgp Exp $
+ * RCS: @(#) $Id: tclPathObj.c,v 1.85 2009/12/21 23:25:39 nijtmans Exp $
  */
 
 #include "tclInt.h"
@@ -2369,7 +2369,10 @@ SetFsPathFromAny(
     FsPath *fsPathPtr;
     Tcl_Obj *transPtr;
     char *name;
-    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&tclFsDataKey);
+#if defined(__CYGWIN__) && defined(__WIN32__)
+    int copied = 0;
+#endif
+     ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&tclFsDataKey);
 
     if (pathPtr->typePtr == &tclFsPathType) {
 	return TCL_OK;
@@ -2514,7 +2517,6 @@ SetFsPathFromAny(
 
 #if defined(__CYGWIN__) && defined(__WIN32__)
     {
-	extern int cygwin_conv_to_win32_path(const char *, char *);
 	char winbuf[MAX_PATH+1];
 
 	/*
@@ -2527,6 +2529,11 @@ SetFsPathFromAny(
 	if (len > 0) {
 	    cygwin_conv_to_win32_path(name, winbuf);
 	    TclWinNoBackslash(winbuf);
+	    if (Tcl_IsShared(transPtr)) {
+		copied = 1;
+		transPtr = Tcl_DuplicateObj(transPtr);
+		Tcl_IncrRefCount(transPtr);
+	    }
 	    Tcl_SetStringObj(transPtr, winbuf, -1);
 	}
     }
@@ -2557,6 +2564,11 @@ SetFsPathFromAny(
     SETPATHOBJ(pathPtr, fsPathPtr);
     PATHFLAGS(pathPtr) = 0;
     pathPtr->typePtr = &tclFsPathType;
+#if defined(__CYGWIN__) && defined(__WIN32__)
+    if (copied) {
+	Tcl_DecrRefCount(transPtr);
+    }
+#endif
 
     return TCL_OK;
 }
diff --git a/generic/tclPlatDecls.h b/generic/tclPlatDecls.h
index a868584..44358c2 100644
--- a/generic/tclPlatDecls.h
+++ b/generic/tclPlatDecls.h
@@ -6,7 +6,7 @@
  * Copyright (c) 1998-1999 by Scriptics Corporation.
  * All rights reserved.
  *
- * RCS: @(#) $Id: tclPlatDecls.h,v 1.33 2008/10/22 20:23:59 nijtmans Exp $
+ * RCS: @(#) $Id: tclPlatDecls.h,v 1.34 2009/12/21 23:25:40 nijtmans Exp $
  */
 
 #ifndef _TCLPLATDECLS
@@ -26,9 +26,7 @@
 /*
  *  Pull in the typedef of TCHAR for windows.
  */
-#if defined(__CYGWIN__)
-    typedef char TCHAR;
-#elif defined(__WIN32__) && !defined(_TCHAR_DEFINED)
+#if defined(__WIN32__) && !defined(_TCHAR_DEFINED)
 #   include <tchar.h>
 #   ifndef _TCHAR_DEFINED
 	/* Borland seems to forget to set this. */
@@ -39,6 +37,8 @@
 	/* MSVC++ misses this. */
 	typedef _TCHAR TCHAR;
 #   endif
+#elif defined(__CYGWIN__)
+    typedef char TCHAR;
 #endif
 
 /* !BEGIN!: Do not edit below this line. */
diff --git a/generic/tclPort.h b/generic/tclPort.h
index d145468..0b4eda9 100644
--- a/generic/tclPort.h
+++ b/generic/tclPort.h
@@ -10,7 +10,7 @@
  * See the file "license.terms" for information on usage and redistribution
  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
- * RCS: @(#) $Id: tclPort.h,v 1.16 2008/11/04 23:57:41 hobbs Exp $
+ * RCS: @(#) $Id: tclPort.h,v 1.17 2009/12/21 23:25:39 nijtmans Exp $
  */
 
 #ifndef _TCLPORT
@@ -27,6 +27,16 @@
 #   include "tclUnixPort.h"
 #endif
 
+#if defined(__CYGWIN__)
+#   define USE_PUTENV 1
+#   define USE_PUTENV_FOR_UNSET 1
+/* On Cygwin, the environment is imported from the Cygwin DLL. */
+    DLLIMPORT extern char **__cygwin_environ;
+    DLLIMPORT extern int cygwin_conv_to_win32_path(const char *, char *);
+#    define environ __cygwin_environ
+#    define timezone _timezone
+#endif
+
 #if !defined(LLONG_MIN)
 #   ifdef TCL_WIDE_INT_IS_LONG
 #      define LLONG_MIN LONG_MIN
diff --git a/generic/tclThreadStorage.c b/generic/tclThreadStorage.c
index 1a0a89d..ea2eeb1 100644
--- a/generic/tclThreadStorage.c
+++ b/generic/tclThreadStorage.c
@@ -10,7 +10,7 @@
  * See the file "license.terms" for information on usage and redistribution of
  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
- * RCS: @(#) $Id: tclThreadStorage.c,v 1.20 2009/03/16 00:43:09 mistachkin Exp $
+ * RCS: @(#) $Id: tclThreadStorage.c,v 1.21 2009/12/21 23:25:40 nijtmans Exp $
  */
 
 #include "tclInt.h"
@@ -43,7 +43,7 @@ static struct TSDMaster {
 				 * increasing value. */
     Tcl_Mutex mutex;		/* Protection for the rest of this structure,
 				 * which holds per-process data. */
-} tsdMaster = { NULL, 0 };
+} tsdMaster = { NULL, 0, NULL };
 
 /*
  * The type of the data held per thread in a system TSD.
diff --git a/tests/env.test b/tests/env.test
index 7d7e5fa..f5669d7 100644
--- a/tests/env.test
+++ b/tests/env.test
@@ -11,7 +11,7 @@
 # See the file "license.terms" for information on usage and redistribution of
 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
 #
-# RCS: @(#) $Id: env.test,v 1.31 2009/05/07 10:34:42 dkf Exp $
+# RCS: @(#) $Id: env.test,v 1.32 2009/12/21 23:25:40 nijtmans Exp $
 
 if {[lsearch [namespace children] ::tcltest] == -1} {
     package require tcltest 2
@@ -78,19 +78,19 @@ set printenvScript [makeFile {
     proc manglechar c {
 	return [format {\u%04x} [scan $c %c]]
     }
-	
+
     set names [lsort [array names env]]
     if {$tcl_platform(platform) eq "windows"} {
 	lrem names HOME
         lrem names COMSPEC
 	lrem names ComSpec
 	lrem names ""
-    }	
+    }
     foreach name {
 	TCL_LIBRARY PATH LD_LIBRARY_PATH LIBPATH PURE_PROG_NAME DISPLAY
 	SHLIB_PATH SYSTEMDRIVE SYSTEMROOT DYLD_LIBRARY_PATH DYLD_FRAMEWORK_PATH
 	DYLD_NEW_LOCAL_SHARED_REGIONS DYLD_NO_FIX_PREBINDING
-	__CF_USER_TEXT_ENCODING SECURITYSESSIONID LANG
+	__CF_USER_TEXT_ENCODING SECURITYSESSIONID LANG WINDIR TERM
     } {
 	lrem names $name
     }
@@ -120,7 +120,7 @@ foreach name [array names env] {
 	TCL_LIBRARY PATH LD_LIBRARY_PATH LIBPATH DISPLAY SHLIB_PATH
 	SYSTEMDRIVE SYSTEMROOT DYLD_LIBRARY_PATH DYLD_FRAMEWORK_PATH
 	DYLD_NEW_LOCAL_SHARED_REGIONS DYLD_NO_FIX_PREBINDING
-	SECURITYSESSIONID LANG
+	SECURITYSESSIONID LANG WINDIR TERM
     }} {
 	unset env($name)
     }
@@ -241,7 +241,7 @@ test env-5.1 {corner cases - remove one elem at a time} -setup {
     array set env $x
 } -result {0}
 test env-5.2 {corner cases - unset the env array} -setup {
-    interp create i 
+    interp create i
 } -body {
     # Unsetting a variable in an interp detaches the C-level traces from the
     # Tcl "env" variable.
@@ -254,7 +254,7 @@ test env-5.2 {corner cases - unset the env array} -setup {
     interp delete i
 } -result {0}
 test env-5.3 {corner cases: unset the env in master should unset child} -setup {
-    interp create i 
+    interp create i
 } -body {
     # Variables deleted in a master interp should be deleted in child interp
     # too.
@@ -266,7 +266,7 @@ test env-5.3 {corner cases: unset the env in master should unset child} -setup {
     interp delete i
 } -result {a 1}
 test env-5.4 {corner cases - unset the env array} -setup {
-    interp create i 
+    interp create i
 } -body {
     # The info exists command should be in synch with the env array.
     # Know Bug: 1737
diff --git a/unix/Makefile.in b/unix/Makefile.in
index f65a2d3..146da43 100644
--- a/unix/Makefile.in
+++ b/unix/Makefile.in
@@ -4,7 +4,7 @@
 # "./configure", which is a configuration script generated by the "autoconf"
 # program (constructs like "@foo@" will get replaced in the actual Makefile.
 #
-# RCS: @(#) $Id: Makefile.in,v 1.285 2009/12/17 16:28:21 dgp Exp $
+# RCS: @(#) $Id: Makefile.in,v 1.286 2009/12/21 23:25:40 nijtmans Exp $
 
 VERSION 		= @TCL_VERSION@
 MAJOR_VERSION		= @TCL_MAJOR_VERSION@
@@ -164,7 +164,8 @@ INSTALL_DATA		= ${INSTALL} -m 644
 # make for the first time. Certain build targets (make genstubs) need it to be
 # available on the PATH. This executable should *NOT* be required just to do a
 # normal build although it can be required to run make dist.
-TCL_EXE			= tclsh
+EXE_SUFFIX		= @EXE_SUFFIX@
+TCL_EXE			= tclsh${EXE_SUFFIX}
 
 # The symbols below provide support for dynamic loading and shared libraries.
 # See configure.in for a description of what the symbols mean. The values of
@@ -178,7 +179,6 @@ SHLIB_LD_LIBS		= @SHLIB_LD_LIBS@
 TCL_SHLIB_LD_EXTRAS	= @TCL_SHLIB_LD_EXTRAS@
 
 SHLIB_SUFFIX		= @SHLIB_SUFFIX@
-#SHLIB_SUFFIX		=
 
 DLTEST_TARGETS		= dltest.marker
 
@@ -588,7 +588,7 @@ SRCS = $(GENERIC_SRCS) $(TOMMATH_SRCS) $(UNIX_SRCS) $(NOTIFY_SRCS) \
 
 all: binaries libraries doc packages
 
-binaries: ${LIB_FILE} $(STUB_LIB_FILE) $(TCL_BUILD_EXP_FILE) tclsh
+binaries: ${LIB_FILE} $(STUB_LIB_FILE) $(TCL_BUILD_EXP_FILE) ${TCL_EXE}
 
 libraries:
 
@@ -614,9 +614,9 @@ tclLibObjs:
 # This targets actually build the objects needed for the lib in the above case
 objs: ${OBJS}
 
-tclsh: ${TCLSH_OBJS} ${TCL_LIB_FILE}
+${TCL_EXE}: ${TCLSH_OBJS} ${TCL_LIB_FILE}
 	${CC} ${CFLAGS} ${LDFLAGS} ${TCLSH_OBJS} @TCL_BUILD_LIB_SPEC@ ${LIBS} @EXTRA_TCLSH_LIBS@ \
-		${CC_SEARCH_FLAGS} -o tclsh
+		${CC_SEARCH_FLAGS} -o ${TCL_EXE}
 
 Makefile: $(UNIX_DIR)/Makefile.in $(DLTEST_DIR)/Makefile.in
 	$(SHELL) config.status
@@ -625,7 +625,7 @@ Makefile: $(UNIX_DIR)/Makefile.in $(DLTEST_DIR)/Makefile.in
 
 clean: clean-packages
 	rm -f *.a *.o libtcl* core errs *~ \#* TAGS *.E a.out \
-		errors tclsh tcltest lib.exp Tcl @DTRACE_HDR@
+		errors ${TCL_EXE} tcltest${EXE_SUFFIX} lib.exp Tcl @DTRACE_HDR@
 	cd dltest ; $(MAKE) clean
 
 distclean: distclean-packages clean
@@ -660,12 +660,12 @@ SHELL_ENV =	@LD_LIBRARY_PATH_VAR@=`pwd`:${@LD_LIBRARY_PATH_VAR@} \
 		TCLLIBPATH="@abs_builddir@/pkgs" \
 		TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"
 
-tcltest: ${TCLTEST_OBJS} ${TCL_LIB_FILE} ${TCL_STUB_LIB_FILE} ${BUILD_DLTEST}
+tcltest${EXE_SUFFIX}: ${TCLTEST_OBJS} ${TCL_LIB_FILE} ${TCL_STUB_LIB_FILE} ${BUILD_DLTEST}
 	$(MAKE) tcltest-real LIB_RUNTIME_DIR="`pwd`"
 
 tcltest-real:
 	${CC} ${CFLAGS} ${LDFLAGS} ${TCLTEST_OBJS} @TCL_BUILD_LIB_SPEC@ ${TCL_STUB_LIB_FILE} ${LIBS} @EXTRA_TCLSH_LIBS@ \
-		${CC_SEARCH_FLAGS} -o tcltest
+		${CC_SEARCH_FLAGS} -o tcltest${EXE_SUFFIX}
 
 # Note, in the targets below TCL_LIBRARY needs to be set or else "make test"
 # won't work in the case where the compilation directory isn't the same as the
@@ -677,24 +677,24 @@ tcltest-real:
 
 test: test-tcl test-packages
 
-test-tcl: tcltest
-	$(SHELL_ENV) ./tcltest $(TOP_DIR)/tests/all.tcl $(TESTFLAGS)
+test-tcl: tcltest${EXE_SUFFIX}
+	$(SHELL_ENV) ./tcltest${EXE_SUFFIX} $(TOP_DIR)/tests/all.tcl $(TESTFLAGS)
 
-gdb-test: tcltest
+gdb-test: tcltest${EXE_SUFFIX}
 	@echo "set env @LD_LIBRARY_PATH_VAR@=\"`pwd`:$${@LD_LIBRARY_PATH_VAR@}\"" > gdb.run
 	@echo "set env TCL_LIBRARY=${TCL_BUILDTIME_LIBRARY}" >> gdb.run
 	@echo "set args $(TOP_DIR)/tests/all.tcl $(TESTFLAGS) -singleproc 1" >> gdb.run
-	$(GDB) ./tcltest --command=gdb.run
+	$(GDB) ./tcltest${EXE_SUFFIX} --command=gdb.run
 	rm gdb.run
 
 # Useful target to launch a built tcltest with the proper path,...
-runtest: tcltest
-	$(SHELL_ENV) ./tcltest
+runtest: tcltest${EXE_SUFFIX}
+	$(SHELL_ENV) ./tcltest${EXE_SUFFIX}
 
 # Useful target for running the test suite with an unwritable current
 # directory...
-ro-test: tcltest
-	echo 'exec chmod -w .;package require tcltest;tcltest::temporaryDirectory /tmp;source ../tests/all.tcl;exec chmod +w .' | $(SHELL_ENV) ./tcltest
+ro-test: tcltest${EXE_SUFFIX}
+	echo 'exec chmod -w .;package require tcltest;tcltest::temporaryDirectory /tmp;source ../tests/all.tcl;exec chmod +w .' | $(SHELL_ENV) ./tcltest${EXE_SUFFIX}
 
 # The following target generates the shared libraries in dltest/ that are used
 # for testing; they are included as part of the "tcltest" target (via the
@@ -711,24 +711,24 @@ dltest.marker: ${STUB_LIB_FILE}
 
 # This target can be used to run tclsh from the build directory
 # via `make shell SCRIPT=/tmp/foo.tcl`
-shell: tclsh
-	$(SHELL_ENV) ./tclsh $(SCRIPT)
+shell: ${TCL_EXE}
+	$(SHELL_ENV) ./${TCL_EXE} $(SCRIPT)
 
 # This target can be used to run tclsh inside either gdb or insight
-gdb: tclsh
-	$(SHELL_ENV) $(GDB) ./tclsh
+gdb: ${TCL_EXE}
+	$(SHELL_ENV) $(GDB) ./${TCL_EXE}
 
 # This target can be used to run tclsh inside ddd
-ddd: tclsh
-	$(SHELL_ENV) $(DDD) ./tclsh
+ddd: ${TCL_EXE}
+	$(SHELL_ENV) $(DDD) ./${TCL_EXE}
 
 VALGRINDARGS=--tool=memcheck --num-callers=8 --leak-resolution=high --leak-check=yes --show-reachable=yes -v
 
-valgrind: tclsh tcltest
-	$(SHELL_ENV) valgrind $(VALGRINDARGS) ./tcltest $(TOP_DIR)/tests/all.tcl -singleproc 1 $(TESTFLAGS)
+valgrind: ${TCL_EXE} tcltest${EXE_SUFFIX}
+	$(SHELL_ENV) valgrind $(VALGRINDARGS) ./tcltest${EXE_SUFFIX} $(TOP_DIR)/tests/all.tcl -singleproc 1 $(TESTFLAGS)
 
-valgrindshell: tclsh
-	$(SHELL_ENV) valgrind $(VALGRINDARGS) ./tclsh $(SCRIPT)
+valgrindshell: ${TCL_EXE}
+	$(SHELL_ENV) valgrind $(VALGRINDARGS) ./${TCL_EXE} $(SCRIPT)
 
 #--------------------------------------------------------------------------
 # Installation rules
@@ -770,7 +770,7 @@ install-binaries: binaries
 			"$(LIB_INSTALL_DIR)"/$(TCL_EXP_FILE); \
 	    fi
 	@echo "Installing tclsh as $(BIN_INSTALL_DIR)/tclsh$(VERSION)"
-	@$(INSTALL_PROGRAM) tclsh "$(BIN_INSTALL_DIR)"/tclsh$(VERSION)
+	@$(INSTALL_PROGRAM) ${TCL_EXE} "$(BIN_INSTALL_DIR)"/tclsh$(VERSION)${EXE_SUFFIX}
 	@echo "Installing tclConfig.sh to $(CONFIG_INSTALL_DIR)/"
 	@$(INSTALL_DATA) tclConfig.sh "$(CONFIG_INSTALL_DIR)"/tclConfig.sh
 	@echo "Installing tclooConfig.sh to $(CONFIG_INSTALL_DIR)/"
@@ -854,18 +854,18 @@ install-libraries: libraries $(INSTALL_TZDATA) install-msgs
 	        "$(SCRIPT_INSTALL_DIR)"/tm.tcl; \
 	fi
 
-install-tzdata: tclsh
+install-tzdata: ${TCL_EXE}
 	@echo "Installing time zone data"
 	@@LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \
 	TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \
-	./tclsh $(TOOL_DIR)/installData.tcl \
+	./${TCL_EXE} $(TOOL_DIR)/installData.tcl \
 	    $(TOP_DIR)/library/tzdata "$(SCRIPT_INSTALL_DIR)"/tzdata
 
-install-msgs: tclsh
+install-msgs: ${TCL_EXE}
 	@echo "Installing message catalogs"
 	@@LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \
 	TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \
-	./tclsh $(TOOL_DIR)/installData.tcl \
+	./${TCL_EXE} $(TOOL_DIR)/installData.tcl \
 	    $(TOP_DIR)/library/msgs "$(SCRIPT_INSTALL_DIR)"/msgs
 
 install-doc: doc
@@ -932,7 +932,7 @@ install-private-headers: libraries
 # tclAppInit.o does not execute concurrently with the renaming and recompiling
 # of that same object file in the targets below.
 
-tclTestInit.o: $(UNIX_DIR)/tclAppInit.c tclsh
+tclTestInit.o: $(UNIX_DIR)/tclAppInit.c ${TCL_EXE}
 	@if test -f tclAppInit.o ; then \
 	    rm -f tclAppInit.sav; \
 	    mv tclAppInit.o tclAppInit.sav; \
@@ -946,7 +946,7 @@ tclTestInit.o: $(UNIX_DIR)/tclAppInit.c tclsh
 	    mv tclAppInit.sav tclAppInit.o; \
 	fi;
 
-xtTestInit.o: $(UNIX_DIR)/tclAppInit.c tclsh
+xtTestInit.o: $(UNIX_DIR)/tclAppInit.c ${TCL_EXE}
 	@if test -f tclAppInit.o ; then \
 	    rm -f tclAppInit.sav; \
 	    mv tclAppInit.o tclAppInit.sav; \
@@ -1674,7 +1674,7 @@ test-packages: tcltest packages
 		  "@LD_LIBRARY_PATH_VAR@=../..:$${@LD_LIBRARY_PATH_VAR@}" \
 		  "TCL_LIBRARY=${TCL_BUILDTIME_LIBRARY}" \
 		  "TCLLIBPATH=../../pkgs" test \
-		  "TCLSH_PROG=../../tcltest"; ) \
+		  "TCLSH_PROG=../../tcltest${EXE_SUFFIX}"; ) \
 	    fi; \
 	  fi; \
 	done
@@ -2011,20 +2011,20 @@ allpatch: dist
 # to function on those of the Tcl/Tk maintainers.
 #--------------------------------------------------------------------------
 
-html: tclsh
+html: ${TCL_EXE}
 	$(BUILD_HTML)
 	@EXTRA_BUILD_HTML@
-html-tcl: tclsh
+html-tcl: ${TCL_EXE}
 	$(BUILD_HTML) --tcl
 	@EXTRA_BUILD_HTML@
-html-tk: tclsh
+html-tk: ${TCL_EXE}
 	$(BUILD_HTML) --tk
 	@EXTRA_BUILD_HTML@
 
 BUILD_HTML = \
 	@@LD_LIBRARY_PATH_VAR@="`pwd`:$${@LD_LIBRARY_PATH_VAR@}"; export @LD_LIBRARY_PATH_VAR@; \
 	TCL_LIBRARY="${TCL_BUILDTIME_LIBRARY}"; export TCL_LIBRARY; \
-	./tclsh $(TOOL_DIR)/tcltk-man2html.tcl --htmldir="$(HTML_INSTALL_DIR)" \
+	./${TCL_EXE} $(TOOL_DIR)/tcltk-man2html.tcl --htmldir="$(HTML_INSTALL_DIR)" \
 		--srcdir=$(TOP_DIR)/.. $(BUILD_HTML_FLAGS)
 
 #--------------------------------------------------------------------------
diff --git a/unix/configure b/unix/configure
index 991879c..65fcfee 100755
--- a/unix/configure
+++ b/unix/configure
@@ -308,7 +308,7 @@ ac_includes_default="\
 # include <unistd.h>
 #endif"
 
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS MAN_FLAGS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP TCL_THREADS ZLIB_DIR ZLIB_OBJS ZLIB_SRCS ZLIB_INCLUDE RANLIB ac_ct_RANLIB AR LIBOBJS TCL_LIBS DL_LIBS DL_OBJS PLAT_OBJS PLAT_SRCS LDAIX_SRC CFLAGS_DEBUG CFLAGS_OPTIMIZE CFLAGS_WARNING LDFLAGS_DEBUG LDFLAGS_OPTIMIZE CC_SEARCH_FLAGS LD_SEARCH_FLAGS STLIB_LD SHLIB_LD TCL_SHLIB_LD_EXTRAS TK_SHLIB_LD_EXTRAS SHLIB_LD_LIBS SHLIB_CFLAGS SHLIB_SUFFIX MAKE_LIB MAKE_STUB_LIB INSTALL_LIB INSTALL_STUB_LIB CFLAGS_DEFAULT LDFLAGS_DEFAULT DTRACE TCL_VERSION TCL_MAJOR_VERSION TCL_MINOR_VERSION TCL_PATCH_LEVEL TCL_YEAR PKG_CFG_ARGS TCL_LIB_FILE TCL_LIB_FLAG TCL_LIB_SPEC TCL_STUB_LIB_FILE TCL_STUB_LIB_FLAG TCL_STUB_LIB_SPEC TCL_STUB_LIB_PATH TCL_INCLUDE_SPEC TCL_BUILD_STUB_LIB_SPEC TCL_BUILD_STUB_LIB_PATH TCL_SRC_DIR CFG_TCL_SHARED_LIB_SUFFIX CFG_TCL_UNSHARED_LIB_SUFFIX CFG_TCL_EXPORT_FILE_SUFFIX TCL_SHARED_BUILD LD_LIBRARY_PATH_VAR TCL_BUILD_LIB_SPEC TCL_NEEDS_EXP_FILE TCL_BUILD_EXP_FILE TCL_EXP_FILE TCL_LIB_VERSIONS_OK TCL_SHARED_LIB_SUFFIX TCL_UNSHARED_LIB_SUFFIX TCL_HAS_LONGLONG INSTALL_TZDATA DTRACE_SRC DTRACE_HDR DTRACE_OBJ MAKEFILE_SHELL BUILD_DLTEST TCL_PACKAGE_PATH TCL_MODULE_PATH TCL_LIBRARY PRIVATE_INCLUDE_DIR HTML_DIR PACKAGE_DIR EXTRA_CC_SWITCHES EXTRA_APP_CC_SWITCHES EXTRA_INSTALL EXTRA_INSTALL_BINARIES EXTRA_BUILD_HTML EXTRA_TCLSH_LIBS DLTEST_LD DLTEST_SUFFIX'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS MAN_FLAGS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP TCL_THREADS ZLIB_DIR ZLIB_OBJS ZLIB_SRCS ZLIB_INCLUDE RANLIB ac_ct_RANLIB AR LIBOBJS TCL_LIBS DL_LIBS DL_OBJS PLAT_OBJS PLAT_SRCS LDAIX_SRC CFLAGS_DEBUG CFLAGS_OPTIMIZE CFLAGS_WARNING LDFLAGS_DEBUG LDFLAGS_OPTIMIZE CC_SEARCH_FLAGS LD_SEARCH_FLAGS STLIB_LD SHLIB_LD TCL_SHLIB_LD_EXTRAS TK_SHLIB_LD_EXTRAS SHLIB_LD_LIBS SHLIB_CFLAGS SHLIB_SUFFIX EXE_SUFFIX MAKE_LIB MAKE_STUB_LIB INSTALL_LIB INSTALL_STUB_LIB CFLAGS_DEFAULT LDFLAGS_DEFAULT DTRACE TCL_VERSION TCL_MAJOR_VERSION TCL_MINOR_VERSION TCL_PATCH_LEVEL TCL_YEAR PKG_CFG_ARGS TCL_LIB_FILE TCL_LIB_FLAG TCL_LIB_SPEC TCL_STUB_LIB_FILE TCL_STUB_LIB_FLAG TCL_STUB_LIB_SPEC TCL_STUB_LIB_PATH TCL_INCLUDE_SPEC TCL_BUILD_STUB_LIB_SPEC TCL_BUILD_STUB_LIB_PATH TCL_SRC_DIR CFG_TCL_SHARED_LIB_SUFFIX CFG_TCL_UNSHARED_LIB_SUFFIX CFG_TCL_EXPORT_FILE_SUFFIX TCL_SHARED_BUILD LD_LIBRARY_PATH_VAR TCL_BUILD_LIB_SPEC TCL_NEEDS_EXP_FILE TCL_BUILD_EXP_FILE TCL_EXP_FILE TCL_LIB_VERSIONS_OK TCL_SHARED_LIB_SUFFIX TCL_UNSHARED_LIB_SUFFIX TCL_HAS_LONGLONG INSTALL_TZDATA DTRACE_SRC DTRACE_HDR DTRACE_OBJ MAKEFILE_SHELL BUILD_DLTEST TCL_PACKAGE_PATH TCL_MODULE_PATH TCL_LIBRARY PRIVATE_INCLUDE_DIR HTML_DIR PACKAGE_DIR EXTRA_CC_SWITCHES EXTRA_APP_CC_SWITCHES EXTRA_INSTALL EXTRA_INSTALL_BINARIES EXTRA_BUILD_HTML EXTRA_TCLSH_LIBS DLTEST_LD DLTEST_SUFFIX'
 ac_subst_files=''
 
 # Initialize some variables set by options.
@@ -6624,6 +6624,7 @@ fi
     # Step 3: set configuration options based on system name and version.
 
     do64bit_ok=no
+    EXE_SUFFIX=""
     LDFLAGS_ORIG="$LDFLAGS"
     # When ld needs options to work in 64-bit mode, put them in
     # LDFLAGS_ARCH so they eventually end up in LDFLAGS even if [load]
@@ -7006,6 +7007,17 @@ fi
 	    CC_SEARCH_FLAGS=""
 	    LD_SEARCH_FLAGS=""
 	    ;;
+	CYGWIN_*)
+	    SHLIB_CFLAGS=""
+	    SHLIB_LD='${CC} -shared'
+	    SHLIB_LD_LIBS='${LIBS}'
+	    SHLIB_SUFFIX=".dll"
+	    EXE_SUFFIX=".exe"
+	    DL_OBJS="tclLoadDl.o"
+	    DL_LIBS="-ldl"
+	    CC_SEARCH_FLAGS=""
+	    LD_SEARCH_FLAGS=""
+	    ;;
 	dgux*)
 	    SHLIB_CFLAGS="-K PIC"
 	    SHLIB_LD='${CC} -G'
@@ -8939,6 +8951,7 @@ fi
 	case $system in
 	    AIX-*) ;;
 	    BSD/OS*) ;;
+	    CYGWIN_*) ;;
 	    IRIX*) ;;
 	    NetBSD-*|FreeBSD-*) ;;
 	    Darwin-*) ;;
@@ -9037,6 +9050,7 @@ fi
 
 
 
+
 cat >>confdefs.h <<_ACEOF
 #define TCL_SHLIB_EXT "${SHLIB_SUFFIX}"
 _ACEOF
@@ -19512,6 +19526,7 @@ s,@TK_SHLIB_LD_EXTRAS@,$TK_SHLIB_LD_EXTRAS,;t t
 s,@SHLIB_LD_LIBS@,$SHLIB_LD_LIBS,;t t
 s,@SHLIB_CFLAGS@,$SHLIB_CFLAGS,;t t
 s,@SHLIB_SUFFIX@,$SHLIB_SUFFIX,;t t
+s,@EXE_SUFFIX@,$EXE_SUFFIX,;t t
 s,@MAKE_LIB@,$MAKE_LIB,;t t
 s,@MAKE_STUB_LIB@,$MAKE_STUB_LIB,;t t
 s,@INSTALL_LIB@,$INSTALL_LIB,;t t
diff --git a/unix/dltest/.cvsignore b/unix/dltest/.cvsignore
index 77ae092..5325f6e 100644
--- a/unix/dltest/.cvsignore
+++ b/unix/dltest/.cvsignore
@@ -1,3 +1,4 @@
 Makefile
 *.bundle
 *.dylib
+*.dll
diff --git a/unix/tcl.m4 b/unix/tcl.m4
index 6c23ace..0920e9b 100644
--- a/unix/tcl.m4
+++ b/unix/tcl.m4
@@ -1090,6 +1090,7 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [
     # Step 3: set configuration options based on system name and version.
 
     do64bit_ok=no
+    EXE_SUFFIX=""
     LDFLAGS_ORIG="$LDFLAGS"
     # When ld needs options to work in 64-bit mode, put them in
     # LDFLAGS_ARCH so they eventually end up in LDFLAGS even if [load]
@@ -1246,6 +1247,17 @@ dnl AC_CHECK_TOOL(AR, ar)
 	    CC_SEARCH_FLAGS=""
 	    LD_SEARCH_FLAGS=""
 	    ;;
+	CYGWIN_*)
+	    SHLIB_CFLAGS=""
+	    SHLIB_LD='${CC} -shared'
+	    SHLIB_LD_LIBS='${LIBS}'
+	    SHLIB_SUFFIX=".dll"
+	    EXE_SUFFIX=".exe"
+	    DL_OBJS="tclLoadDl.o"
+	    DL_LIBS="-ldl"
+	    CC_SEARCH_FLAGS=""
+	    LD_SEARCH_FLAGS=""
+	    ;;
 	dgux*)
 	    SHLIB_CFLAGS="-K PIC"
 	    SHLIB_LD='${CC} -G'
@@ -2046,6 +2058,7 @@ dnl # preprocessing tests use only CPPFLAGS.
 	case $system in
 	    AIX-*) ;;
 	    BSD/OS*) ;;
+	    CYGWIN_*) ;;
 	    IRIX*) ;;
 	    NetBSD-*|FreeBSD-*) ;;
 	    Darwin-*) ;;
@@ -2117,6 +2130,7 @@ dnl # preprocessing tests use only CPPFLAGS.
     AC_SUBST(SHLIB_LD_LIBS)
     AC_SUBST(SHLIB_CFLAGS)
     AC_SUBST(SHLIB_SUFFIX)
+    AC_SUBST(EXE_SUFFIX)
     AC_DEFINE_UNQUOTED(TCL_SHLIB_EXT,"${SHLIB_SUFFIX}",
 	[What is the default extension for shared libraries?])
 
diff --git a/win/tclWinDde.c b/win/tclWinDde.c
index 742ff05..4f94e76 100644
--- a/win/tclWinDde.c
+++ b/win/tclWinDde.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: tclWinDde.c,v 1.38 2009/11/23 20:17:36 nijtmans Exp $
+ * RCS: @(#) $Id: tclWinDde.c,v 1.39 2009/12/21 23:25:41 nijtmans Exp $
  */
 
 #undef STATIC_BUILD
@@ -19,7 +19,6 @@
 #include "tclInt.h"
 #include <dde.h>
 #include <ddeml.h>
-#include <tchar.h>
 
 /*
  * TCL_STORAGE_CLASS is set unconditionally to DLLEXPORT because the Dde_Init
@@ -634,7 +633,7 @@ DdeServerProc(
 
 	for (riPtr = tsdPtr->interpListPtr; riPtr != NULL;
 		riPtr = riPtr->nextPtr) {
-	    if (stricmp(utilString, riPtr->name) == 0) {
+	    if (strcasecmp(utilString, riPtr->name) == 0) {
 		Tcl_DStringFree(&dString);
 		return (HDDEDATA) TRUE;
 	    }
@@ -658,7 +657,7 @@ DdeServerProc(
 		CP_WINANSI);
 	for (riPtr = tsdPtr->interpListPtr; riPtr != NULL;
 		riPtr = riPtr->nextPtr) {
-	    if (stricmp(riPtr->name, utilString) == 0) {
+	    if (strcasecmp(riPtr->name, utilString) == 0) {
 		convPtr = (Conversation *) ckalloc(sizeof(Conversation));
 		convPtr->nextPtr = tsdPtr->currentConversations;
 		convPtr->returnPackagePtr = NULL;
@@ -723,7 +722,7 @@ DdeServerProc(
 	    utilString = Tcl_DStringValue(&dString);
 	    DdeQueryString(ddeInstance, ddeItem, utilString, (DWORD) len + 1,
 		    CP_WINANSI);
-	    if (stricmp(utilString, TCL_DDE_EXECUTE_RESULT) == 0) {
+	    if (strcasecmp(utilString, TCL_DDE_EXECUTE_RESULT) == 0) {
 		returnString =
 			Tcl_GetStringFromObj(convPtr->returnPackagePtr, &len);
 		ddeReturn = DdeCreateDataHandle(ddeInstance, (LPBYTE)returnString,
@@ -1504,7 +1503,7 @@ DdeObjCmd(
 
 	for (riPtr = tsdPtr->interpListPtr; riPtr != NULL;
 		riPtr = riPtr->nextPtr) {
-	    if (stricmp(serviceName, riPtr->name) == 0) {
+	    if (strcasecmp(serviceName, riPtr->name) == 0) {
 		break;
 	    }
 	}
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index 23fea2b..c9d6e28 100644
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.c
@@ -11,7 +11,7 @@
  * See the file "license.terms" for information on usage and redistribution of
  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
- * RCS: @(#) $Id: tclWinFile.c,v 1.100 2009/12/16 23:26:02 nijtmans Exp $
+ * RCS: @(#) $Id: tclWinFile.c,v 1.101 2009/12/21 23:25:40 nijtmans Exp $
  */
 
 /* #define _WIN32_WINNT	0x0500 */
@@ -1264,8 +1264,8 @@ WinIsReserved(
 	    }
 	}
 
-    } else if (!stricmp(path, "prn") || !stricmp(path, "nul")
-	    || !stricmp(path, "aux")) {
+    } else if (!strcasecmp(path, "prn") || !strcasecmp(path, "nul")
+	    || !strcasecmp(path, "aux")) {
 	/*
 	 * Have match for 'prn', 'nul' or 'aux'.
 	 */
@@ -1787,9 +1787,9 @@ NativeIsExec(
 	 * Use wide-char case-insensitive comparison
 	 */
 
-	if ((_wcsicmp(path+len-3, L"exe") == 0)
-		|| (_wcsicmp(path+len-3, L"com") == 0)
-		|| (_wcsicmp(path+len-3, L"bat") == 0)) {
+	if ((wcscasecmp(path+len-3, L"exe") == 0)
+		|| (wcscasecmp(path+len-3, L"com") == 0)
+		|| (wcscasecmp(path+len-3, L"bat") == 0)) {
 	    return 1;
 	}
     } else {
@@ -1808,9 +1808,9 @@ NativeIsExec(
 	     * executable, whereas access did not.
 	     */
 
-	    if ((stricmp(p, "exe") == 0)
-		    || (stricmp(p, "com") == 0)
-		    || (stricmp(p, "bat") == 0)) {
+	    if ((strcasecmp(p, "exe") == 0)
+		    || (strcasecmp(p, "com") == 0)
+		    || (strcasecmp(p, "bat") == 0)) {
 		/*
 		 * File that ends with .exe, .com, or .bat is executable.
 		 */
diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c
index b1dd26f..1306e1c 100644
--- a/win/tclWinPipe.c
+++ b/win/tclWinPipe.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: tclWinPipe.c,v 1.70 2009/02/03 23:10:58 nijtmans Exp $
+ * RCS: @(#) $Id: tclWinPipe.c,v 1.71 2009/12/21 23:25:41 nijtmans Exp $
  */
 
 #include "tclWinInt.h"
@@ -1423,7 +1423,7 @@ ApplicationType(
 	Tcl_DStringFree(&ds);
 
 	ext = strrchr(fullName, '.');
-	if ((ext != NULL) && (stricmp(ext, ".bat") == 0)) {
+	if ((ext != NULL) && (strcasecmp(ext, ".bat") == 0)) {
 	    applType = APPL_DOS;
 	    break;
 	}
@@ -1447,7 +1447,7 @@ ApplicationType(
 	     */
 
 	    CloseHandle(hFile);
-	    if ((ext != NULL) && (stricmp(ext, ".com") == 0)) {
+	    if ((ext != NULL) && (strcasecmp(ext, ".com") == 0)) {
 		applType = APPL_DOS;
 		break;
 	    }
diff --git a/win/tclWinPort.h b/win/tclWinPort.h
index 93eca70..01e5432 100644
--- a/win/tclWinPort.h
+++ b/win/tclWinPort.h
@@ -10,7 +10,7 @@
  * See the file "license.terms" for information on usage and redistribution
  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
- * RCS: @(#) $Id: tclWinPort.h,v 1.51 2009/07/22 19:54:49 nijtmans Exp $
+ * RCS: @(#) $Id: tclWinPort.h,v 1.52 2009/12/21 23:25:41 nijtmans Exp $
  */
 
 #ifndef _TCLWINPORT
@@ -48,8 +48,11 @@
  * These string functions are not defined with the same names on Windows.
  */
 
+#ifndef __CYGWIN__
+#define wcscasecmp _wcsicmp
 #define strcasecmp stricmp
 #define strncasecmp strnicmp
+#endif
 
 /*
  * Need to block out these includes for building extensions with MetroWerks
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index b03bf48..c843260 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -8,7 +8,7 @@
  * See the file "license.terms" for information on usage and redistribution of
  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
- * RCS: @(#) $Id: tclWinSock.c,v 1.66 2009/01/27 00:02:08 ferrieux Exp $
+ * RCS: @(#) $Id: tclWinSock.c,v 1.67 2009/12/21 23:25:41 nijtmans Exp $
  */
 
 #include "tclWinInt.h"
@@ -1821,7 +1821,7 @@ TcpSetOptionProc(
     sock = infoPtr->socket;
 
 #ifdef TCL_FEATURE_KEEPALIVE_NAGLE
-    if (!stricmp(optionName, "-keepalive")) {
+    if (!strcasecmp(optionName, "-keepalive")) {
 	BOOL val = FALSE;
 	int boolVar, rtn;
 
@@ -1842,7 +1842,7 @@ TcpSetOptionProc(
 	    return TCL_ERROR;
 	}
 	return TCL_OK;
-    } else if (!stricmp(optionName, "-nagle")) {
+    } else if (!strcasecmp(optionName, "-nagle")) {
 	BOOL val = FALSE;
 	int boolVar, rtn;
 
-- 
cgit v0.12