summaryrefslogtreecommitdiff
path: root/indexing/addindex/scanpath.c
blob: 9541ebf55fd3ea2952d4e83d6e8a1e080fbe6182 (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
47
48
49
50
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <malloc.h>

extern char *ProgName;

static char *InDir(path,name)
char *path;
char *name;
{
	char *s;

	if ((s = strchr(path,':')) != (char *)0) 
		*s == '\0';	
	if (*path == '\0')
		return (char *)0;
	if ((s = malloc(2 + strlen(path) + strlen(name))) == (char *)0) {
		(void) fprintf(stderr,
			"%s: cannot malloc for %s/%s\n",
			ProgName,path,name
		);
		return (char *)0;
	} 
	(void) sprintf(s,"%s/%s",path,name);
	if (access(s,F_OK) == 0)
		return s;
	(void) free(s);
	return (char *)0;
}

char *scanpath(path,name)
char *path;
char *name;
{
	char *s;

	if (path == (char *)0)
		return (char *)0;

	for (;;) {
		char *where;		

		if (where = InDir(path,name))
			return where;
		if ((s = strchr(path,':')) == (char *)0)
			return (char *)0;
		path = s+1;
	}	
}