| Name | Description | Notes | Source | Availability | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
getenv() |
Get environment string | (·) | <stdlib.h> |
C89 | C90 | C95 | C99 | C11 | |||
getenv_s() |
Get environment string | ? | (·) | <stdlib.h> |
C11 | ||||||
The environment in which a C program is executing may provide to it a set of named environment strings which it can use to determine its behaviour.
#include <stdlib.h>
char *getenv(const char *name);
#define __STDC_WANT_ 1 #includeLIB_ EXT1__ <stdlib.h>errno_t getenv_s(size_t *lenp, char *val, rsize_t max, const char *name);
getenv
returns a pointer to the null-terminated environment string
identified by the null-terminated string name. If no such string is found, it returns
NULL. Although the string
appears to be modifiable, the result should not be modified,
so it's usually best to assign it straight to a const char * at
once.
getenv_s
does the same, but copies the environment string into the
array of max bytes starting at
val, including a null terminator, and
writes the number of bytes (excluding the null) to
*lenp, if lenp
is not null, and finally returns zero. If the string
(including the terminating null) is too long, or the named
string is not found, *lenp is set to
zero if lenp is not null, and the
function returns non-zero. val[0] is
also set to a null character if the named string is not found
and max is not zero.