summaryrefslogtreecommitdiffstats
path: root/generic/tclEnv.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclEnv.c')
-rw-r--r--generic/tclEnv.c163
1 files changed, 29 insertions, 134 deletions
diff --git a/generic/tclEnv.c b/generic/tclEnv.c
index ea1a16f..caa80f1 100644
--- a/generic/tclEnv.c
+++ b/generic/tclEnv.c
@@ -43,11 +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__)
- static void TclCygwinPutenv(char *string);
-# define putenv TclCygwinPutenv
-#endif
/*
*----------------------------------------------------------------------
@@ -106,8 +101,7 @@ TclSetupEnv(
} else {
Tcl_MutexLock(&envMutex);
for (i = 0; environ[i] != NULL; i++) {
- p1 = Tcl_ExternalToUtfDString(NULL, environ[i], TCL_STRLEN,
- &envString);
+ p1 = Tcl_ExternalToUtfDString(NULL, environ[i], -1, &envString);
p2 = strchr(p1, '=');
if (p2 == NULL) {
/*
@@ -159,11 +153,9 @@ TclSetEnv(
const char *value) /* New value for variable (UTF-8). */
{
Tcl_DString envString;
- unsigned nameLength, valueLength;
- int index;
+ int index, length, nameLength;
char *p, *oldValue;
const char *p2;
- size_t length;
/*
* Figure out where the entry is going to go. If the name doesn't already
@@ -183,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;
@@ -208,8 +201,7 @@ TclSetEnv(
* interpreters.
*/
- env = Tcl_ExternalToUtfDString(NULL, environ[index], TCL_STRLEN,
- &envString);
+ env = Tcl_ExternalToUtfDString(NULL, environ[index], -1, &envString);
if (strcmp(value, env + (length + 1)) == 0) {
Tcl_DStringFree(&envString);
Tcl_MutexUnlock(&envMutex);
@@ -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);
- p2 = Tcl_UtfToExternalDString(NULL, p, TCL_STRLEN, &envString);
+ 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
@@ -323,8 +314,7 @@ Tcl_PutEnv(
* name and value parts, and call TclSetEnv to do all of the real work.
*/
- name = Tcl_ExternalToUtfDString(NULL, assignment, TCL_STRLEN,
- &nameString);
+ name = Tcl_ExternalToUtfDString(NULL, assignment, -1, &nameString);
value = strchr(name, '=');
if ((value != NULL) && (value != name)) {
@@ -360,7 +350,7 @@ TclUnsetEnv(
const char *name) /* Name of variable to remove (UTF-8). */
{
char *oldValue;
- size_t length;
+ int length;
int index;
#ifdef USE_PUTENV_FOR_UNSET
Tcl_DString envString;
@@ -399,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, TCL_STRLEN, &envString);
- string = ckrealloc(string, Tcl_DStringLength(&envString) + 1);
- memcpy(string, Tcl_DStringValue(&envString),
- (unsigned) Tcl_DStringLength(&envString)+1);
+ Tcl_UtfToExternalDString(NULL, string, -1, &envString);
+ string = ckrealloc(string, (unsigned) Tcl_DStringLength(&envString)+1);
+ strcpy(string, Tcl_DStringValue(&envString));
Tcl_DStringFree(&envString);
putenv(string);
@@ -476,8 +465,7 @@ TclGetEnv(
* value of the environment variable is
* stored. */
{
- size_t length;
- int index;
+ int length, index;
const char *result;
Tcl_MutexLock(&envMutex);
@@ -486,13 +474,12 @@ TclGetEnv(
if (index != -1) {
Tcl_DString envStr;
- result = Tcl_ExternalToUtfDString(NULL, environ[index], TCL_STRLEN,
- &envStr);
+ result = Tcl_ExternalToUtfDString(NULL, environ[index], -1, &envStr);
result += length;
if (*result == '=') {
result++;
Tcl_DStringInit(valuePtr);
- Tcl_DStringAppend(valuePtr, result, TCL_STRLEN);
+ Tcl_DStringAppend(valuePtr, result, -1);
result = Tcl_DStringValue(valuePtr);
} else {
result = NULL;
@@ -571,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);
@@ -648,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;
}
}
@@ -687,7 +674,7 @@ TclFinalizeEnvironment(void)
*/
if (env.cache) {
- ckfree(env.cache);
+ ckfree((char *) env.cache);
env.cache = NULL;
env.cacheSize = 0;
#ifndef USE_PUTENV
@@ -696,98 +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).
- */
-DLLIMPORT extern void __stdcall SetEnvironmentVariableA(const char*, const char *);
-
-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) {
- SetEnvironmentVariableA("PATH", NULL);
- unsetenv("PATH");
- }
-
- SetEnvironmentVariableA(name, value);
- } else {
- char *buf;
-
- /*
- * Eliminate any Path variable, to prevent any confusion.
- */
-
- SetEnvironmentVariableA("Path", NULL);
- unsetenv("Path");
-
- if (value == NULL) {
- buf = NULL;
- } else {
- int size;
-
- size = cygwin_conv_path_list(0, value, NULL, 0);
- buf = alloca(size + 1);
- cygwin_conv_path_list(0, value, buf, size);
- }
-
- SetEnvironmentVariableA(name, buf);
- }
-}
-#endif /* __CYGWIN__ */
-
/*
* Local Variables:
* mode: c