#define INCL_DOSQUEUES USHORT rc = DosScanEnv(EnvVarName, ResultPointer); PSZ EnvVarName; /* Environment variable name string */ PSZ FAR * ResultPointer; /* Search result pointer (returned) */ USHORT rc; /* return code */
Example
The following example scans the environment segment for the PATH variable and prints its value. It then searches the path given by inserting the current directory into the value of the PATH variable for the file named "cmd.exe", and prints the full filename.
#define INCL_DOS #include <os2.h> #define ENVVARNAME "PATH" /* Environment variable name */ #define FILENAME "cmd.exe" /* File for which to search */ #define SEARCH_CUR_DIRECTORY 0x03 /* Search control - current dir., */ /* then environment variable */ main() { PSZ FAR *ResultPointer; /* Environment scan result pointer (returned) */ BYTE ResultBuffer[128]; /* Path search result (returned) */ USHORT rc; /* return code */ /** Scan environment segment for PATH; notice the far-string pointer **/ /** specification ("%Fs") used to print. **/ if(!(rc=DosScanEnv(ENVVARNAME, /* Environment variable name */ &ResultPointer))) /* Scan result pointer (returned) */ printf("%s is %Fs\n", ENVVARNAME, ResultPointer); /** Search current directory + PATH variable for "cmd.exe" **/ if(!(rc=DosSearchPath(SEARCH_CUR_DIRECTORY, /* Search control vector */ ENVVARNAME, /* Search path reference string */ FILENAME, /* File name string */ ResultBuffer, /* Search result (returned) */ sizeof(ResultBuffer)))) /* Length of search result */ printf("Found desired file -- %s\n", ResultBuffer); }