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 "copyright.h" |
11 |
+ |
|
12 |
|
#include "standard.h" |
13 |
|
|
14 |
|
#include "paths.h" |
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); |