git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Use setenv(), fix warnings

From
THTimo Hirvonen <tihirvon@gmail.com>
Date
Feb 26, 2006, 18:37 UTC
Message-ID
<20060226203756.05dcfb26.tihirvon@gmail.com>
In-Reply-To
<7vmzge570u.fsf@assigned-by-dhcp.cox.net>

On Sun, 26 Feb 2006 10:06:41 -0800 Junio C Hamano <junkio@cox.net> wrote:

Show 11 quoted lines
> Timo Hirvonen <tihirvon@gmail.com> writes:
> 
> >   - Use setenv() instead of putenv()
> >   - Fix -Wundef -Wold-style-definition warnings
> >   - Make pll_free() static
> 
> I think the last one makes sense, and I can see why some people
> may prefer -Wundef but I am not sure about the first one.  Care
> to defend why we should prefer setenv()?  IIRC, initially we did
> not use setenv() anywhere because certain platforms only had
> putenv().

I was confused by putenv(3) man page. I thought it wanted malloc'ed strings (no 'const' in the parameter -> warning). It appears that statically allocated strings are accepted but _automatic_ variables aren't. I noticed setenv is now in compat/ so I though it was good idea to use it.

Sorry for the noise.
Show 10 quoted lines
> > diff --git a/fsck-objects.c b/fsck-objects.c
> > @@ -483,7 +483,7 @@ int main(int argc, char **argv)
> >  	if (standalone && check_full)
> >  		die("Only one of --standalone or --full can be used.");
> >  	if (standalone)
> > -		putenv("GIT_ALTERNATE_OBJECT_DIRECTORIES=");
> > +		setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", "", 1);
> 
> For platforms with only putenv we did this; here, what we really
> wanted to do was unsetenv.
putenv(3):
    "If the argument `string` is of the form `name`, and does not
    contain an `=' character, then the variable `name` is removed from
    the environment."

So the variable is emptied, not removed. But usually empty environment variables are treated as if they didn't exist...

-- 
http://onion.dynserv.net/~timo/
Previous: Junio C HamanoNext: Jason Riedy
Message 3 of 5 in “Use setenv(), fix warnings”
  1. Use setenv(), fix warningsTimo Hirvonen, Feb 26, 2006
  2. Junio C HamanoFeb 26, 2006
  3. Timo HirvonenFeb 26, 2006
  4. Jason RiedyFeb 26, 2006
  5. Junio C HamanoFeb 26, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.