GETENV(3C) Standard C Library Functions GETENV(3C)

getenv, secure_getenvreturn value for environment name

Standard C Library (libc, -lc)

#include <stdlib.h>

char *
getenv(const char *name);

char *
secure_getenv(const char *name);

The () function searches the environment list (see environ(7)) for a string of the form = and, if the string is present, returns a pointer to the value in the current environment.

The () function behaves similarly; however, evaluates the conditions that the process was executed under. If the process was executed in a way that it is considered setuid, setgid, or raised its privileges, that is the issetugid(2) function would return true, then the secure_getenv() function will always return NULL. This is designed for programs that want to ensure they do not trust potentially malicious user input while executed with elevated capabilities. In all other respects, the secure_getenv() function is identical to the getenv() function.

If successful, the getenv() and secure_getenv() functions return a pointer to the value in the current environment; otherwise, they returns a NULL pointer.

The getenv() function can be safely called from a multithreaded application. Care must be exercised when using both getenv() and putenv(3C) in a multithreaded application. These functions examine and modify the environment list, which is shared by all threads in an application. The system prevents the list from being accessed simultaneously by two different threads. It does not, however, prevent two threads from successively accessing the environment list using getenv() or putenv(3C)

exec(2), issetugid(2), putenv(3C), attributes(7), environ(7), standards(7)

January 19, 2025 OmniOS