PUTENV(3)                  POSIX Programmer's Manual                 PUTENV(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       putenv -- change or add a value to an environment

SSYYNNOOPPSSIISS
       #include <stdlib.h>

       int putenv(char *_s_t_r_i_n_g);

DDEESSCCRRIIPPTTIIOONN
       The _p_u_t_e_n_v() function shall use the _s_t_r_i_n_g argument to set environment
       variable values. The _s_t_r_i_n_g argument should point to a string of the
       form "_n_a_m_e=_v_a_l_u_e".  The _p_u_t_e_n_v() function shall make the value of the
       environment variable _n_a_m_e equal to _v_a_l_u_e by altering an existing
       variable or creating a new one. In either case, the string pointed to
       by _s_t_r_i_n_g shall become part of the environment, so altering the string
       shall change the environment.

       The _p_u_t_e_n_v() function need not be thread-safe.

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

EERRRROORRSS
       The _p_u_t_e_n_v() function may fail if:

       EENNOOMMEEMM Insufficient memory was available.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   CChhaannggiinngg tthhee VVaalluuee ooff aann EEnnvviirroonnmmeenntt VVaarriiaabbllee
       The following example changes the value of the _H_O_M_E environment
       variable to the value //uussrr//hhoommee.


           #include <stdlib.h>
           ...
           static char *var = "HOME=/usr/home";
           int ret;

           ret = putenv(var);

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The _p_u_t_e_n_v() function manipulates the environment pointed to by
       _e_n_v_i_r_o_n, and can be used in conjunction with _g_e_t_e_n_v().

       See _e_x_e_c() for restrictions on changing the environment in multi-
       threaded applications.

       This routine may use _m_a_l_l_o_c() to enlarge the environment.

       A potential error is to call _p_u_t_e_n_v() with an automatic variable as the
       argument, then return from the calling function while _s_t_r_i_n_g is still
       part of the environment.

       Although the space used by _s_t_r_i_n_g is no longer used once a new string
       which defines _n_a_m_e is passed to _p_u_t_e_n_v(), if any thread in the
       application has used _g_e_t_e_n_v() to retrieve a pointer to this variable,
       it should not be freed by calling _f_r_e_e().  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 _p_u_t_e_n_v() for the same variable.

       The _s_e_t_e_n_v() function is preferred over this function. One reason is
       that _p_u_t_e_n_v() is optional and therefore less portable. Another is that
       using _p_u_t_e_n_v() can slow down environment searches, as explained in the
       RATIONALE section for _g_e_t_e_n_v().

RRAATTIIOONNAALLEE
       Refer to the RATIONALE section in _s_e_t_e_n_v().

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _e_x_e_c, _f_r_e_e(), _g_e_t_e_n_v(), _m_a_l_l_o_c(), _s_e_t_e_n_v()

       The Base Definitions volume of POSIX.1-2017, <<ssttddlliibb..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 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 .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                            PUTENV(3)
