Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

putenv - change or add environment variables

&pagelevel(4)&pagelevel

Syntax

#include <stdlib.h>

int putenv (const char *string); 

Description

putenv() may be used to alter the value of an existing environment variable or to define a
new one. string must point to a string of the form "name=value", where name is the name of
an environment variable, and value is the value assigned to it. If name is identical to an
existing environment variable, the associated value of the existing variable is updated with
the new value. If name is a new environment variable, it is added to the environment. In either
case, string becomes part of the environment and thus alters it.

The space occupied by string is no longer used when a new value is assigned to an existing
environment variable with putenv().

putenv() is not thread-safe.

Return val.

0

!= 0

if successful.

if an error occurs, e.g. because not enough memory is available. errno is
set to indicate the error.

Errors

putenv() will fail if:

ENOMEM       There is not enough memory available.

Notes

putenv() manipulates the environment to which environ points and may be used in
connection with getenv().

putenv() may use malloc() to expand the environment.

A potential source of error is to call putenv() with an automatic variable as an argument
and then return from the calling function while string is still part of the environment.

BS2000
When a program is started from the POSIX shell, the SDF-P variable structure SYSPOSIX
is evaluated as part of the environment definition in addition to the defaults for the
environment (see also environ). putenv()does not, however, alter the SDF-P variables.
The POSIX environment corresponds to the one pointed to be environ. SYSPOSIX.name is
defined in BS2000, i.e. outside the POSIX subsystem. (End)

See also

environ, exec, getenv(), malloc(), setenv(), unsetenv(), stdlib.h, section“Environment variables”.