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