poll.2: Remove <signal.h>
[man-pages.git] / man3 / clearenv.3
blob60f89b288ffa5cad59aa8e30731c29f35d9ee1ec
1 .\" Copyright 2001 John Levon <moz@compsoc.man.ac.uk>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
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.
12 .\"
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.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Additions, aeb, 2001-10-17.
26 .TH CLEARENV 3  2021-03-22 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 clearenv \- clear the environment
29 .SH SYNOPSIS
30 .nf
31 .B #include <stdlib.h>
32 .PP
33 .B "int clearenv(void);"
34 .fi
35 .PP
36 .RS -4
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
39 .RE
40 .PP
41 .BR clearenv ():
42 .nf
43     /* Glibc since 2.19: */ _DEFAULT_SOURCE
44         || /* Glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
45 .fi
46 .SH DESCRIPTION
47 The
48 .BR clearenv ()
49 function clears the environment of all name-value
50 pairs and sets the value of the external variable
51 .I environ
52 to NULL.
53 After this call, new variables can be added to the environment using
54 .BR putenv (3)
55 and
56 .BR setenv (3).
57 .SH RETURN VALUE
58 The
59 .BR clearenv ()
60 function returns zero on success, and a nonzero
61 value on failure.
62 .\" Most versions of UNIX return -1 on error, or do not even have errors.
63 .\" Glibc info and the Watcom C library document "a nonzero value".
64 .SH VERSIONS
65 Available since glibc 2.0.
66 .SH ATTRIBUTES
67 For an explanation of the terms used in this section, see
68 .BR attributes (7).
69 .ad l
70 .nh
71 .TS
72 allbox;
73 lbx lb lb
74 l l l.
75 Interface       Attribute       Value
77 .BR clearenv ()
78 T}      Thread safety   MT-Unsafe const:env
79 .TE
80 .hy
81 .ad
82 .sp 1
83 .SH CONFORMING TO
84 Various UNIX variants (DG/UX, HP-UX, QNX, ...).
85 POSIX.9 (bindings for FORTRAN77).
86 POSIX.1-1996 did not accept
87 .BR clearenv ()
88 and
89 .BR putenv (3),
90 but changed its mind and scheduled these functions for some
91 later issue of this standard (see \[sc]B.4.6.1).
92 However, POSIX.1-2001
93 adds only
94 .BR putenv (3),
95 and rejected
96 .BR clearenv ().
97 .SH NOTES
98 On systems where
99 .BR clearenv ()
100 is unavailable, the assignment
102 .in +4n
104 environ = NULL;
108 will probably do.
111 .BR clearenv ()
112 function may be useful in security-conscious applications that want to
113 precisely control the environment that is passed to programs
114 executed using
115 .BR exec (3).
116 The application would do this by first clearing the environment
117 and then adding select environment variables.
119 Note that the main effect of
120 .BR clearenv ()
121 is to adjust the value of the pointer
122 .BR environ (7);
123 this function does not erase the contents of the buffers
124 containing the environment definitions.
126 The DG/UX and Tru64 man pages write: If
127 .I environ
128 has been modified by anything other than the
129 .BR putenv (3),
130 .BR getenv (3),
132 .BR clearenv ()
133 functions, then
134 .BR clearenv ()
135 will return an error and the process environment will remain unchanged.
136 .\" .LP
137 .\" HP-UX has a ENOMEM error return.
138 .SH SEE ALSO
139 .BR getenv (3),
140 .BR putenv (3),
141 .BR setenv (3),
142 .BR unsetenv (3),
143 .BR environ (7)