Lines Matching refs:ep

88 char **env_get(Env_t* ep)
91 register int n=ep->extra;
92 if(ep->flags&ENV_VALID)
93 return(ep->env+n);
94 if(ep->count > ep->max)
96 if(ep->flags&ENV_MALLOCED)
97 free((void*)ep->env);
98 if(!(ep->env = (char**)malloc(sizeof(char*)*(ep->count+1))))
100 ep->flags |= ENV_MALLOCED;
101 ep->max = ep->count;
103 for(vp=(Evar_t*)dtfirst(ep->dt);vp; vp=(Evar_t*)dtnext(ep->dt,vp))
106 ep->env[n++] = vp->un.ptr;
108 ep->env[n] = 0;
109 ep->flags |= ENV_VALID;
110 environ = ep->env+ep->extra;
111 return(ep->env+ep->extra);
115 * add name=value pair given by <str> to <ep>
120 int env_add(Env_t *ep, const char *str, int flags)
122 Evar_t *vp = (Evar_t*)dtmatch(ep->dt,(void*)str);
132 if(ep->env && (ep->flags&ENV_VALID))
133 ep->env[vp->index>>ENV_BITS] = vp->un.ptr;
137 ep->flags &= ~ENV_VALID;
138 if(vp = ep->freelist)
139 ep->freelist = vp->un.next;
143 ep->freelist = (vp+1);
144 ep->freelist->un.next = 0;
149 if(!(vp=dtinsert(ep->dt,vp)))
151 ep->count++;
162 * delete name from <ep>
166 int env_delete(Env_t *ep, const char *str)
168 Evar_t *vp = (Evar_t*)dtmatch(ep->dt,(void*)str);
171 ep->flags &= ~ENV_VALID;
174 dtdelete(ep->dt,vp);
175 vp->un.next = ep->freelist;
176 ep->freelist = vp;
192 Env_t *ep;
195 if(!(ep = newof((Env_t*)0,Env_t,1,0)))
197 if(!(ep->dt = dtopen(&env_disc,Dtoset)))
206 ep->env = envp;
207 ep->max = n-1;
210 ep->count = ep->extra = extra;
211 ep->freelist = vp = newof((Evar_t*)0,Evar_t,n,0);
222 env_add(ep,*env,0);
224 return(ep);
228 * close <ep> and free up all space used by it
230 void env_close(Env_t *ep)
233 if(ep->env && (ep->flags&ENV_MALLOCED))
234 free((void*)ep->env);
235 for(vp=(Evar_t*)dtfirst(ep->dt);vp; vp=vpnext)
237 vpnext = (Evar_t*)dtnext(ep->dt,vp);
238 env_delete(ep,vp->un.ptr);
240 for(top=0,vp = ep->freelist; vp; vp = vpnext)
254 dtclose(ep->dt);