8 |
|
* getpath.c - function to search for file in a list of directories |
9 |
|
*/ |
10 |
|
|
11 |
+ |
#include "standard.h" |
12 |
+ |
|
13 |
|
#include "paths.h" |
14 |
|
|
15 |
< |
#define NULL 0 |
14 |
< |
|
15 |
< |
#ifndef NIX |
15 |
> |
#ifndef NIX |
16 |
|
#include <pwd.h> |
17 |
|
extern struct passwd *getpwnam(); |
18 |
|
#endif |
19 |
|
|
20 |
– |
extern char *strcpy(), *strcat(), *getenv(); |
20 |
|
|
22 |
– |
|
21 |
|
char * |
22 |
|
getpath(fname, searchpath, mode) /* expand fname, return full path */ |
23 |
|
register char *fname; |
24 |
|
register char *searchpath; |
25 |
|
int mode; |
26 |
|
{ |
27 |
< |
#ifndef NIX |
27 |
> |
#ifndef NIX |
28 |
|
struct passwd *pwent; |
29 |
|
#endif |
30 |
|
static char pname[MAXPATH]; |
33 |
|
if (fname == NULL) |
34 |
|
return(NULL); |
35 |
|
|
36 |
+ |
pname[0] = '\0'; /* check for full specification */ |
37 |
|
switch (*fname) { |
38 |
|
CASEDIRSEP: /* relative to root */ |
39 |
|
case '.': /* relative to cwd */ |
40 |
|
strcpy(pname, fname); |
41 |
< |
return(pname); |
41 |
> |
break; |
42 |
|
#ifndef NIX |
43 |
|
case '~': /* relative to home directory */ |
44 |
|
fname++; |
47 |
|
return(NULL); |
48 |
|
strcpy(pname, cp); |
49 |
|
strcat(pname, fname); |
50 |
< |
return(pname); |
50 |
> |
break; |
51 |
|
} |
52 |
|
cp = pname; /* user */ |
53 |
|
do |
58 |
|
return(NULL); |
59 |
|
strcpy(pname, pwent->pw_dir); |
60 |
|
strcat(pname, fname); |
61 |
< |
return(pname); |
61 |
> |
break; |
62 |
|
#endif |
63 |
|
} |
64 |
+ |
if (pname[0]) /* got it, check access if search requested */ |
65 |
+ |
return(searchpath==NULL||access(pname,mode)==0 ? pname : NULL); |
66 |
|
|
67 |
|
if (searchpath == NULL) { /* don't search */ |
68 |
|
strcpy(pname, fname); |