1
/*-------------------------------------------------------------------------
4
* unsetenv() emulation for machines without it
6
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7
* Portions Copyright (c) 1994, Regents of the University of California
11
* $PostgreSQL: pgsql/src/port/unsetenv.c,v 1.4 2004-12-31 22:03:53 pgsql Exp $
13
*-------------------------------------------------------------------------
20
unsetenv(const char *name)
24
if (getenv(name) == NULL)
28
* The technique embodied here works if libc follows the Single Unix
29
* Spec and actually uses the storage passed to putenv() to hold the
30
* environ entry. When we clobber the entry in the second step we are
31
* ensuring that we zap the actual environ member. However, there are
32
* some libc implementations (notably recent BSDs) that do not obey
33
* SUS but copy the presented string. This method fails on such
34
* platforms. Hopefully all such platforms have unsetenv() and thus
35
* won't be using this hack.
37
* Note that repeatedly setting and unsetting a var using this code will
41
envstr = (char *) malloc(strlen(name) + 2);
42
if (!envstr) /* not much we can do if no memory */
45
/* Override the existing setting by forcibly defining the var */
46
sprintf(envstr, "%s=", name);
49
/* Now we can clobber the variable definition this way: */
53
* This last putenv cleans up if we have multiple zero-length names as
54
* a result of unsetting multiple things.