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