diff options
Diffstat (limited to 'generic/tclEnv.c')
| -rw-r--r-- | generic/tclEnv.c | 149 |
1 files changed, 20 insertions, 129 deletions
diff --git a/generic/tclEnv.c b/generic/tclEnv.c index 980a785..caa80f1 100644 --- a/generic/tclEnv.c +++ b/generic/tclEnv.c @@ -43,14 +43,6 @@ 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__) -/* 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 /* *---------------------------------------------------------------------- @@ -161,8 +153,7 @@ TclSetEnv( const char *value) /* New value for variable (UTF-8). */ { Tcl_DString envString; - unsigned nameLength, valueLength; - int index, length; + int index, length, nameLength; char *p, *oldValue; const char *p2; @@ -184,11 +175,12 @@ TclSetEnv( */ if ((env.ourEnviron != environ) || (length+2 > env.ourEnvironSize)) { - char **newEnviron = ckalloc((length + 5) * sizeof(char *)); + char **newEnviron = (char **) + ckalloc(((unsigned) length + 5) * sizeof(char *)); memcpy(newEnviron, environ, length * sizeof(char *)); if ((env.ourEnvironSize != 0) && (env.ourEnviron != NULL)) { - ckfree(env.ourEnviron); + ckfree((char *) env.ourEnviron); } environ = env.ourEnviron = newEnviron; env.ourEnvironSize = length + 5; @@ -218,7 +210,7 @@ TclSetEnv( Tcl_DStringFree(&envString); oldValue = environ[index]; - nameLength = (unsigned) length; + nameLength = length; } /* @@ -227,19 +219,18 @@ TclSetEnv( * and set the environ array value. */ - valueLength = strlen(value); - p = ckalloc(nameLength + valueLength + 2); - memcpy(p, name, nameLength); + p = ckalloc((unsigned) nameLength + strlen(value) + 2); + strcpy(p, name); p[nameLength] = '='; - memcpy(p+nameLength+1, value, valueLength+1); + strcpy(p+nameLength+1, value); p2 = Tcl_UtfToExternalDString(NULL, p, -1, &envString); /* * Copy the native string to heap memory. */ - p = ckrealloc(p, Tcl_DStringLength(&envString) + 1); - memcpy(p, p2, (unsigned) Tcl_DStringLength(&envString) + 1); + p = ckrealloc(p, strlen(p2) + 1); + strcpy(p, p2); Tcl_DStringFree(&envString); #ifdef USE_PUTENV @@ -398,21 +389,20 @@ TclUnsetEnv( * that no = should be included, and Windows requires it. */ -#if defined(__WIN32__) || defined(__CYGWIN__) - string = ckalloc(length + 2); +#if defined(__WIN32__) + string = ckalloc((unsigned) length+2); memcpy(string, name, (size_t) length); string[length] = '='; string[length+1] = '\0'; #else - string = ckalloc(length + 1); + string = ckalloc((unsigned) length+1); memcpy(string, name, (size_t) length); string[length] = '\0'; #endif /* WIN32 */ Tcl_UtfToExternalDString(NULL, string, -1, &envString); - string = ckrealloc(string, Tcl_DStringLength(&envString) + 1); - memcpy(string, Tcl_DStringValue(&envString), - (unsigned) Tcl_DStringLength(&envString)+1); + string = ckrealloc(string, (unsigned) Tcl_DStringLength(&envString)+1); + strcpy(string, Tcl_DStringValue(&envString)); Tcl_DStringFree(&envString); putenv(string); @@ -568,7 +558,7 @@ EnvTraceProc( const char *value = TclGetEnv(name2, &valueString); if (value == NULL) { - return (char *) "no such variable"; + return "no such variable"; } Tcl_SetVar2(interp, name1, name2, value, 0); Tcl_DStringFree(&valueString); @@ -645,11 +635,11 @@ ReplaceString( const int growth = 5; - env.cache = ckrealloc(env.cache, + env.cache = (char **) ckrealloc((char *) env.cache, (env.cacheSize + growth) * sizeof(char *)); env.cache[env.cacheSize] = newStr; - (void) memset(env.cache+env.cacheSize+1, 0, - (size_t) (growth-1) * sizeof(char *)); + (void) memset(env.cache+env.cacheSize+1, (int) 0, + (size_t) (growth-1) * sizeof(char*)); env.cacheSize += growth; } } @@ -684,7 +674,7 @@ TclFinalizeEnvironment(void) */ if (env.cache) { - ckfree(env.cache); + ckfree((char *) env.cache); env.cache = NULL; env.cacheSize = 0; #ifndef USE_PUTENV @@ -693,105 +683,6 @@ TclFinalizeEnvironment(void) } } -#if defined(__CYGWIN__) - -/* - * 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( - char *str) -{ - char *name, *value; - - /* - * Get the name and value, so that we can change the environment variable - * for Windows. - */ - - name = alloca(strlen(str) + 1); - strcpy(name, str); - for (value=name ; *value!='=' && *value!='\0' ; ++value) { - /* Empty body */ - } - if (*value == '\0') { - /* Can't happen. */ - return; - } - *(value++) = '\0'; - 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) { -#ifdef __WIN32__ - SetEnvironmentVariableA("PATH", NULL); -#endif - unsetenv("PATH"); - } - -#ifdef __WIN32__ - SetEnvironmentVariableA(name, value); -#endif - } else { - char *buf; - - /* - * Eliminate any Path variable, to prevent any confusion. - */ - -#ifdef __WIN32__ - SetEnvironmentVariableA("Path", NULL); -#endif - unsetenv("Path"); - - if (value == NULL) { - buf = NULL; - } else { - int size; - - size = cygwin_posix_to_win32_path_list_buf_size(value); - buf = alloca(size + 1); - cygwin_posix_to_win32_path_list(value, buf); - } - -#ifdef __WIN32__ - SetEnvironmentVariableA(name, buf); -#endif - } -} -#endif /* __CYGWIN__ */ - /* * Local Variables: * mode: c |
