8 |
|
* getpath.c - function to search for file in a list of directories |
9 |
|
*/ |
10 |
|
|
11 |
< |
#include "paths.h" |
11 |
> |
#include "paths.h" |
12 |
|
|
13 |
|
#define NULL 0 |
14 |
|
|
17 |
|
extern struct passwd *getpwnam(); |
18 |
|
#endif |
19 |
|
|
20 |
< |
extern char *strcpy(), *strcat(); |
20 |
> |
extern char *strcpy(), *strcat(), *getenv(); |
21 |
|
|
22 |
|
|
23 |
|
char * |
29 |
|
#ifndef NIX |
30 |
|
struct passwd *pwent; |
31 |
|
#endif |
32 |
< |
static char pname[256]; |
32 |
> |
static char pname[MAXPATH]; |
33 |
|
register char *cp; |
34 |
|
|
35 |
|
if (fname == NULL) |
36 |
|
return(NULL); |
37 |
|
|
38 |
|
switch (*fname) { |
39 |
< |
case DIRSEP: /* relative to root */ |
39 |
> |
CASEDIRSEP: /* relative to root */ |
40 |
|
case '.': /* relative to cwd */ |
41 |
|
strcpy(pname, fname); |
42 |
|
return(pname); |
43 |
|
#ifndef NIX |
44 |
|
case '~': /* relative to home directory */ |
45 |
|
fname++; |
46 |
< |
if (*fname == '\0' || *fname == DIRSEP) { /* ours */ |
46 |
> |
if (*fname == '\0' || ISDIRSEP(*fname)) { /* ours */ |
47 |
|
if ((cp = getenv("HOME")) == NULL) |
48 |
|
return(NULL); |
49 |
|
strcpy(pname, cp); |
53 |
|
cp = pname; /* user */ |
54 |
|
do |
55 |
|
*cp++ = *fname++; |
56 |
< |
while (*fname && *fname != DIRSEP); |
56 |
> |
while (*fname && !ISDIRSEP(*fname)); |
57 |
|
*cp = '\0'; |
58 |
|
if ((pwent = getpwnam(pname)) == NULL) |
59 |
|
return(NULL); |
72 |
|
cp = pname; |
73 |
|
while (*searchpath && (*cp = *searchpath++) != PATHSEP) |
74 |
|
cp++; |
75 |
< |
if (cp > pname && cp[-1] != DIRSEP) |
75 |
> |
if (cp > pname && !ISDIRSEP(cp[-1])) |
76 |
|
*cp++ = DIRSEP; |
77 |
|
strcpy(cp, fname); |
78 |
|
if (access(pname, mode) == 0) /* file accessable? */ |