SETENV(3)                  POSIX Programmer's Manual                 SETENV(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
       setenv -- add or change environment variable

SSYYNNOOPPSSIISS
       #include <stdlib.h>

       int setenv(const char *_e_n_v_n_a_m_e, const char *_e_n_v_v_a_l, int _o_v_e_r_w_r_i_t_e);

DDEESSCCRRIIPPTTIIOONN
       The _s_e_t_e_n_v() function shall update or add a variable in the environment
       of the calling process. The _e_n_v_n_a_m_e argument points to a string
       containing the name of an environment variable to be added or altered.
       The environment variable shall be set to the value to which _e_n_v_v_a_l
       points. The function shall fail if _e_n_v_n_a_m_e points to a string which
       contains an ''=='' character. If the environment variable named by _e_n_v_n_a_m_e
       already exists and the value of _o_v_e_r_w_r_i_t_e is non-zero, the function
       shall return success and the environment shall be updated. If the
       environment variable named by _e_n_v_n_a_m_e already exists and the value of
       _o_v_e_r_w_r_i_t_e is zero, the function shall return success and the
       environment shall remain unchanged.

       The _s_e_t_e_n_v() function shall update the list of pointers to which
       _e_n_v_i_r_o_n points.

       The strings described by _e_n_v_n_a_m_e and _e_n_v_v_a_l are copied by this
       function.

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

RREETTUURRNN VVAALLUUEE
       Upon successful completion, zero shall be returned. Otherwise, -1 shall
       be returned, _e_r_r_n_o set to indicate the error, and the environment shall
       be unchanged.

EERRRROORRSS
       The _s_e_t_e_n_v() function shall fail if:

       EEIINNVVAALL The _e_n_v_n_a_m_e argument points to an empty string or points to a
              string containing an ''=='' character.

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

       _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
       None.

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

RRAATTIIOONNAALLEE
       Unanticipated results may occur if _s_e_t_e_n_v() changes the external
       variable _e_n_v_i_r_o_n.  In particular, if the optional _e_n_v_p argument to
       _m_a_i_n() is present, it is not changed, and thus may point to an obsolete
       copy of the environment (as may any other copy of _e_n_v_i_r_o_n).  However,
       other than the aforementioned restriction, the standard developers
       intended that the traditional method of walking through the environment
       by way of the _e_n_v_i_r_o_n pointer must be supported.

       It was decided that _s_e_t_e_n_v() should be required by this version because
       it addresses a piece of missing functionality, and does not impose a
       significant burden on the implementor.

       There was considerable debate as to whether the System V _p_u_t_e_n_v()
       function or the BSD _s_e_t_e_n_v() function should be required as a mandatory
       function. The _s_e_t_e_n_v() function was chosen because it permitted the
       implementation of the _u_n_s_e_t_e_n_v() function to delete environmental
       variables, without specifying an additional interface. The _p_u_t_e_n_v()
       function is available as part of the XSI option.

       The standard developers considered requiring that _s_e_t_e_n_v() indicate an
       error when a call to it would result in exceeding {ARG_MAX}.  The
       requirement was rejected since the condition might be temporary, with
       the application eventually reducing the environment size. The ultimate
       success or failure depends on the size at the time of a call to _e_x_e_c,
       which returns an indication of this error condition.

       See also the RATIONALE section in _g_e_t_e_n_v().

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _e_x_e_c, _g_e_t_e_n_v(), _p_u_t_e_n_v(), _u_n_s_e_t_e_n_v()

       The Base Definitions volume of POSIX.1-2017, <<ssttddlliibb..hh>>, <<ssyyss__ttyyppeess..hh>>,
       <<uunniissttdd..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                            SETENV(3)
