]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/clearenv.3
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man3 / clearenv.3
CommitLineData
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
8clearenv \- clear the environment
b813014f
AC
9.SH LIBRARY
10Standard 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
20Feature 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
30The
31.BR clearenv ()
32function clears the environment of all name-value
fea681da
MK
33pairs and sets the value of the external variable
34.I environ
35to NULL.
f34269b6
MK
36After this call, new variables can be added to the environment using
37.BR putenv (3)
38and
39.BR setenv (3).
47297adb 40.SH RETURN VALUE
60a90ecd
MK
41The
42.BR clearenv ()
c7094399 43function returns zero on success, and a nonzero
fea681da 44value 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 48Available since glibc 2.0.
cc0d547f
ZL
49.SH ATTRIBUTES
50For 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
55allbox;
c466875e 56lbx lb lb
cc0d547f
ZL
57l l l.
58Interface Attribute Value
59T{
60.BR clearenv ()
61T} Thread safety MT-Unsafe const:env
62.TE
c466875e
MK
63.hy
64.ad
847e0d88 65.sp 1
3113c7f3 66.SH STANDARDS
008f1ecc 67Various UNIX variants (DG/UX, HP-UX, QNX, ...).
fea681da 68POSIX.9 (bindings for FORTRAN77).
60a90ecd
MK
69POSIX.1-1996 did not accept
70.BR clearenv ()
d9c1ae64
MK
71and
72.BR putenv (3),
fea681da 73but changed its mind and scheduled these functions for some
9ab7f611 74later issue of this standard (see \[sc]B.4.6.1).
68e1685c 75However, POSIX.1-2001
33a0ccb2 76adds only
988db661 77.BR putenv (3),
d9c1ae64 78and rejected
60a90ecd 79.BR clearenv ().
fea681da 80.SH NOTES
e44a70d6
MK
81On systems where
82.BR clearenv ()
83is unavailable, the assignment
207050fa
MK
84.PP
85.in +4n
86.EX
87environ = NULL;
88.EE
89.in
90.PP
fea681da 91will probably do.
847e0d88 92.PP
c66649c8
MK
93The
94.BR clearenv ()
95function may be useful in security-conscious applications that want to
96precisely control the environment that is passed to programs
97executed using
98.BR exec (3).
99The application would do this by first clearing the environment
100and then adding select environment variables.
847e0d88 101.PP
c66649c8
MK
102Note that the main effect of
103.BR clearenv ()
104is to adjust the value of the pointer
105.BR environ (7);
106this function does not erase the contents of the buffers
107containing the environment definitions.
847e0d88 108.PP
aa496226 109The DG/UX and Tru64 man pages write: If
fea681da
MK
110.I environ
111has been modified by anything other than the
fb186734
MK
112.BR putenv (3),
113.BR getenv (3),
fea681da 114or
31e9a9ec 115.BR clearenv ()
fea681da 116functions, then
63aa9df0 117.BR clearenv ()
fea681da
MK
118will 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)