1CLEARENV(3)                Linux Programmer's Manual               CLEARENV(3)
2
3
4

NAME

6       clearenv - clear the environment
7

SYNOPSIS

9       #include <stdlib.h>
10
11       int clearenv(void);
12
13   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15       clearenv():
16           /* Glibc since 2.19: */ _DEFAULT_SOURCE
17               || /* Glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
18

DESCRIPTION

20       The  clearenv() function clears the environment of all name-value pairs
21       and sets the value of the external variable  environ  to  NULL.   After
22       this  call,  new  variables  can  be  added  to  the  environment using
23       putenv(3) and setenv(3).
24

RETURN VALUE

26       The clearenv() function returns zero on success, and a nonzero value on
27       failure.
28

VERSIONS

30       Available since glibc 2.0.
31

ATTRIBUTES

33       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
34       tributes(7).
35
36       ┌────────────────────────────────┬───────────────┬─────────────────────┐
37Interface                       Attribute     Value               
38       ├────────────────────────────────┼───────────────┼─────────────────────┤
39clearenv()                      │ Thread safety │ MT-Unsafe const:env │
40       └────────────────────────────────┴───────────────┴─────────────────────┘
41

CONFORMING TO

43       Various UNIX variants (DG/UX, HP-UX, QNX, ...).  POSIX.9 (bindings  for
44       FORTRAN77).   POSIX.1-1996 did not accept clearenv() and putenv(3), but
45       changed its mind and scheduled these functions for some later issue  of
46       this   standard   (see  §B.4.6.1).   However,  POSIX.1-2001  adds  only
47       putenv(3), and rejected clearenv().
48

NOTES

50       On systems where clearenv() is unavailable, the assignment
51
52           environ = NULL;
53
54       will probably do.
55
56       The clearenv() function may be useful  in  security-conscious  applica‐
57       tions  that want to precisely control the environment that is passed to
58       programs executed using exec(3).  The  application  would  do  this  by
59       first clearing the environment and then adding select environment vari‐
60       ables.
61
62       Note that the main effect of clearenv() is to adjust the value  of  the
63       pointer  environ(7);  this  function does not erase the contents of the
64       buffers containing the environment definitions.
65
66       The DG/UX and Tru64 man pages write: If environ has  been  modified  by
67       anything  other than the putenv(3), getenv(3), or clearenv() functions,
68       then clearenv() will return an error and the process  environment  will
69       remain unchanged.
70

SEE ALSO

72       getenv(3), putenv(3), setenv(3), unsetenv(3), environ(7)
73

COLOPHON

75       This  page  is  part of release 5.13 of the Linux man-pages project.  A
76       description of the project, information about reporting bugs,  and  the
77       latest     version     of     this    page,    can    be    found    at
78       https://www.kernel.org/doc/man-pages/.
79
80
81
82Linux                             2021-03-22                       CLEARENV(3)
Impressum