diff options
Diffstat (limited to 'src/lib/libc/stdlib/getenv.3')
| -rw-r--r-- | src/lib/libc/stdlib/getenv.3 | 133 |
1 files changed, 78 insertions, 55 deletions
diff --git a/src/lib/libc/stdlib/getenv.3 b/src/lib/libc/stdlib/getenv.3 index 411eb35da4..f987eb13a1 100644 --- a/src/lib/libc/stdlib/getenv.3 +++ b/src/lib/libc/stdlib/getenv.3 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | .\" Copyright (c) 1988, 1991 The Regents of the University of California. | 1 | .\" Copyright (c) 1988, 1991, 1993 |
| 2 | .\" All rights reserved. | 2 | .\" The Regents of the University of California. All rights reserved. |
| 3 | .\" | 3 | .\" |
| 4 | .\" This code is derived from software contributed to Berkeley by | 4 | .\" This code is derived from software contributed to Berkeley by |
| 5 | .\" the American National Standards Committee X3, on Information | 5 | .\" the American National Standards Committee X3, on Information |
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,10 +29,9 @@ | |||
| 33 | .\" 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 |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)getenv.3 6.11 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: getenv.3,v 1.18 2012/09/23 16:08:04 jeremy Exp $ |
| 37 | .\" $Id: getenv.3,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: September 23 2012 $ |
| 40 | .Dt GETENV 3 | 35 | .Dt GETENV 3 |
| 41 | .Os | 36 | .Os |
| 42 | .Sh NAME | 37 | .Sh NAME |
| @@ -52,82 +47,97 @@ | |||
| 52 | .Ft int | 47 | .Ft int |
| 53 | .Fn setenv "const char *name" "const char *value" "int overwrite" | 48 | .Fn setenv "const char *name" "const char *value" "int overwrite" |
| 54 | .Ft int | 49 | .Ft int |
| 55 | .Fn putenv "const char *string" | 50 | .Fn putenv "char *string" |
| 56 | .Ft void | 51 | .Ft int |
| 57 | .Fn unsetenv "const char *name" | 52 | .Fn unsetenv "const char *name" |
| 58 | .Sh DESCRIPTION | 53 | .Sh DESCRIPTION |
| 59 | These functions set, unset and fetch environment variables from the | 54 | These functions set, unset, and fetch environment variables from the host |
| 60 | host | ||
| 61 | .Em environment list . | 55 | .Em environment list . |
| 62 | For compatibility with differing environment conventions, | ||
| 63 | the given arguments | ||
| 64 | .Ar name | ||
| 65 | and | ||
| 66 | .Ar value | ||
| 67 | may be appended and prepended, | ||
| 68 | respectively, | ||
| 69 | with an equal sign | ||
| 70 | .Dq Li \&= . | ||
| 71 | .Pp | 56 | .Pp |
| 72 | The | 57 | The |
| 73 | .Fn getenv | 58 | .Fn getenv |
| 74 | function obtains the current value of the environment variable, | 59 | function obtains the current value of the environment variable |
| 75 | .Ar name . | 60 | .Fa name . |
| 76 | If the variable | 61 | If the variable |
| 77 | .Ar name | 62 | .Fa name |
| 78 | is not in the current environment , | 63 | is not in the current environment, a null pointer is returned. |
| 79 | a null pointer is returned. | ||
| 80 | .Pp | 64 | .Pp |
| 81 | The | 65 | The |
| 82 | .Fn setenv | 66 | .Fn setenv |
| 83 | function inserts or resets the environment variable | 67 | function inserts or resets the environment variable |
| 84 | .Ar name | 68 | .Fa name |
| 85 | in the current environment list. | 69 | in the current environment list. |
| 86 | If the variable | 70 | If the variable |
| 87 | .Ar name | 71 | .Fa name |
| 88 | does not exist in the list, | 72 | does not exist in the list, it is inserted with the given |
| 89 | it is inserted with the given | 73 | .Fa value . |
| 90 | .Ar value. | ||
| 91 | If the variable does exist, the argument | 74 | If the variable does exist, the argument |
| 92 | .Ar overwrite | 75 | .Fa overwrite |
| 93 | is tested; if | 76 | is tested; if |
| 94 | .Ar overwrite is | 77 | .Fa overwrite |
| 95 | zero, the | 78 | is zero, the variable is not reset, otherwise it is reset to the given |
| 96 | variable is not reset, otherwise it is reset | 79 | .Fa value . |
| 97 | to the given | ||
| 98 | .Ar value . | ||
| 99 | .Pp | 80 | .Pp |
| 100 | The | 81 | The |
| 101 | .Fn putenv | 82 | .Fn putenv |
| 102 | function takes an argument of the form ``name=value'' and is | 83 | function takes an argument of the form |
| 103 | equivalent to: | 84 | .Ar name Ns = Ns Ar value . |
| 104 | .Bd -literal -offset indent | 85 | The memory pointed to by |
| 105 | setenv(name, value, 1); | 86 | .Ar string |
| 106 | .Ed | 87 | becomes part of the environment and must not be deallocated by the caller. |
| 88 | If the variable already exists, it will be overwritten. | ||
| 89 | A common source of bugs is to pass a | ||
| 90 | .Ar string | ||
| 91 | argument that is a locally scoped string buffer. | ||
| 92 | This will result in corruption of the environment after leaving | ||
| 93 | the scope in which the variable is defined. | ||
| 94 | For this reason, the | ||
| 95 | .Fn setenv | ||
| 96 | function is preferred over | ||
| 97 | .Fn putenv . | ||
| 107 | .Pp | 98 | .Pp |
| 108 | The | 99 | The |
| 109 | .Fn unsetenv | 100 | .Fn unsetenv |
| 110 | function | 101 | function deletes all instances of the variable name pointed to by |
| 111 | deletes all instances of the variable name pointed to by | ||
| 112 | .Fa name | 102 | .Fa name |
| 113 | from the list. | 103 | from the list. |
| 114 | .Sh RETURN VALUES | 104 | .Sh RETURN VALUES |
| 115 | The functions | 105 | These functions |
| 116 | .Fn setenv | ||
| 117 | and | ||
| 118 | .Fn putenv | ||
| 119 | return zero if successful; otherwise the global variable | 106 | return zero if successful; otherwise the global variable |
| 120 | .Va errno | 107 | .Va errno |
| 121 | is set to indicate the error and a | 108 | is set to indicate the error and \-1 is returned. |
| 122 | \-1 is returned. | 109 | .Pp |
| 110 | If | ||
| 111 | .Fn getenv | ||
| 112 | is successful, the string returned should be considered read-only. | ||
| 123 | .Sh ERRORS | 113 | .Sh ERRORS |
| 124 | .Bl -tag -width Er | 114 | .Bl -tag -width Er |
| 115 | .It Bq Er EINVAL | ||
| 116 | The | ||
| 117 | .Fn setenv | ||
| 118 | or | ||
| 119 | .Fn unsetenv | ||
| 120 | function was passed an empty | ||
| 121 | .Ar name | ||
| 122 | or a NULL pointer, or was passed a | ||
| 123 | .Ar name | ||
| 124 | containing an | ||
| 125 | .Sq = | ||
| 126 | character. | ||
| 127 | .Pp | ||
| 128 | The | ||
| 129 | .Fn putenv | ||
| 130 | function was passed a | ||
| 131 | .Ar string | ||
| 132 | that did not contain an | ||
| 133 | .Sq = | ||
| 134 | character. | ||
| 125 | .It Bq Er ENOMEM | 135 | .It Bq Er ENOMEM |
| 126 | The function | 136 | The |
| 127 | .Fn setenv | 137 | .Fn setenv |
| 128 | or | 138 | or |
| 129 | .Fn putenv | 139 | .Fn putenv |
| 130 | failed because they were unable to allocate memory for the environment. | 140 | function failed because it was unable to allocate memory for the environment. |
| 131 | .El | 141 | .El |
| 132 | .Sh SEE ALSO | 142 | .Sh SEE ALSO |
| 133 | .Xr csh 1 , | 143 | .Xr csh 1 , |
| @@ -139,13 +149,26 @@ The | |||
| 139 | .Fn getenv | 149 | .Fn getenv |
| 140 | function conforms to | 150 | function conforms to |
| 141 | .St -ansiC . | 151 | .St -ansiC . |
| 152 | The | ||
| 153 | .Fn putenv , | ||
| 154 | .Fn setenv , | ||
| 155 | and | ||
| 156 | .Fn unsetenv | ||
| 157 | functions conform to | ||
| 158 | .St -p1003.1-2008 . | ||
| 142 | .Sh HISTORY | 159 | .Sh HISTORY |
| 160 | The function | ||
| 161 | .Fn getenv | ||
| 162 | appeared in | ||
| 163 | .At v7 | ||
| 164 | and | ||
| 165 | .Bx 3 . | ||
| 143 | The functions | 166 | The functions |
| 144 | .Fn setenv | 167 | .Fn setenv |
| 145 | and | 168 | and |
| 146 | .Fn unsetenv | 169 | .Fn unsetenv |
| 147 | appeared in | 170 | appeared in |
| 148 | .At v7 . | 171 | .Bx 4.3 Tahoe . |
| 149 | The | 172 | The |
| 150 | .Fn putenv | 173 | .Fn putenv |
| 151 | function appeared in | 174 | function appeared in |
