Commit | Line | Data |
---|---|---|
31b20f0a KB |
1 | .\" Copyright (c) 1988 The Regents of the University of California. |
2 | .\" All rights reserved. | |
c80211f9 | 3 | .\" |
adb19fe0 | 4 | .\" %sccs.include.redist.man% |
31b20f0a | 5 | .\" |
58e8ceb7 | 6 | .\" @(#)getenv.3 6.9 (Berkeley) %G% |
31b20f0a | 7 | .\" |
500e7be1 | 8 | .TH GETENV 3 "" |
c80211f9 KM |
9 | .AT 3 |
10 | .SH NAME | |
79fc0f61 | 11 | getenv, putenv, setenv, unsetenv \- manipulate environmental variables |
c80211f9 KM |
12 | .SH SYNOPSIS |
13 | .nf | |
adb19fe0 | 14 | .ft B |
58e8ceb7 KB |
15 | #include <stdlib.h> |
16 | ||
adb19fe0 KB |
17 | char * |
18 | getenv(const char *name); | |
19 | ||
20 | setenv(const char *name, const char *value, int overwrite); | |
21 | ||
22 | putenv(const char *string); | |
23 | ||
24 | void | |
25 | unsetenv(const char *name); | |
26 | .ft R | |
c80211f9 KM |
27 | .fi |
28 | .SH DESCRIPTION | |
adb19fe0 KB |
29 | .I Getenv |
30 | searches the environment list (see | |
31 | .IR environ (7)) | |
4f3c5ada | 32 | for a string of the form \fIname\fP\fB=\fP\fIvalue\fP and returns |
adb19fe0 KB |
33 | a pointer to the string |
34 | .I value | |
35 | if such a string is present, and a NULL pointer if it is not. | |
4f3c5ada | 36 | .PP |
adb19fe0 KB |
37 | .I Setenv |
38 | searches the environment list as | |
39 | .I getenv | |
40 | does; if the string | |
41 | .I name | |
42 | is not found, a string of the form \fIname\fP\fB=\fP\fIvalue\fP is | |
43 | added to the environment. | |
44 | If it is found, and | |
45 | .I overwrite | |
46 | is non-zero, its value is changed to | |
47 | .IR value . | |
48 | .I Setenv | |
49 | returns 0 on success and -1 on failure, setting the external variable | |
50 | .IR errno . | |
4f3c5ada | 51 | .PP |
79fc0f61 | 52 | .I Putenv |
adb19fe0 KB |
53 | takes an argument of the form ``\fIname\fR=\fIvalue\fR'' and is the |
54 | equivalent of: | |
55 | .sp | |
56 | .RS | |
57 | setenv(name, value, 1); | |
58 | .RE | |
0125ac17 | 59 | .PP |
adb19fe0 KB |
60 | .I Unsetenv |
61 | removes all occurrences of the string | |
62 | .I name | |
63 | from the environment. | |
64 | There is no library provision for completely removing the current | |
65 | environment. | |
66 | It is suggested that the following code be used to do so. | |
67 | .sp | |
68 | .RS | |
0125ac17 | 69 | .nf |
adb19fe0 KB |
70 | static char *envinit[1]; |
71 | extern char **environ; | |
72 | environ = envinit; | |
0125ac17 | 73 | .fi |
adb19fe0 | 74 | .RE |
4f3c5ada KB |
75 | .PP |
76 | All of these routines permit, but do not require, a trailing equals | |
adb19fe0 KB |
77 | (``='') sign on |
78 | .I name | |
79 | or a leading equals sign on | |
80 | .IR value . | |
81 | .SH ERRORS | |
82 | .TP | |
83 | [ENOMEM] | |
84 | .I Setenv | |
85 | or | |
86 | .I putenv | |
87 | failed because they were unable to allocate memory for the environment. | |
c80211f9 | 88 | .SH SEE ALSO |
4f3c5ada | 89 | csh(1), sh(1), execve(2), environ(7) |
adb19fe0 KB |
90 | .SH STANDARDS |
91 | .B Getenv | |
92 | conforms to ANSI X3.159-1989 (``ANSI C''). |