cvs.delorie.com/djgpp/doc/libc/libc_686.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

searchpath

Syntax

 
#include <dir.h>
 
char * searchpath(const char *file);

Description

Given a name of a file in file, searches for that file in a list of directories, including the current working directory and directories listed in the PATH environment variable, and if found, returns the file name with leading directories prepended, so that the result can be used to access the file (e.g. by calling open or stat).

If file includes a drive letter or leading directories, searchpath first tries that name unaltered, in case it is already a fully-qualified path, or is relative to the current working directory. If that fails, it tries every directory in PATH in turn. Note that this will find e.g. `c:/foo/bar/baz.exe' if you pass `bar/baz.exe' to searchpath and if `c:/foo' is mentioned in PATH.

Return Value

When successfull, the function returns a pointer to a static buffer where the full pathname of the found file is stored. Otherwise, it returns NULL. (The static buffer is overwritten on each call.)

Portability

ANSI/ISO C No
POSIX No

This function is provided for compatibility with Borland's library. However, note that the Borland version disregards the leading directories altogether and searches for the basename only. Thus, it will happily find e.g. `c:/foo/bar/baz.exe', even if the directory `c:/foo/bar' doesn't exist, provided that `baz.exe' is somewhere on your PATH. We think this is a bug, so DJGPP's implementation doesn't behave like that.

Example

 
  printf("%s was found as %s\n", argv[1], searchpath(argv[1]));
 


  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004