1.\" $NetBSD: getenv.3,v 1.7 1995/12/28 08:52:17 thorpej Exp $ 2.\" 3.\" Copyright (c) 1988, 1991 The Regents of the University of California. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" the American National Standards Committee X3, on Information 8.\" Processing Systems. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. All advertising materials mentioning features or use of this software 19.\" must display the following acknowledgement: 20.\" This product includes software developed by the University of 21.\" California, Berkeley and its contributors. 22.\" 4. Neither the name of the University nor the names of its contributors 23.\" may be used to endorse or promote products derived from this software 24.\" without specific prior written permission. 25.\" 26.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36.\" SUCH DAMAGE. 37.\" 38.\" from: @(#)getenv.3 6.11 (Berkeley) 6/29/91 39.\" 40.Dd June 29, 1991 41.Dt GETENV 3 42.Os 43.Sh NAME 44.Nm getenv , 45.Nm putenv , 46.Nm setenv , 47.Nm unsetenv 48.Nd environment variable functions 49.Sh SYNOPSIS 50.Fd #include <stdlib.h> 51.Ft char * 52.Fn getenv "const char *name" 53.Ft int 54.Fn setenv "const char *name" "const char *value" "int overwrite" 55.Ft int 56.Fn putenv "const char *string" 57.Ft void 58.Fn unsetenv "const char *name" 59.Sh DESCRIPTION 60These functions set, unset and fetch environment variables from the 61host 62.Em environment list . 63For compatibility with differing environment conventions, 64the given arguments 65.Ar name 66and 67.Ar value 68may be appended and prepended, 69respectively, 70with an equal sign 71.Dq Li \&= . 72.Pp 73The 74.Fn getenv 75function obtains the current value of the environment variable, 76.Ar name . 77If the variable 78.Ar name 79is not in the current environment , 80a null pointer is returned. 81.Pp 82The 83.Fn setenv 84function inserts or resets the environment variable 85.Ar name 86in the current environment list. 87If the variable 88.Ar name 89does not exist in the list, 90it is inserted with the given 91.Ar value. 92If the variable does exist, the argument 93.Ar overwrite 94is tested; if 95.Ar overwrite is 96zero, the 97variable is not reset, otherwise it is reset 98to the given 99.Ar value . 100.Pp 101The 102.Fn putenv 103function takes an argument of the form ``name=value'' and is 104equivalent to: 105.Bd -literal -offset indent 106setenv(name, value, 1); 107.Ed 108.Pp 109The 110.Fn unsetenv 111function 112deletes all instances of the variable name pointed to by 113.Fa name 114from the list. 115.Sh RETURN VALUES 116The functions 117.Fn setenv 118and 119.Fn putenv 120return zero if successful; otherwise the global variable 121.Va errno 122is set to indicate the error and a 123\-1 is returned. 124.Sh ERRORS 125.Bl -tag -width Er 126.It Bq Er ENOMEM 127The function 128.Fn setenv 129or 130.Fn putenv 131failed because they were unable to allocate memory for the environment. 132.El 133.Sh SEE ALSO 134.Xr csh 1 , 135.Xr sh 1 , 136.Xr execve 2 , 137.Xr environ 7 138.Sh STANDARDS 139The 140.Fn getenv 141function conforms to 142.St -ansiC . 143.Sh HISTORY 144The functions 145.Fn setenv 146and 147.Fn unsetenv 148appeared in 149.At v7 . 150The 151.Fn putenv 152function appeared in 153.Bx 4.3 Reno . 154