1 .\" Copyright (c) 1988, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)getenv.3 8.2 (Berkeley) 12/11/93
43 .Nd environment variable functions
49 .Fn getenv "const char *name"
51 .Fn setenv "const char *name" "const char *value" "int overwrite"
53 .Fn putenv "char *string"
55 .Fn unsetenv "const char *name"
57 These functions set, unset and fetch environment variables from the
59 .Em environment list .
63 function obtains the current value of the environment variable,
65 The application should not modify the string pointed
72 function inserts or resets the environment variable
74 in the current environment list.
77 does not exist in the list,
78 it is inserted with the given
80 If the variable does exist, the argument
85 variable is not reset, otherwise it is reset
91 function takes an argument of the form ``name=value'' and is
93 .Bd -literal -offset indent
94 setenv(name, value, 1);
97 The string pointed to by
99 becomes part of the environment.
100 A program should not alter or free the string,
101 and should not use stack or other transient string variables
106 function is strongly preferred to
112 deletes all instances of the variable name pointed to by
115 Note that only the variable name (e.g., "NAME") should be given;
116 "NAME=value" will not work.
120 function returns the value of the environment variable as a
125 is not in the current environment,
129 .Rv -std setenv putenv unsetenv
142 pointer, points to an empty string, or points to a string containing an
163 failed because it was unable to allocate memory for the environment.
166 .Fd #include <stdlib.h>
171 .Fa "const char *name"
175 doesn't return a value.
178 no longer copies its input buffer.
179 This often appears in crash logs as a crash in
181 Avoid passing local buffers or freeing the memory
186 which still makes an internal copy of its buffers.
189 no longer parses the variable name;
190 e.g., unsetenv ("FOO=BAR") no longer works.
193 also now returns a status value and will set
197 is not a defined environment variable.
214 functions conforms to
230 that assign a larger-sized
232 than any previous value to the same
234 will result in a memory leak.
237 semantics for this function
238 (namely, that the contents of
240 are copied and that old values remain accessible indefinitely) make this
242 Future versions may eliminate one or both of these
243 semantic guarantees in order to fix the bug.