![]() |
![]() |
![]() |
![]() |
Search the directories listed in an environment variable
#include <stdlib.h> void searchenv( const char* name, const char* env_var, char* buffer );
![]() |
The searchenv() function doesn't search the current directory unless it's specified in the environment variable. |
libc
The searchenv() function searches for the file specified by name in the list of directories assigned to the environment variable specified by env_var.
![]() |
Use pathfind() or pathfind_r() instead of this function. |
#include <stdio.h> #include <stdlib.h> #include <limits.h> void display_help( FILE *fp ) { printf( "display_help T.B.I.\n" ); } int main( void ) { FILE *help_file; char full_path[ PATH_MAX ]; searchenv( "lib_ref.html", "PATH", full_path ); if( full_path[0] == '\0' ) { printf( "Unable to find help file\n" ); } else { help_file = fopen( full_path, "r" ); display_help( help_file ); fclose( help_file ); } return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
The searchenv() function manipulates the environment pointed to by the global environ variable.
getenv(), pathfind(), pathfind_r(), setenv()
![]() |
![]() |
![]() |
![]() |