aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/other/search.c
blob: 15963bf2fc54d2d6058b339bebe8ac23410dd760 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}