Unfortunately, I found some things out today (I must have known this before, because a bell was ringing in the back of my brain yesterday) that cause me to think setenv() and unsetenv() should *not* be implemented.  There are two reasons for this:

1) They inherently and unavoidably leak memory, even though setenv() copies its arguments before putting them in the environment.  The problem is created by the existence of putenv(), which is required by both ISO C and Posix.  Putenv() deliberately does *not* copy its argument; rather, the argument becomes part of the environment data structure.  This means putenv() by itself is deterministic: if you unsetenv() the variable, or if you are about to putenv() it again, the memory used by the previous putenv can be free()d, or can even be a stack variable if you are careful.

But having both putenv() and setenv() means that setenv() and unsetenv() *cannot free* the entry they are about to remove, because it may have been inserted by putenv.  So if you are using setenv() freely, you have a permanent (though usually small) memory leak.

2) The only reasons to modify the environment rather than changing a variable initialized from the environment are these:

2a) to affect the behavior of some other part of the process, typically some library (as TZ affects the time zone library).  The trouble here is that most such libraries do *not* expect these variables to change and don't check whether they should mutate their internal view, so changing the environment is likely to be ineffectual.  (Fortunately, the Olson time zone library provides a way to change the timezone directly without changing the environment.)

2b) to pass a modified environment to a subprocess.  But we can already get the whole environment as an alist, and the ProcessesCowan pre-SRFI accepts an alist and synthesizes a replacement environment from it.  Leaks don't matter here because memory will be discarded by the execve() call,

John Cowan          http://vrici.lojban.org/~cowan        xxxxxx@ccil.org
I must confess that I have very little notion of what [s. 4 of the British
Trade Marks Act, 1938] is intended to convey, and particularly the sentence
of 253 words, as I make them, which constitutes sub-section 1.  I doubt if
the entire statute book could be successfully searched for a sentence of
equal length which is of more fuliginous obscurity. --MacKinnon LJ, 1940