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