diff options
author | millert <> | 2009-06-03 15:52:16 +0000 |
---|---|---|
committer | millert <> | 2009-06-03 15:52:16 +0000 |
commit | ba53e391e204926a7a71b5a9848b928a56af0062 (patch) | |
tree | 27076f4f89f7c81fc3ad7e7b02facdf369d4b2e6 /src/lib/libc/stdlib/getenv.3 | |
parent | 43170abfbd0c2858c372e7ef19f5dffe4f34137c (diff) | |
download | openbsd-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.3 | 54 |
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 |
54 | These functions set, unset, and fetch environment variables from the host | 54 | These 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 | |||
87 | The | 87 | The |
88 | .Fn putenv | 88 | .Fn putenv |
89 | function takes an argument of the form | 89 | function takes an argument of the form |
90 | .Ar name Ns = Ns Ar value | 90 | .Ar name Ns = Ns Ar value . |
91 | and is equivalent to: | 91 | The memory pointed to by |
92 | .Bd -literal -offset indent | 92 | .Ar string |
93 | setenv(name, value, 1); | 93 | becomes part of the environment and must not be deallocated by the caller. |
94 | .Ed | 94 | If the variable already exists, it will be overwritten. |
95 | A common source of bugs is to pass a | ||
96 | .Ar string | ||
97 | argument that is a locally scoped string buffer. | ||
98 | This will result in corruption of the environment after leaving | ||
99 | the scope in which the variable is defined. | ||
100 | For this reason, the | ||
101 | .Fn setenv | ||
102 | function is preferred over | ||
103 | .Fn putenv . | ||
95 | .Pp | 104 | .Pp |
96 | The | 105 | The |
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 |
100 | from the list. | 109 | from the list. |
101 | .Sh RETURN VALUES | 110 | .Sh RETURN VALUES |
102 | The functions | 111 | These functions |
103 | .Fn setenv | ||
104 | and | ||
105 | .Fn putenv | ||
106 | return zero if successful; otherwise the global variable | 112 | return zero if successful; otherwise the global variable |
107 | .Va errno | 113 | .Va errno |
108 | is set to indicate the error and \-1 is returned. | 114 | is set to indicate the error and \-1 is returned. |
@@ -112,12 +118,30 @@ If | |||
112 | is successful, the string returned should be considered read-only. | 118 | is 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 | ||
122 | The | ||
123 | .Fn setenv | ||
124 | or | ||
125 | .Fn putenv | ||
126 | function was passed a | ||
127 | .Ar name | ||
128 | containing an | ||
129 | .Sq = | ||
130 | character. | ||
131 | .Pp | ||
132 | The | ||
133 | .Fn putenv | ||
134 | function was passed a | ||
135 | .Ar string | ||
136 | that did not contain an | ||
137 | .Sq = | ||
138 | character. | ||
115 | .It Bq Er ENOMEM | 139 | .It Bq Er ENOMEM |
116 | The function | 140 | The |
117 | .Fn setenv | 141 | .Fn setenv |
118 | or | 142 | or |
119 | .Fn putenv | 143 | .Fn putenv |
120 | failed because they were unable to allocate memory for the environment. | 144 | function 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 , |