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