Re: [PATCH] Use setenv(), fix warnings
- From
Jason Riedy <ejr@eecs.berkeley.edu>
- Date
- Feb 26, 2006, 19:38 UTC
- Message-ID
- <15703.1140982710@lotus.CS.Berkeley.EDU>
- In-Reply-To
- <20060226203756.05dcfb26.tihirvon@gmail.com>
And Timo Hirvonen writes: - It appears that statically allocated strings are accepted but - _automatic_ variables aren't.
The putenv()-ed string has to exist as long as the environment does. You can twiddle the environment just by twiddling the string you registered. What fun!
- I noticed setenv is now in compat/ so I though it was good idea - to use it.
All uses of putenv() originally were setenv(). I finally realized a compat/setenv.c was better than playing whack-a-setenv on every release... (Ah, hindsight.)
Note that the current compat/setenv.c _LEAKS MEMORY_ on purpose. Because putenv() requires the string to stay around, we can't ever free it. I hope any library implementing bits of git (libgitbit?) avoids setting environment variables.
- So the variable is emptied, not removed. But usually empty environment - variables are treated as if they didn't exist...
More specifically, git treats both "" and NULL as empty, or at least it did last time I checked.
Jason