Borland C++ reference

_searchenv

raw OCR

Searches an environment path for a file.

Defined in header <stdlib.h>

Syntax

#include <stdlib.h>
char *_searchenv(const  char *file, const char *varname, char *huf);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

_searchenv attempts to locate file, searching along the path specified by the DOS 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 huf. 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 filename. If the file cannot be successfully located, an empty string (consisting of only a null character) will be stored at buf.

Return value

None.

See also

Example

#include <stdio.h>
#include <stdlib.h>

char buf [_MAX_PATH];

int main (void)

   /* looks for TLINK  */
   _searchenv ("TLINK.EXE","PATH",buf);
   if (buf[0] ==  '\0')
      printf ("TLINK.EXE not found\n");
   else
      printf ("TLINK.EXE found in %s\n", buf);

   /* looks for non-existent  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;

Program   output

   TLINK.EXE found in C:\BIN\TLINK.EXE
   NOTEXIST.FIL not found

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • heading `searchenv` read as `_searchenv`