xref: /illumos-gate/usr/src/man/man3c/getenv.3c (revision 35e0963c135e57db23f111dfe9dbf1dae97a9fc3)
1'\"
2.\"  Copyright 1989 AT&T  Copyright (c) 2002, Sun Microsystems, Inc.  All Rights Reserved
3.\" Copyright 2025 Oxide Computer Company
4.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
5.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
6.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7.Dd January 19, 2025
8.Dt GETENV 3C
9.Os
10.Sh NAME
11.Nm getenv ,
12.Nm secure_getenv
13.Nd return value for environment name
14.Sh LIBRARY
15.Lb libc
16.Sh SYNOPSIS
17.In stdlib.h
18.Ft "char *"
19.Fo getenv
20.Fa "const char *name"
21.Fc
22.Ft "char *"
23.Fo secure_getenv
24.Fa "const char *name"
25.Fc
26.Sh DESCRIPTION
27The
28.Fn getenv
29function searches the environment list
30.Po
31see
32.Xr environ 7
33.Pc
34for a string of the form
35.Em name Ns = Ns Em Value
36and, if the string is present, returns a pointer to the
37.Em value
38in the current environment.
39.Pp
40The
41.Fn secure_getenv
42function behaves similarly; however, evaluates the conditions that the
43process was executed under.
44If the process was executed in a way that it is considered setuid,
45setgid, or raised its privileges, that is the
46.Xr issetugid 2
47function would return true, then the
48.Fn secure_getenv
49function will always return
50.Dv NULL .
51This is designed for programs that want to ensure they do not trust
52potentially malicious user input while executed with elevated
53capabilities.
54In all other respects, the
55.Fn secure_getenv
56function is identical to the
57.Fn getenv
58function.
59.Sh RETURN VALUES
60If successful, the
61.Fn getenv
62and
63.Fn secure_getenv
64functions return a pointer to the
65.Em value
66in the current environment; otherwise, they returns a
67.Dv NULL
68pointer.
69.Sh USAGE
70The
71.Fn getenv
72function can be safely called from a multithreaded application.
73Care must be exercised when using both
74.Fn getenv
75and
76.Xr putenv 3C
77in a multithreaded application.
78These functions examine and modify the environment list, which is shared by all
79threads in an application.
80The system prevents the list from being accessed simultaneously by two different
81threads.
82It does not, however, prevent two threads from successively accessing the
83environment list using
84.Fn getenv
85or
86.Xr putenv 3C
87.Sh INTERFACE STABILITY
88.Sy Committed
89.Sh MT-LEVEL
90.Sy Safe
91.Sh SEE ALSO
92.Xr exec 2 ,
93.Xr issetugid 2 ,
94.Xr putenv 3C ,
95.Xr attributes 7 ,
96.Xr environ 7 ,
97.Xr standards 7
98