Get the value of an environment variable
#include <stdlib.h> char* getenv( const char* name );
libc
The getenv() function searches the environment list for a string in the form name=value and returns a pointer to a string containing the value for the specified name. The matching is case-sensitive.
| The returned string must not be modified by the calling process. |
A pointer to the value assigned to name, or NULL if name wasn't found in the environment.
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
char* path;
path = getenv( "INCLUDE" );
if( path != NULL ) {
printf( "INCLUDE=%s\n", path );
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | No |
| Thread | No |
The getenv() function manipulates the environment pointed to by the global environ variable.
clearenv(), environ, execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), putenv(), searchenv(), setenv(), spawn*() functions, system()