Consistently use "superuser" instead of "super user"
[pgsql.git] / src / port / setenv.c
blob440bc832ce858697ad737bef23b31041fc384c50
1 /*-------------------------------------------------------------------------
3 * setenv.c
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
10 * IDENTIFICATION
11 * src/port/setenv.c
13 *-------------------------------------------------------------------------
16 #include "c.h"
19 int
20 setenv(const char *name, const char *value, int overwrite)
22 char *envstr;
24 /* Error conditions, per POSIX */
25 if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL ||
26 value == NULL)
28 errno = EINVAL;
29 return -1;
32 /* No work if variable exists and we're not to replace it */
33 if (overwrite == 0 && getenv(name) != NULL)
34 return 0;
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 */
43 return -1;
45 sprintf(envstr, "%s=%s", name, value);
47 return putenv(envstr);