]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
fea681da MK |
2 | .\" Copyright 2001 John Levon <moz@compsoc.man.ac.uk> |
3 | .\" | |
5fbde956 | 4 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da MK |
5 | .\" |
6 | .\" Additions, aeb, 2001-10-17. | |
4c1c5274 | 7 | .TH clearenv 3 (date) "Linux man-pages (unreleased)" |
fea681da MK |
8 | .SH NAME |
9 | clearenv \- clear the environment | |
b813014f AC |
10 | .SH LIBRARY |
11 | Standard C library | |
12 | .RI ( libc ", " \-lc ) | |
fea681da MK |
13 | .SH SYNOPSIS |
14 | .nf | |
15 | .B #include <stdlib.h> | |
68e4db0a | 16 | .PP |
0daa9e92 | 17 | .B "int clearenv(void);" |
fea681da | 18 | .fi |
68e4db0a | 19 | .PP |
d39ad78f | 20 | .RS -4 |
cc4615cc MK |
21 | Feature Test Macro Requirements for glibc (see |
22 | .BR feature_test_macros (7)): | |
d39ad78f | 23 | .RE |
68e4db0a | 24 | .PP |
cc4615cc | 25 | .BR clearenv (): |
9d281e06 | 26 | .nf |
75c018a1 AC |
27 | /* glibc >= 2.19: */ _DEFAULT_SOURCE |
28 | || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE | |
9d281e06 | 29 | .fi |
fea681da | 30 | .SH DESCRIPTION |
60a90ecd MK |
31 | The |
32 | .BR clearenv () | |
33 | function clears the environment of all name-value | |
fea681da MK |
34 | pairs and sets the value of the external variable |
35 | .I environ | |
36 | to NULL. | |
f34269b6 MK |
37 | After this call, new variables can be added to the environment using |
38 | .BR putenv (3) | |
39 | and | |
40 | .BR setenv (3). | |
47297adb | 41 | .SH RETURN VALUE |
60a90ecd MK |
42 | The |
43 | .BR clearenv () | |
c7094399 | 44 | function returns zero on success, and a nonzero |
fea681da | 45 | value on failure. |
008f1ecc | 46 | .\" Most versions of UNIX return -1 on error, or do not even have errors. |
75c018a1 | 47 | .\" glibc info and the Watcom C library document "a nonzero value". |
cc0d547f ZL |
48 | .SH ATTRIBUTES |
49 | For an explanation of the terms used in this section, see | |
50 | .BR attributes (7). | |
51 | .TS | |
52 | allbox; | |
c466875e | 53 | lbx lb lb |
cc0d547f ZL |
54 | l l l. |
55 | Interface Attribute Value | |
56 | T{ | |
9e54434e BR |
57 | .na |
58 | .nh | |
cc0d547f ZL |
59 | .BR clearenv () |
60 | T} Thread safety MT-Unsafe const:env | |
61 | .TE | |
847e0d88 | 62 | .sp 1 |
3113c7f3 | 63 | .SH STANDARDS |
4131356c AC |
64 | .TP |
65 | .BR putenv () | |
66 | POSIX.1-2008. | |
67 | .TP | |
68 | .BR clearenv () | |
69 | None. | |
70 | .SH HISTORY | |
71 | .TP | |
72 | .BR putenv () | |
73 | glibc 2.0. | |
74 | POSIX.1-2001. | |
75 | .TP | |
76 | .BR clearenv () | |
77 | glibc 2.0. | |
78 | .PP | |
008f1ecc | 79 | Various UNIX variants (DG/UX, HP-UX, QNX, ...). |
fea681da | 80 | POSIX.9 (bindings for FORTRAN77). |
60a90ecd MK |
81 | POSIX.1-1996 did not accept |
82 | .BR clearenv () | |
d9c1ae64 MK |
83 | and |
84 | .BR putenv (3), | |
fea681da | 85 | but changed its mind and scheduled these functions for some |
9ab7f611 | 86 | later issue of this standard (see \[sc]B.4.6.1). |
68e1685c | 87 | However, POSIX.1-2001 |
33a0ccb2 | 88 | adds only |
988db661 | 89 | .BR putenv (3), |
d9c1ae64 | 90 | and rejected |
60a90ecd | 91 | .BR clearenv (). |
fea681da | 92 | .SH NOTES |
e44a70d6 MK |
93 | On systems where |
94 | .BR clearenv () | |
95 | is unavailable, the assignment | |
207050fa MK |
96 | .PP |
97 | .in +4n | |
98 | .EX | |
99 | environ = NULL; | |
100 | .EE | |
101 | .in | |
102 | .PP | |
fea681da | 103 | will probably do. |
847e0d88 | 104 | .PP |
c66649c8 MK |
105 | The |
106 | .BR clearenv () | |
107 | function may be useful in security-conscious applications that want to | |
108 | precisely control the environment that is passed to programs | |
109 | executed using | |
110 | .BR exec (3). | |
111 | The application would do this by first clearing the environment | |
112 | and then adding select environment variables. | |
847e0d88 | 113 | .PP |
c66649c8 MK |
114 | Note that the main effect of |
115 | .BR clearenv () | |
116 | is to adjust the value of the pointer | |
117 | .BR environ (7); | |
118 | this function does not erase the contents of the buffers | |
119 | containing the environment definitions. | |
847e0d88 | 120 | .PP |
aa496226 | 121 | The DG/UX and Tru64 man pages write: If |
fea681da MK |
122 | .I environ |
123 | has been modified by anything other than the | |
fb186734 MK |
124 | .BR putenv (3), |
125 | .BR getenv (3), | |
fea681da | 126 | or |
31e9a9ec | 127 | .BR clearenv () |
fea681da | 128 | functions, then |
63aa9df0 | 129 | .BR clearenv () |
fea681da MK |
130 | will return an error and the process environment will remain unchanged. |
131 | .\" .LP | |
68e1685c | 132 | .\" HP-UX has a ENOMEM error return. |
47297adb | 133 | .SH SEE ALSO |
fea681da MK |
134 | .BR getenv (3), |
135 | .BR putenv (3), | |
136 | .BR setenv (3), | |
137 | .BR unsetenv (3), | |
aa949e2d | 138 | .BR environ (7) |