PUTENV(3,L) AIX Technical Reference PUTENV(3,L)
-------------------------------------------------------------------------------
putenv
PURPOSE
Sets an environment variable.
LIBRARY
Standard C Library (libc.a)
SYNTAX
int putenv (str)
char *str;
DESCRIPTION
The putenv subroutine sets the value of an environment variable by altering an
existing variable or by creating a new one. The str parameter points to a
string of the form name=value, where name is the environment variable and value
is the new value for it.
The memory space pointed to by the str parameter becomes part of the
environment, so that altering the string effectively changes part of the
environment. The space is no longer used after the value of the environment
variable is changed by calling putenv again.
Warning: Unpredictable results can occur if a subroutine passes putenv a
pointer to an automatic variable and then returns while the variable is still
part of the environment.
Note: The putenv subroutine manipulates the environment pointed to by the
environ external variable, and it can be used in conjunction with
getenv. However, envp, the third parameter to main, is not changed.
See "exec: execl, execv, execle, execve, execlp, execvp" for more
information about environ and envp.
The putenv subroutine uses malloc to enlarge the environment.
After putenv is called, environment variables are not necessarily in
alphabetical order.
RETURN VALUE
Upon successful completion, a value of 0 is returned. If malloc is unable to
obtain sufficient space to expand the environment, then putenv returns a value
of -1.
Processed November 7, 1990 PUTENV(3,L) 1
PUTENV(3,L) AIX Technical Reference PUTENV(3,L)
ERROR CONDITIONS
The putenv subroutine fails if the following is true:
ENOMEM Insufficient memory was available.
RELATED INFORMATION
In this book: "exec: execl, execv, execle, execve, execlp, execvp," "getenv,
NLgetenv," "malloc, free, realloc, calloc, valloc, alloca, mallopt, mallinfo,"
and "environment."
Processed November 7, 1990 PUTENV(3,L) 2