Debian Codegraph @

upstream/debian-unstable/man3/getenv.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright 2007-2012, Michael Kerrisk <[email protected]>
4 .\" Copyright, the authors of the Linux man-pages project
5 .\"
6 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .\"
8 .TH getenv 3 2026-02-08 "Linux man-pages 6.18"
9 .SH NAME
10 getenv, secure_getenv \- get an environment variable
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc ,\~ \-lc )
14 .SH SYNOPSIS
15 .nf
16 .B #include <stdlib.h>
17 .P
18 .BI "char *getenv(const char *" name );
19 .BI "char *secure_getenv(const char *" name );
20 .fi
21 .P
22 .RS -4
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
25 .RE
26 .P
27 .BR secure_getenv ():
28 .nf
29 _GNU_SOURCE
30 .fi
31 .SH DESCRIPTION
32 The
33 .BR getenv ()
34 function searches the environment list to find the
35 environment variable
36 .IR name ,
37 and returns a pointer to the corresponding
38 .I value
39 string.
40 .P
41 The
42 .BR secure_getenv ()
43 function is just like
44 .BR getenv ()
45 except that it returns NULL in cases where "secure execution" is required.
46 Secure execution is required if one of the following conditions
47 was true when the program run by the calling process was loaded:
48 .IP \[bu] 3
49 the process's effective user ID did not match its real user ID or
50 the process's effective group ID did not match its real group ID
51 (typically this is the result of executing a set-user-ID or
52 set-group-ID program);
53 .IP \[bu]
54 the effective capability bit was set on the executable file;
55 or
56 .IP \[bu]
57 the process has a nonempty permitted capability set.
58 .P
59 Secure execution may also be required if triggered
60 by some Linux security modules.
61 .P
62 The
63 .BR secure_getenv ()
64 function is intended for use in general-purpose libraries
65 to avoid vulnerabilities that could occur if
66 set-user-ID or set-group-ID programs accidentally
67 trusted the environment.
68 .SH RETURN VALUE
69 The
70 .BR getenv ()
71 function returns a pointer to the value in the
72 environment, or NULL if there is no match.
73 .SH ATTRIBUTES
74 For an explanation of the terms used in this section, see
75 .BR attributes (7).
76 .TS
77 allbox;
78 lbx lb lb
79 l l l.
80 Interface Attribute Value
81 T{
82 .na
83 .nh
84 .BR getenv (),
85 .BR secure_getenv ()
86 T} Thread safety MT-Safe env
87 .TE
88 .SH STANDARDS
89 .TP
90 .BR getenv ()
91 C11, POSIX.1-2008.
92 .TP
93 .BR secure_getenv ()
94 POSIX.1-2024.
95 .SH HISTORY
96 .TP
97 .BR getenv ()
98 POSIX.1-2001, C89, C99, SVr4, 4.3BSD.
99 .TP
100 .BR secure_getenv ()
101 POSIX.1-2024, glibc 2.17.
102 .SH NOTES
103 The strings in the environment list are of the form
104 .IR name=value .
105 .P
106 As typically implemented,
107 .BR getenv ()
108 returns a pointer to a string within the environment list.
109 The caller must take care not to modify this string,
110 since that would change the environment of the process.
111 .P
112 The implementation of
113 .BR getenv ()
114 is not required to be reentrant.
115 The string pointed to by the return value of
116 .BR getenv ()
117 may be statically allocated,
118 and can be modified by a subsequent call to
119 .BR getenv (),
120 .BR putenv (3),
121 .BR setenv (3),
122 or
123 .BR unsetenv (3).
124 .P
125 The "secure execution" mode of
126 .BR secure_getenv ()
127 is controlled by the
128 .B AT_SECURE
129 flag contained in the auxiliary vector passed from the kernel to user space.
130 .SH SEE ALSO
131 .BR clearenv (3),
132 .BR getauxval (3),
133 .BR putenv (3),
134 .BR setenv (3),
135 .BR unsetenv (3),
136 .BR capabilities (7),
137 .BR environ (7)