diff options
Diffstat (limited to 'sdk/other/search.c')
-rw-r--r-- | sdk/other/search.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sdk/other/search.c b/sdk/other/search.c new file mode 100644 index 0000000..15963bf --- /dev/null +++ b/sdk/other/search.c @@ -0,0 +1,46 @@ +/* + * File path search routines. + * $Id$ + * Copyright (c) 1997 by Tycho Softworks. + * For conditions of distribution and reuse see product license. + */ + +#include <other/files.h> +#include <other/string.h> +#include <std/process.h> + +#ifdef QNX +#define PATHMARK "!" +#endif + +#ifndef PATHMARK +#define PATHMARK ":" +#endif + +char *search(const char *path, const char *file) +{ + static char buf[PATH_MAX + 1]; + char pbuf[PATH_MAX + 1]; + char *p; + + if(!path) + return NULL; + + strcpy(pbuf, path); + + p = strtok(pbuf, PATHMARK); + + while(p) + { + if(*p) + fncat(strcpy(buf, p), file); + else + strcpy(buf, file); + if(isfile(buf)) + return buf; + p = strtok(NULL, PATHMARK); + } + return NULL; +} + + |