From: Junio C Hamano Date: Tue, 22 May 2007 06:33:44 GMT Subject: Re: [PATCH] Add ability to specify environment extension to run_command Message-ID: <7v646l9xkn.fsf@assigned-by-dhcp.cox.net> In-Reply-To: <20070522060302.GH5412@admingilde.org> Martin Waitz writes: > On Mon, May 21, 2007 at 04:02:42PM -0700, Junio C Hamano wrote: >> I had a feeling that some callers needed to be able to unsetenv >> some. How would this patch help them, or are they outside of >> the scope? > > At first I had the same objection but the putenv documentation > told me that at least in glibc you can unsetenv by providing > the variable name without a "=". I recall SysV putenv() does not remove "ENVNAME" without '=', and http://www.opengroup.org/onlinepubs/000095399/functions/putenv.html seems to say that as well. > But perhaps we should check for other systems? Probably. At least we have setenv/unsetenv calls already (with emulation where they aren't available), we could do something like this: struct child_process { ... const struct { const char *name; const char *value; /* NULL to unsetenv */ } *env; ... }; and in start_command(): if (cmd->env) { int i; for (i = 0; cmd->env[i].name; i++) { if (cmd->env[i].value) setenv(cmd->env[i].name, cmd->env[i].value, 1); else unsetenv(cmd->env[i].name); } }