.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
.TH "PUTENV" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" putenv
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.SH NAME
putenv \- change or add a value to an environment
.SH SYNOPSIS
.LP
\fB#include <stdlib.h>
.br
.sp
int putenv(char *\fP\fIstring\fP\fB); \fP
\fB
.br
\fP
.SH DESCRIPTION
.LP
The \fIputenv\fP() function shall use the \fIstring\fP argument to
set environment variable values. The \fIstring\fP argument
should point to a string of the form " \fIname\fP= \fIvalue\fP ".
The \fIputenv\fP() function shall make the value of the
environment variable \fIname\fP equal to \fIvalue\fP by altering an
existing variable or creating a new one. In either case, the
string pointed to by \fIstring\fP shall become part of the environment,
so altering the string shall change the environment. The
space used by \fIstring\fP is no longer used once a new string which
defines \fIname\fP is passed to \fIputenv\fP().
.LP
The \fIputenv\fP() function need not be reentrant. A function that
is not required to be reentrant is not required to be
thread-safe.
.SH RETURN VALUE
.LP
Upon successful completion, \fIputenv\fP() shall return 0; otherwise,
it shall return a non-zero value and set \fIerrno\fP to
indicate the error.
.SH ERRORS
.LP
The \fIputenv\fP() function may fail if:
.TP 7
.B ENOMEM
Insufficient memory was available.
.sp
.LP
\fIThe following sections are informative.\fP
.SH EXAMPLES
.SS Changing the Value of an Environment Variable
.LP
The following example changes the value of the \fIHOME\fP environment
variable to the value \fB/usr/home\fP.
.sp
.RS
.nf
\fB#include <stdlib.h>
\&...
static char *var = "HOME=/usr/home";
int ret;
.sp
ret = putenv(var);
\fP
.fi
.RE
.SH APPLICATION USAGE
.LP
The \fIputenv\fP() function manipulates the environment pointed to
by \fIenviron\fP, and can be used in conjunction with \fIgetenv\fP().
.LP
See \fIexec\fP(), for restrictions on changing the environment in
multi-threaded applications.
.LP
This routine may use \fImalloc\fP() to enlarge the environment.
.LP
A potential error is to call \fIputenv\fP() with an automatic variable
as the argument, then return from the calling function
while \fIstring\fP is still part of the environment.
.LP
The \fIsetenv\fP() function is preferred over this function.
.SH RATIONALE
.LP
The standard developers noted that \fIputenv\fP() is the only function
available to add to the environment without permitting
memory leaks.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIexec\fP(), \fIgetenv\fP(), \fImalloc\fP(), \fIsetenv\fP(),
the Base Definitions volume of
IEEE\ Std\ 1003.1-2001, \fI<stdlib.h>\fP
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
|