summaryrefslogtreecommitdiffstats
path: root/generic/tclEnv.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2002-09-27 00:50:10 (GMT)
committerhobbs <hobbs>2002-09-27 00:50:10 (GMT)
commitb96b459a4907a164acb205a2b024c2c8419ea496 (patch)
tree7ecd449f330b92357eb4737a43574667df864290 /generic/tclEnv.c
parent4985043c6ed39477bf0abc04fe017cccfd090f62 (diff)
downloadtcl-b96b459a4907a164acb205a2b024c2c8419ea496.zip
tcl-b96b459a4907a164acb205a2b024c2c8419ea496.tar.gz
tcl-b96b459a4907a164acb205a2b024c2c8419ea496.tar.bz2
2002-09-18 Mumit Khan <khan@nanotech.wisc.edu>
Added basic Cygwin support. * win/tcl.m4 (SC_PATH_TCLCONFIG): Support one-tree build. (SC_PATH_TKCONFIG): Likewise. (SC_PROG_TCLSH): Likewise. (SC_CONFIG_CFLAGS): Assume real Cygwin port and remove -mno-cygwin flags. Add -mwin32 to extra_cflags and extra_ldflags. Remove ``-e _WinMain@16'' from LDFLAGS_WINDOW. * win/configure.in: Allow Cygwin build. (SEH test): Define to be 1 instead of empty value. (EXCEPTION_DISPOSITION): Add test. * win/configure: Regenerate. * generic/tcl.h: Don't explicitly define __WIN32__ for Cygwin, let the user decide whether to use Windows or POSIX personality. (TCL_WIDE_INT_TYPE, TCL_LL_MODIFIER, struct Tcl_StatBuf): Define for Cygwin. * generic/tclEnv.c (Tcl_CygwinPutenv): putenv replacement for Cygwin. * generic/tclFileName.c (Tcl_TranslateFileName): Convert POSIX to native format. (TclDoGlob): Likewise. * generic/tclPlatDecls.h (TCHAR): Define for Cygwin. * win/tclWinPort.h (putenv, TclpSysAlloc, TclpSysFree, TclpSysRealloc): Define for Cygwin.
Diffstat (limited to 'generic/tclEnv.c')
-rw-r--r--generic/tclEnv.c86
1 files changed, 85 insertions, 1 deletions
diff --git a/generic/tclEnv.c b/generic/tclEnv.c
index 75f5eab..3702ff4 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.17 2002/08/28 22:48:10 davygrvy Exp $
+ * RCS: @(#) $Id: tclEnv.c,v 1.18 2002/09/27 00:50:10 hobbs Exp $
*/
#include "tclInt.h"
@@ -54,6 +54,9 @@ void TclSetEnv _ANSI_ARGS_((CONST char *name,
CONST char *value));
void TclUnsetEnv _ANSI_ARGS_((CONST char *name));
+#if defined (__CYGWIN__) && defined(__WIN32__)
+static void TclCygwinPutenv _ANSI_ARGS_((CONST char *string));
+#endif
/*
*----------------------------------------------------------------------
@@ -699,3 +702,84 @@ TclFinalizeEnvironment()
#endif
}
}
+
+#if defined(__CYGWIN__) && defined(__WIN32__)
+
+#include <windows.h>
+
+/*
+ * When using cygwin, when an environment variable changes, we need to synch
+ * with both the cygwin environment (in case the application C code calls
+ * fork) and the Windows environment (in case the application TCL code calls
+ * exec, which calls the Windows CreateProcess function).
+ */
+
+static void
+TclCygwinPutenv(str)
+ const char *str;
+{
+ char *name, *value;
+
+ /* Get the name and value, so that we can change the environment
+ variable for Windows. */
+ name = (char *) alloca (strlen (str) + 1);
+ strcpy (name, str);
+ for (value = name; *value != '=' && *value != '\0'; ++value)
+ ;
+ if (*value == '\0') {
+ /* Can't happen. */
+ return;
+ }
+ *value = '\0';
+ ++value;
+ if (*value == '\0') {
+ value = NULL;
+ }
+
+ /* Set the cygwin environment variable. */
+#undef putenv
+ if (value == NULL) {
+ unsetenv (name);
+ } else {
+ putenv(str);
+ }
+
+ /*
+ * Before changing the environment variable in Windows, if this is PATH,
+ * we need to convert the value back to a Windows style path.
+ *
+ * FIXME: The calling program may know it is running under windows, and
+ * may have set the path to a Windows path, or, worse, appended or
+ * prepended a Windows path to PATH.
+ */
+ if (strcmp (name, "PATH") != 0) {
+ /* If this is Path, eliminate any PATH variable, to prevent any
+ confusion. */
+ if (strcmp (name, "Path") == 0) {
+ SetEnvironmentVariable ("PATH", (char *) NULL);
+ unsetenv ("PATH");
+ }
+
+ SetEnvironmentVariable (name, value);
+ } else {
+ char *buf;
+
+ /* Eliminate any Path variable, to prevent any confusion. */
+ SetEnvironmentVariable ("Path", (char *) NULL);
+ unsetenv ("Path");
+
+ if (value == NULL) {
+ buf = NULL;
+ } else {
+ int size;
+
+ size = cygwin_posix_to_win32_path_list_buf_size (value);
+ buf = (char *) alloca (size + 1);
+ cygwin_posix_to_win32_path_list (value, buf);
+ }
+
+ SetEnvironmentVariable (name, buf);
+ }
+}
+
+#endif /* __CYGWIN__ && __WIN32__ */