searchpath
Searches the DOS path for a file.
Defined in header <dir.h>
Syntax
#include <dir.h>
char *searchpathCconst char *file);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ |
Remarks
searchpath attempts to locate file, searching along the DOS path, which is the PATH=... string in the environment. A pointer to the complete path-name string is returned as the function value.
searchpath searches for the file in the current directory of the current drive first. If the file is not found there, the PATH environment variable is fetched, and each directory in the path is searched in turn until the file is found, or the path is exhausted.
When the file is located, a string is returned containing the full path name. This string can be used in a call to access the file (for example, with fopen or exec...).
The string returned is located in a static buffer and is overwritten on each subsequent call to searchpath.
Return value
searchpath returns a pointer to a file name string if the file is successfully located; otherwise, searchpath returns null.
See also
Example
#include <stdio.h>
#include <dir.h>
int main(void)
{
char *p;
/* looks for TLINK and returns a pointer to the path */
p = searchpath ("TLINK.EXE"),•
printf ("Search for TLINK.EXE : %s\n", p);
/* looks for non-existent file */
p = searchpath ("NOTEXIST.FIL"),•
printf("Search for NOTEXIST.FIL : %s\n", p);
return 0;
Program output
Search for TLINK.EXE : C:\BIN\TLINK.EXE
Search for NOTEXIST.FIL : (IWLL)
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/dir.h/searchpath/
· short form /3.1/searchpath/