PostgreSQL Source Code
git master
setenv.c
Go to the documentation of this file.
1
/*-------------------------------------------------------------------------
2
*
3
* setenv.c
4
* setenv() emulation for machines without it
5
*
6
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7
* Portions Copyright (c) 1994, Regents of the University of California
8
*
9
*
10
* IDENTIFICATION
11
* src/port/setenv.c
12
*
13
*-------------------------------------------------------------------------
14
*/
15
16
#include "
c.h
"
17
18
19
int
20
setenv
(
const
char
*
name
,
const
char
*
value
,
int
overwrite
)
21
{
22
char
*envstr;
23
24
/* Error conditions, per POSIX */
25
if
(
name
== NULL ||
name
[0] ==
'\0'
|| strchr(
name
,
'='
) != NULL ||
26
value
== NULL)
27
{
28
errno = EINVAL;
29
return
-1;
30
}
31
32
/* No work if variable exists and we're not to replace it */
33
if
(
overwrite
== 0 && getenv(
name
) != NULL)
34
return
0;
35
36
/*
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().
40
*/
41
envstr = (
char
*)
malloc
(strlen(
name
) + strlen(
value
) + 2);
42
if
(!envstr)
/* not much we can do if no memory */
43
return
-1;
44
45
sprintf
(envstr,
"%s=%s"
,
name
,
value
);
46
47
return
putenv
(envstr);
48
}
c.h
name
const char * name
Definition:
encode.c:561
malloc
#define malloc(a)
Definition:
header.h:50
value
static struct @151 value
sprintf
#define sprintf
Definition:
port.h:227
setenv
int setenv(const char *name, const char *value, int overwrite)
Definition:
setenv.c:20
overwrite
static void overwrite(PGconn *conn, Oid lobjId, int start, int len)
Definition:
testlo.c:108
putenv
#define putenv(x)
Definition:
win32_port.h:506
src
port
setenv.c
Generated on Mon May 23 2022 06:13:23 for PostgreSQL Source Code by
1.9.1