diff options
Diffstat (limited to 'src/lib/libc/stdlib/getenv.3')
| -rw-r--r-- | src/lib/libc/stdlib/getenv.3 | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/getenv.3 b/src/lib/libc/stdlib/getenv.3 new file mode 100644 index 0000000000..1d8546997f --- /dev/null +++ b/src/lib/libc/stdlib/getenv.3 | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | .\" Copyright (c) 1988, 1991, 1993 | ||
| 2 | .\" The Regents of the University of California. All rights reserved. | ||
| 3 | .\" | ||
| 4 | .\" This code is derived from software contributed to Berkeley by | ||
| 5 | .\" the American National Standards Committee X3, on Information | ||
| 6 | .\" Processing Systems. | ||
| 7 | .\" | ||
| 8 | .\" Redistribution and use in source and binary forms, with or without | ||
| 9 | .\" modification, are permitted provided that the following conditions | ||
| 10 | .\" are met: | ||
| 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. | ||
| 19 | .\" | ||
| 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 | ||
| 30 | .\" SUCH DAMAGE. | ||
| 31 | .\" | ||
| 32 | .\" $OpenBSD: getenv.3,v 1.12 2007/05/31 19:19:31 jmc Exp $ | ||
| 33 | .\" | ||
| 34 | .Dd $Mdocdate: May 31 2007 $ | ||
| 35 | .Dt GETENV 3 | ||
| 36 | .Os | ||
| 37 | .Sh NAME | ||
| 38 | .Nm getenv , | ||
| 39 | .Nm putenv , | ||
| 40 | .Nm setenv , | ||
| 41 | .Nm unsetenv | ||
| 42 | .Nd environment variable functions | ||
| 43 | .Sh SYNOPSIS | ||
| 44 | .Fd #include <stdlib.h> | ||
| 45 | .Ft char * | ||
| 46 | .Fn getenv "const char *name" | ||
| 47 | .Ft int | ||
| 48 | .Fn setenv "const char *name" "const char *value" "int overwrite" | ||
| 49 | .Ft int | ||
| 50 | .Fn putenv "const char *string" | ||
| 51 | .Ft void | ||
| 52 | .Fn unsetenv "const char *name" | ||
| 53 | .Sh DESCRIPTION | ||
| 54 | These functions set, unset, and fetch environment variables from the host | ||
| 55 | .Em environment list . | ||
| 56 | For compatibility with differing environment conventions, the given arguments | ||
| 57 | .Fa name | ||
| 58 | and | ||
| 59 | .Fa value | ||
| 60 | may be appended and prepended, respectively, with an equal sign | ||
| 61 | .Dq Li \&= . | ||
| 62 | .Pp | ||
| 63 | The | ||
| 64 | .Fn getenv | ||
| 65 | function obtains the current value of the environment variable | ||
| 66 | .Fa name . | ||
| 67 | If the variable | ||
| 68 | .Fa name | ||
| 69 | is not in the current environment, a null pointer is returned. | ||
| 70 | .Pp | ||
| 71 | The | ||
| 72 | .Fn setenv | ||
| 73 | function inserts or resets the environment variable | ||
| 74 | .Fa name | ||
| 75 | in the current environment list. | ||
| 76 | If the variable | ||
| 77 | .Fa name | ||
| 78 | does not exist in the list, it is inserted with the given | ||
| 79 | .Fa value . | ||
| 80 | If the variable does exist, the argument | ||
| 81 | .Fa overwrite | ||
| 82 | is tested; if | ||
| 83 | .Fa overwrite | ||
| 84 | is zero, the variable is not reset, otherwise it is reset to the given | ||
| 85 | .Fa value . | ||
| 86 | .Pp | ||
| 87 | The | ||
| 88 | .Fn putenv | ||
| 89 | function takes an argument of the form | ||
| 90 | .Ar name Ns = Ns Ar value | ||
| 91 | and is equivalent to: | ||
| 92 | .Bd -literal -offset indent | ||
| 93 | setenv(name, value, 1); | ||
| 94 | .Ed | ||
| 95 | .Pp | ||
| 96 | The | ||
| 97 | .Fn unsetenv | ||
| 98 | function deletes all instances of the variable name pointed to by | ||
| 99 | .Fa name | ||
| 100 | from the list. | ||
| 101 | .Sh RETURN VALUES | ||
| 102 | The functions | ||
| 103 | .Fn setenv | ||
| 104 | and | ||
| 105 | .Fn putenv | ||
| 106 | return zero if successful; otherwise the global variable | ||
| 107 | .Va errno | ||
| 108 | is set to indicate the error and \-1 is returned. | ||
| 109 | .Pp | ||
| 110 | If | ||
| 111 | .Fn getenv | ||
| 112 | is successful, the string returned should be considered read-only. | ||
| 113 | .Sh ERRORS | ||
| 114 | .Bl -tag -width Er | ||
| 115 | .It Bq Er ENOMEM | ||
| 116 | The function | ||
| 117 | .Fn setenv | ||
| 118 | or | ||
| 119 | .Fn putenv | ||
| 120 | failed because they were unable to allocate memory for the environment. | ||
| 121 | .El | ||
| 122 | .Sh SEE ALSO | ||
| 123 | .Xr csh 1 , | ||
| 124 | .Xr sh 1 , | ||
| 125 | .Xr execve 2 , | ||
| 126 | .Xr environ 7 | ||
| 127 | .Sh STANDARDS | ||
| 128 | The | ||
| 129 | .Fn getenv | ||
| 130 | function conforms to | ||
| 131 | .St -ansiC . | ||
| 132 | .Sh HISTORY | ||
| 133 | The function | ||
| 134 | .Fn getenv | ||
| 135 | appeared in | ||
| 136 | .At v7 | ||
| 137 | and | ||
| 138 | .Bx 3 . | ||
| 139 | The functions | ||
| 140 | .Fn setenv | ||
| 141 | and | ||
| 142 | .Fn unsetenv | ||
| 143 | appeared in | ||
| 144 | .Bx 4.3 Tahoe . | ||
| 145 | The | ||
| 146 | .Fn putenv | ||
| 147 | function appeared in | ||
| 148 | .Bx 4.3 Reno . | ||
