Header File
stdlib.h
Category
Miscellaneous Routines
Prototype
char *_searchenv(const char *file, const char *varname, char *buf);
char *_wsearchenv(const wchar_t *file, const wchar_t *varname, wchar_t *buf);
Description
Looks for a file, using an environment variable as the search path.
_searchenv attempts to locate file, searching along the path specified by the operating system environment variable varname. Typical environment variables that contain paths are PATH, LIB, and INCLUDE.
_searchenv searches for the file in the current directory of the current drive first. If the file is not found there, the environment variable varname is fetched, and each directory in the path it specifies is searched in turn until the file is found, or the path is exhausted.
When the file is located, the full path name is stored in the buffer pointed to by buf. This string can be used in a call to access the file (for example, with fopen or exec...). The buffer is assumed to be large enough to store any possible file name. If the file cannot be successfully located, an empty string (consisting of only a null character) will be stored at buf.
Return Value
None.
Example
#include <stdio.h> #include <stdlib.h> char buf[_MAX_PATH]; int main(void) { /* ILINK32 will be found in your installation directory */ _searchenv("ILINK32.EXE","PATH",buf); if (buf[0] == '\0') printf("ILINK32.EXE not found\n"); else printf("ILINK32.EXE found in %s\n", buf); /* looks for nonexistent file */ _searchenv("NOTEXIST.FIL","PATH",buf); if (buf[0] == '\0') printf("NOTEXIST.FIL not found\n"); else printf("NOTEXIST.FIL found in %s\n", buf); return 0; }
Portability
|
POSIX |
Win32 |
ANSI C |
ANSI C++ |
_searchenv |
|
+ |
|
|
_wsearchenv |
|
NT only |
|
|
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|