[41603] trunk/base/src/pextlib1.0/Pextlib.c

blb at macports.org blb at macports.org
Thu Nov 6 18:48:44 PST 2008


Revision: 41603
          http://trac.macports.org/changeset/41603
Author:   blb at macports.org
Date:     2008-11-06 18:48:44 -0800 (Thu, 06 Nov 2008)
Log Message:
-----------
base/src/pextlib1.0/Pextlib.c - this should get the edge case issues of
the Tcl environment bug (#13930); basically, looping through environ while
unsetting stuff changes environ, so not all variables are caught.
clearenv() if it becomes a standard would be best for this, but is not
available everywhere (including Mac OS X/Darwin), so instead use a simple
technique that has been found to work on a number of various platforms (see
<http://lists.freebsd.org/pipermail/freebsd-stable/2008-June/043136.html>).

Modified Paths:
--------------
    trunk/base/src/pextlib1.0/Pextlib.c

Modified: trunk/base/src/pextlib1.0/Pextlib.c
===================================================================
--- trunk/base/src/pextlib1.0/Pextlib.c	2008-11-07 02:40:00 UTC (rev 41602)
+++ trunk/base/src/pextlib1.0/Pextlib.c	2008-11-07 02:48:44 UTC (rev 41603)
@@ -1129,9 +1129,6 @@
 int UnsetEnvCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
     char *name;
-    char **envp;
-    char *equals;
-    size_t len;
     
     if (objc != 2) {
         Tcl_WrongNumArgs(interp, 1, objv, "name");
@@ -1145,20 +1142,11 @@
     }
 
     if (strcmp(name, "*") == 0) {
-        /* unset all current environment variables */
-        for (envp = environ; *envp != NULL; envp++) {
-            equals = strchr(*envp, '=');
-            if (equals != NULL) {
-                len = equals - *envp;
-                name = malloc(len+1);
-                if (name != NULL) {
-                    memcpy(name, *envp, len);
-                    name[len] = '\0';
-                    (void) unsetenv(name);
-                    free(name);
-                }
-            }
-        }
+        /* unset all current environment variables; it'd be best to use
+           clearenv() but that is not yet standardized, instead use this
+           technique which appears to be good across platforms, see eg:
+           <http://lists.freebsd.org/pipermail/freebsd-stable/2008-June/043136.html> */
+        environ = calloc(1, sizeof(char *));
     } else {
         (void) unsetenv(name);
     }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20081106/e00590dc/attachment.html>


More information about the macports-changes mailing list