]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/clearenv.3
proc.5: Note kernel version for /proc/PID/smaps VmFlags "wf" flag
[thirdparty/man-pages.git] / man3 / clearenv.3
CommitLineData
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.
4b8c67d9 26.TH CLEARENV 3 2017-09-15 "Linux" "Linux Programmer's Manual"
fea681da
MK
27.SH NAME
28clearenv \- 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
37Feature 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
45The
46.BR clearenv ()
47function clears the environment of all name-value
fea681da
MK
48pairs and sets the value of the external variable
49.I environ
50to NULL.
f34269b6
MK
51After this call, new variables can be added to the environment using
52.BR putenv (3)
53and
54.BR setenv (3).
47297adb 55.SH RETURN VALUE
60a90ecd
MK
56The
57.BR clearenv ()
c7094399 58function returns zero on success, and a nonzero
fea681da 59value 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 63Available since glibc 2.0.
cc0d547f
ZL
64.SH ATTRIBUTES
65For an explanation of the terms used in this section, see
66.BR attributes (7).
67.TS
68allbox;
69lb lb lb
70l l l.
71Interface Attribute Value
72T{
73.BR clearenv ()
74T} Thread safety MT-Unsafe const:env
75.TE
847e0d88 76.sp 1
47297adb 77.SH CONFORMING TO
008f1ecc 78Various UNIX variants (DG/UX, HP-UX, QNX, ...).
fea681da 79POSIX.9 (bindings for FORTRAN77).
60a90ecd
MK
80POSIX.1-1996 did not accept
81.BR clearenv ()
d9c1ae64
MK
82and
83.BR putenv (3),
fea681da 84but changed its mind and scheduled these functions for some
9ab7f611 85later issue of this standard (see \[sc]B.4.6.1).
68e1685c 86However, POSIX.1-2001
33a0ccb2 87adds only
988db661 88.BR putenv (3),
d9c1ae64 89and rejected
60a90ecd 90.BR clearenv ().
fea681da 91.SH NOTES
e44a70d6
MK
92On systems where
93.BR clearenv ()
94is unavailable, the assignment
207050fa
MK
95.PP
96.in +4n
97.EX
98environ = NULL;
99.EE
100.in
101.PP
fea681da 102will probably do.
847e0d88 103.PP
c66649c8
MK
104The
105.BR clearenv ()
106function may be useful in security-conscious applications that want to
107precisely control the environment that is passed to programs
108executed using
109.BR exec (3).
110The application would do this by first clearing the environment
111and then adding select environment variables.
847e0d88 112.PP
c66649c8
MK
113Note that the main effect of
114.BR clearenv ()
115is to adjust the value of the pointer
116.BR environ (7);
117this function does not erase the contents of the buffers
118containing the environment definitions.
847e0d88 119.PP
aa496226 120The DG/UX and Tru64 man pages write: If
fea681da
MK
121.I environ
122has been modified by anything other than the
fb186734
MK
123.BR putenv (3),
124.BR getenv (3),
fea681da 125or
31e9a9ec 126.BR clearenv ()
fea681da 127functions, then
63aa9df0 128.BR clearenv ()
fea681da
MK
129will return an error and the process environment will remain unchanged.
130.\" .LP
68e1685c 131.\" HP-UX has a ENOMEM error return.
47297adb 132.SH SEE ALSO
fea681da
MK
133.BR getenv (3),
134.BR putenv (3),
135.BR setenv (3),
136.BR unsetenv (3),
aa949e2d 137.BR environ (7)