Get the value of an environment variable
#include <stdlib.h> char* getenv( const char* name );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
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.
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 | Yes |
The getenv() function manipulates the environment pointed to by the global environ variable.