Projects
New Ticket     Wiki     Browse Source     Timeline     Roadmap     Bug Reports     Search

Changeset 36719

Show
Ignore:
Timestamp:
05/13/08 04:04:28 (7 months ago)
Author:
afb@…
Message:

add unsetenv command, for working around bugs in Leopard tcl

Location:
trunk/base/src/pextlib1.0
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/base/src/pextlib1.0/Pextlib.c

    r34514 r36719  
    11191119} 
    11201120 
     1121/** 
     1122 * deletes environment variable 
     1123 * 
     1124 * Syntax is: 
     1125 * unsetenv name (* for all) 
     1126 */ 
     1127int UnsetEnvCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) 
     1128{ 
     1129    char *name; 
     1130    char **envp; 
     1131    char *equals; 
     1132    size_t len; 
     1133     
     1134    if (objc != 2) { 
     1135        Tcl_WrongNumArgs(interp, 1, objv, "name"); 
     1136        return TCL_ERROR; 
     1137    } 
     1138 
     1139    name = Tcl_GetString(objv[1]); 
     1140    if (strchr(name, '=') != NULL) { 
     1141        Tcl_SetResult(interp, "only the name should be given", TCL_STATIC); 
     1142        return TCL_ERROR; 
     1143    } 
     1144 
     1145    if (strcmp(name, "*") == 0) { 
     1146        /* unset all current environment variables */ 
     1147        for (envp = environ; *envp != NULL; envp++) { 
     1148            equals = strchr(*envp, '='); 
     1149            if (equals != NULL) { 
     1150                len = equals - *envp; 
     1151                name = malloc(len+1); 
     1152                if (name != NULL) { 
     1153                    memcpy(name, *envp, len); 
     1154                    name[len] = '\0'; 
     1155                    (void) unsetenv(name); 
     1156                    free(name); 
     1157                } 
     1158            } 
     1159        } 
     1160    } else { 
     1161        (void) unsetenv(name); 
     1162    } 
     1163 
     1164    return TCL_OK; 
     1165} 
     1166 
    11211167int Pextlib_Init(Tcl_Interp *interp) 
    11221168{ 
     
    11501196        Tcl_CreateObjCommand(interp, "curl", CurlCmd, NULL, NULL); 
    11511197    Tcl_CreateObjCommand(interp, "symlink", CreateSymlinkCmd, NULL, NULL); 
     1198    Tcl_CreateObjCommand(interp, "unsetenv", UnsetEnvCmd, NULL, NULL); 
    11521199         
    11531200        Tcl_CreateObjCommand(interp, "readline", ReadlineCmd, NULL, NULL);