# putenv

## 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.
    


## NAME



           putenv — change or add a value to an environment
    


## SYNOPSIS



           #include <stdlib.h>
    
           int putenv(char *_string_);
    


## DESCRIPTION



           The _putenv_() function shall use the _string_ argument to set
           environment variable values. The _string_ argument should point to a
           string of the form "_name_ =_value_ ".  The _putenv_() function shall make
           the value of the environment variable _name_ equal to _value_ by
           altering an existing variable or creating a new one. In either
           case, the string pointed to by _string_ shall become part of the
           environment, so altering the string shall change the environment.
    
           The _putenv_() function need not be thread-safe.
    


## RETURN VALUE



           Upon successful completion, _putenv_() shall return 0; otherwise, it
           shall return a non-zero value and set _errno_ to indicate the error.
    


## ERRORS



           The _putenv_() function may fail if:
    
           **ENOMEM** Insufficient memory was available.
    
           _The following sections are informative._
    


## EXAMPLES



       **Changing the Value of an Environment Variable**
           The following example changes the value of the _HOME_ environment
           variable to the value **/usr/home**.
    
               #include <stdlib.h>
               ...
               static char *var = "HOME=/usr/home";
               int ret;
    
               ret = putenv(var);
    


## APPLICATION USAGE



           The _putenv_() function manipulates the environment pointed to by
           _environ_ , and can be used in conjunction with _getenv_().
    
           See _exec_() for restrictions on changing the environment in multi-
           threaded applications.
    
           This routine may use _malloc_() to enlarge the environment.
    
           A potential error is to call _putenv_() with an automatic variable
           as the argument, then return from the calling function while
           _string_ is still part of the environment.
    
           Although the space used by _string_ is no longer used once a new
           string which defines _name_ is passed to _putenv_(), if any thread in
           the application has used _getenv_() to retrieve a pointer to this
           variable, it should not be freed by calling _free_().  If the
           changed environment variable is one known by the system (such as
           the locale environment variables) the application should never
           free the buffer used by earlier calls to _putenv_() for the same
           variable.
    
           The _setenv_() function is preferred over this function. One reason
           is that _putenv_() is optional and therefore less portable. Another
           is that using _putenv_() can slow down environment searches, as
           explained in the RATIONALE section for getenv(3p).
    


## RATIONALE



           Refer to the RATIONALE section in setenv(3p).
    


## FUTURE DIRECTIONS



           None.
    


* * *