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

Definition   

#include <stdlib.h>

int putenv (const char *string);

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().

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.

Error

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.

When a program is started, the S variable SYSPOSIX is evaluated as part of the environment
definition in addition to the defaults for the environment (see section “Environmentvariables”).
putenv()does not, however, alter the S variable, but manipulates
the environment for the current program run only.

See also

environ, getenv, malloc, stdlib.h.