1 /*-------------------------------------------------------------------------
4 * setenv() emulation for machines without it
6 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
13 *-------------------------------------------------------------------------
20 setenv(const char *name
, const char *value
, int overwrite
)
24 /* Error conditions, per POSIX */
25 if (name
== NULL
|| name
[0] == '\0' || strchr(name
, '=') != NULL
||
32 /* No work if variable exists and we're not to replace it */
33 if (overwrite
== 0 && getenv(name
) != NULL
)
37 * Add or replace the value using putenv(). This will leak memory if the
38 * same variable is repeatedly redefined, but there's little we can do
39 * about that when sitting atop putenv().
41 envstr
= (char *) malloc(strlen(name
) + strlen(value
) + 2);
42 if (!envstr
) /* not much we can do if no memory */
45 sprintf(envstr
, "%s=%s", name
, value
);
47 return putenv(envstr
);