]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 2001 John Levon <moz@compsoc.man.ac.uk> |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
4 | .\" Permission is granted to make and distribute verbatim copies of this |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
c13182ef | 12 | .\" |
fea681da MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
24 | .\" |
25 | .\" Additions, aeb, 2001-10-17. | |
97986708 | 26 | .TH CLEARENV 3 2016-03-15 "Linux" "Linux Programmer's Manual" |
fea681da MK |
27 | .SH NAME |
28 | clearenv \- clear the environment | |
29 | .SH SYNOPSIS | |
30 | .nf | |
31 | .B #include <stdlib.h> | |
68e4db0a | 32 | .PP |
0daa9e92 | 33 | .B "int clearenv(void);" |
fea681da | 34 | .fi |
68e4db0a | 35 | .PP |
cc4615cc MK |
36 | .in -4n |
37 | Feature Test Macro Requirements for glibc (see | |
38 | .BR feature_test_macros (7)): | |
39 | .in | |
68e4db0a | 40 | .PP |
cc4615cc | 41 | .BR clearenv (): |
2b1b0424 MK |
42 | /* Glibc since 2.19: */ _DEFAULT_SOURCE |
43 | || /* Glibc versions <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE | |
fea681da | 44 | .SH DESCRIPTION |
60a90ecd MK |
45 | The |
46 | .BR clearenv () | |
47 | function clears the environment of all name-value | |
fea681da MK |
48 | pairs and sets the value of the external variable |
49 | .I environ | |
50 | to NULL. | |
f34269b6 MK |
51 | After this call, new variables can be added to the environment using |
52 | .BR putenv (3) | |
53 | and | |
54 | .BR setenv (3). | |
47297adb | 55 | .SH RETURN VALUE |
60a90ecd MK |
56 | The |
57 | .BR clearenv () | |
c7094399 | 58 | function returns zero on success, and a nonzero |
fea681da | 59 | value on failure. |
008f1ecc | 60 | .\" Most versions of UNIX return -1 on error, or do not even have errors. |
c7094399 | 61 | .\" Glibc info and the Watcom C library document "a nonzero value". |
a759cc87 | 62 | .SH VERSIONS |
5d612d3c | 63 | Available since glibc 2.0. |
cc0d547f ZL |
64 | .SH ATTRIBUTES |
65 | For an explanation of the terms used in this section, see | |
66 | .BR attributes (7). | |
67 | .TS | |
68 | allbox; | |
69 | lb lb lb | |
70 | l l l. | |
71 | Interface Attribute Value | |
72 | T{ | |
73 | .BR clearenv () | |
74 | T} Thread safety MT-Unsafe const:env | |
75 | .TE | |
847e0d88 | 76 | .sp 1 |
47297adb | 77 | .SH CONFORMING TO |
008f1ecc | 78 | Various UNIX variants (DG/UX, HP-UX, QNX, ...). |
fea681da | 79 | POSIX.9 (bindings for FORTRAN77). |
60a90ecd MK |
80 | POSIX.1-1996 did not accept |
81 | .BR clearenv () | |
d9c1ae64 MK |
82 | and |
83 | .BR putenv (3), | |
fea681da | 84 | but changed its mind and scheduled these functions for some |
c13182ef | 85 | later issue of this standard (cf. B.4.6.1). |
68e1685c | 86 | However, POSIX.1-2001 |
33a0ccb2 | 87 | adds only |
988db661 | 88 | .BR putenv (3), |
d9c1ae64 | 89 | and rejected |
60a90ecd | 90 | .BR clearenv (). |
fea681da | 91 | .SH NOTES |
e44a70d6 MK |
92 | On systems where |
93 | .BR clearenv () | |
94 | is unavailable, the assignment | |
fea681da | 95 | .nf |
d830deef | 96 | |
7295b7ed | 97 | environ = NULL; |
d830deef | 98 | |
fea681da | 99 | .fi |
fea681da | 100 | will probably do. |
847e0d88 | 101 | .PP |
c66649c8 MK |
102 | The |
103 | .BR clearenv () | |
104 | function may be useful in security-conscious applications that want to | |
105 | precisely control the environment that is passed to programs | |
106 | executed using | |
107 | .BR exec (3). | |
108 | The application would do this by first clearing the environment | |
109 | and then adding select environment variables. | |
847e0d88 | 110 | .PP |
c66649c8 MK |
111 | Note that the main effect of |
112 | .BR clearenv () | |
113 | is to adjust the value of the pointer | |
114 | .BR environ (7); | |
115 | this function does not erase the contents of the buffers | |
116 | containing the environment definitions. | |
847e0d88 | 117 | .PP |
aa496226 | 118 | The DG/UX and Tru64 man pages write: If |
fea681da MK |
119 | .I environ |
120 | has been modified by anything other than the | |
fb186734 MK |
121 | .BR putenv (3), |
122 | .BR getenv (3), | |
fea681da | 123 | or |
31e9a9ec | 124 | .BR clearenv () |
fea681da | 125 | functions, then |
63aa9df0 | 126 | .BR clearenv () |
fea681da MK |
127 | will return an error and the process environment will remain unchanged. |
128 | .\" .LP | |
68e1685c | 129 | .\" HP-UX has a ENOMEM error return. |
47297adb | 130 | .SH SEE ALSO |
fea681da MK |
131 | .BR getenv (3), |
132 | .BR putenv (3), | |
133 | .BR setenv (3), | |
134 | .BR unsetenv (3), | |
aa949e2d | 135 | .BR environ (7) |