summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/getenv.3
diff options
context:
space:
mode:
authormillert <>2009-06-03 15:52:16 +0000
committermillert <>2009-06-03 15:52:16 +0000
commitba53e391e204926a7a71b5a9848b928a56af0062 (patch)
tree27076f4f89f7c81fc3ad7e7b02facdf369d4b2e6 /src/lib/libc/stdlib/getenv.3
parent43170abfbd0c2858c372e7ef19f5dffe4f34137c (diff)
downloadopenbsd-ba53e391e204926a7a71b5a9848b928a56af0062.tar.gz
openbsd-ba53e391e204926a7a71b5a9848b928a56af0062.tar.bz2
openbsd-ba53e391e204926a7a71b5a9848b928a56af0062.zip
Make putenv(), setenv() and unsetenv() standards compliant. The
standard explicitly disallows passing setenv a name with a '=' in it but historic BSD behavior is to allow this but to ignore the '=' and anything after it.
Diffstat (limited to 'src/lib/libc/stdlib/getenv.3')
-rw-r--r--src/lib/libc/stdlib/getenv.354
1 files changed, 39 insertions, 15 deletions
diff --git a/src/lib/libc/stdlib/getenv.3 b/src/lib/libc/stdlib/getenv.3
index 1d8546997f..484ff991dc 100644
--- a/src/lib/libc/stdlib/getenv.3
+++ b/src/lib/libc/stdlib/getenv.3
@@ -29,9 +29,9 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
31.\" 31.\"
32.\" $OpenBSD: getenv.3,v 1.12 2007/05/31 19:19:31 jmc Exp $ 32.\" $OpenBSD: getenv.3,v 1.13 2009/06/03 15:52:16 millert Exp $
33.\" 33.\"
34.Dd $Mdocdate: May 31 2007 $ 34.Dd $Mdocdate: June 3 2009 $
35.Dt GETENV 3 35.Dt GETENV 3
36.Os 36.Os
37.Sh NAME 37.Sh NAME
@@ -47,8 +47,8 @@
47.Ft int 47.Ft int
48.Fn setenv "const char *name" "const char *value" "int overwrite" 48.Fn setenv "const char *name" "const char *value" "int overwrite"
49.Ft int 49.Ft int
50.Fn putenv "const char *string" 50.Fn putenv "char *string"
51.Ft void 51.Ft int
52.Fn unsetenv "const char *name" 52.Fn unsetenv "const char *name"
53.Sh DESCRIPTION 53.Sh DESCRIPTION
54These functions set, unset, and fetch environment variables from the host 54These functions set, unset, and fetch environment variables from the host
@@ -87,11 +87,20 @@ is zero, the variable is not reset, otherwise it is reset to the given
87The 87The
88.Fn putenv 88.Fn putenv
89function takes an argument of the form 89function takes an argument of the form
90.Ar name Ns = Ns Ar value 90.Ar name Ns = Ns Ar value .
91and is equivalent to: 91The memory pointed to by
92.Bd -literal -offset indent 92.Ar string
93setenv(name, value, 1); 93becomes part of the environment and must not be deallocated by the caller.
94.Ed 94If the variable already exists, it will be overwritten.
95A common source of bugs is to pass a
96.Ar string
97argument that is a locally scoped string buffer.
98This will result in corruption of the environment after leaving
99the scope in which the variable is defined.
100For this reason, the
101.Fn setenv
102function is preferred over
103.Fn putenv .
95.Pp 104.Pp
96The 105The
97.Fn unsetenv 106.Fn unsetenv
@@ -99,10 +108,7 @@ function deletes all instances of the variable name pointed to by
99.Fa name 108.Fa name
100from the list. 109from the list.
101.Sh RETURN VALUES 110.Sh RETURN VALUES
102The functions 111These functions
103.Fn setenv
104and
105.Fn putenv
106return zero if successful; otherwise the global variable 112return zero if successful; otherwise the global variable
107.Va errno 113.Va errno
108is set to indicate the error and \-1 is returned. 114is set to indicate the error and \-1 is returned.
@@ -112,12 +118,30 @@ If
112is successful, the string returned should be considered read-only. 118is successful, the string returned should be considered read-only.
113.Sh ERRORS 119.Sh ERRORS
114.Bl -tag -width Er 120.Bl -tag -width Er
121.It Bq Er EINVAL
122The
123.Fn setenv
124or
125.Fn putenv
126function was passed a
127.Ar name
128containing an
129.Sq =
130character.
131.Pp
132The
133.Fn putenv
134function was passed a
135.Ar string
136that did not contain an
137.Sq =
138character.
115.It Bq Er ENOMEM 139.It Bq Er ENOMEM
116The function 140The
117.Fn setenv 141.Fn setenv
118or 142or
119.Fn putenv 143.Fn putenv
120failed because they were unable to allocate memory for the environment. 144function failed because it was unable to allocate memory for the environment.
121.El 145.El
122.Sh SEE ALSO 146.Sh SEE ALSO
123.Xr csh 1 , 147.Xr csh 1 ,