]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/clearenv.3
fuse.4: fuse_entry_out: rework discussion of uniqueness of nodeid + generation
[thirdparty/man-pages.git] / man3 / clearenv.3
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 2016-03-15 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 clearenv \- clear the environment
29 .SH SYNOPSIS
30 .nf
31 .B #include <stdlib.h>
32 .sp
33 .B "int clearenv(void);"
34 .fi
35 .sp
36 .in -4n
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
39 .in
40 .sp
41 .BR clearenv ():
42 /* Glibc since 2.19: */ _DEFAULT_SOURCE
43 || /* Glibc versions <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
44 .SH DESCRIPTION
45 The
46 .BR clearenv ()
47 function clears the environment of all name-value
48 pairs and sets the value of the external variable
49 .I environ
50 to NULL.
51 After this call, new variables can be added to the environment using
52 .BR putenv (3)
53 and
54 .BR setenv (3).
55 .SH RETURN VALUE
56 The
57 .BR clearenv ()
58 function returns zero on success, and a nonzero
59 value on failure.
60 .\" Most versions of UNIX return -1 on error, or do not even have errors.
61 .\" Glibc info and the Watcom C library document "a nonzero value".
62 .SH VERSIONS
63 Available since glibc 2.0.
64 .SH ATTRIBUTES
65 For an explanation of the terms used in this section, see
66 .BR attributes (7).
67 .TS
68 allbox;
69 lb lb lb
70 l l l.
71 Interface Attribute Value
72 T{
73 .BR clearenv ()
74 T} Thread safety MT-Unsafe const:env
75 .TE
76
77 .SH CONFORMING TO
78 Various UNIX variants (DG/UX, HP-UX, QNX, ...).
79 POSIX.9 (bindings for FORTRAN77).
80 POSIX.1-1996 did not accept
81 .BR clearenv ()
82 and
83 .BR putenv (3),
84 but changed its mind and scheduled these functions for some
85 later issue of this standard (cf. B.4.6.1).
86 However, POSIX.1-2001
87 adds only
88 .BR putenv (3),
89 and rejected
90 .BR clearenv ().
91 .SH NOTES
92 On systems where
93 .BR clearenv ()
94 is unavailable, the assignment
95 .nf
96
97 environ = NULL;
98
99 .fi
100 will probably do.
101
102 The
103 .BR clearenv ()
104 function may be useful in security-conscious applications that want to
105 precisely control the environment that is passed to programs
106 executed using
107 .BR exec (3).
108 The application would do this by first clearing the environment
109 and then adding select environment variables.
110
111 Note that the main effect of
112 .BR clearenv ()
113 is to adjust the value of the pointer
114 .BR environ (7);
115 this function does not erase the contents of the buffers
116 containing the environment definitions.
117
118 The DG/UX and Tru64 man pages write: If
119 .I environ
120 has been modified by anything other than the
121 .BR putenv (3),
122 .BR getenv (3),
123 or
124 .BR clearenv ()
125 functions, then
126 .BR clearenv ()
127 will return an error and the process environment will remain unchanged.
128 .\" .LP
129 .\" HP-UX has a ENOMEM error return.
130 .SH SEE ALSO
131 .BR getenv (3),
132 .BR putenv (3),
133 .BR setenv (3),
134 .BR unsetenv (3),
135 .BR environ (7)