Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

setenv - add or change environment variable

&pagelevel(4)&pagelevel

Syntax

#include <stdlib.h>

int setenv (const char *envname, const char *envval, int overwrite);

Description

The setenv() function updates or adds a variable in the environment of the calling process.

The envname argument points to a string containing the name of an environment variable to be added or altered. If the environment variable already exists, two cases must be distinguished: If the value of overwrite is not zero, the environment is changed; if the value is zero, the environment remains unchanged. In both cases the function is terminated successfully.

If the application modifies environ or the pointers to which it points, the behavior of setenv is undefined. The setenv function updates the list of pointers to which environ points.

The strings described by envname and envval are copied by this function.

setenv() is not thread-safe.

Return val.

0

-1

if successful.

otherwise. errno is set to indicate the error. The environment remains unchanged.

Errors

setenv() will fail if:

 

 

EINVAL

The envname argument is a null pointer, points to an empty string, or points to a string containing an '=' character.

 

ENOMEM

Insufficient memory was available to add a variable or its value to the environment. 

See also

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