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