4 |
|
/* |
5 |
|
* getpath.c - function to search for file in a list of directories |
6 |
|
* |
7 |
< |
* External symbols declared in rtio.h |
7 |
> |
* External symbols declared in paths.h |
8 |
|
*/ |
9 |
|
|
10 |
|
#include "copyright.h" |
11 |
|
|
12 |
|
#include <ctype.h> |
13 |
|
|
14 |
– |
#include "rtio.h" |
14 |
|
#include "paths.h" |
15 |
|
|
16 |
|
|
32 |
|
char *cp; |
33 |
|
int i; |
34 |
|
|
35 |
< |
if (fname == NULL) { return(NULL); } |
35 |
> |
if (!fname | (fname == pname)) |
36 |
> |
return(fname); |
37 |
|
|
38 |
|
pname[0] = '\0'; /* check for full specification */ |
39 |
|
|
40 |
< |
if (ISABS(fname)) { /* absolute path */ |
40 |
> |
if (ISABS(fname)) { /* absolute path */ |
41 |
|
strlcpy(pname, fname, sizeof(pname)); |
42 |
|
} else { |
43 |
|
switch (*fname) { |
44 |
< |
case '.': /* relative to cwd */ |
44 |
> |
case '.': /* relative to cwd */ |
45 |
|
strlcpy(pname, fname, sizeof(pname)); |
46 |
|
break; |
47 |
< |
case '~': /* relative to home directory */ |
47 |
> |
case '~': /* relative to home directory */ |
48 |
|
fname++; |
49 |
|
cp = uname; |
50 |
|
for (i = 0; i < sizeof(uname) && *fname |
60 |
|
if (pname[0]) /* got it, check access if search requested */ |
61 |
|
return(!searchpath || access(pname,mode)==0 ? pname : NULL); |
62 |
|
|
63 |
< |
if (!searchpath) { /* no search */ |
63 |
> |
if (!searchpath) { /* no search? */ |
64 |
|
strlcpy(pname, fname, sizeof(pname)); |
65 |
|
return(pname); |
66 |
|
} |
100 |
|
char *cp; |
101 |
|
char fname[PATH_MAX]; |
102 |
|
|
103 |
< |
if (ffname == NULL) |
104 |
< |
return(NULL); |
103 |
> |
if (!ffname | (ffname == fname)) |
104 |
> |
return(ffname); |
105 |
|
|
106 |
|
/* if we have a dot in the string, we assume there is a file name |
107 |
|
extension present */ |
108 |
|
/* XXX We'd better test for .exe/.bat/.etc explicitly */ |
109 |
< |
if (!(mode & X_OK) || (strrchr(ffname, '.') != NULL)) { |
109 |
> |
if (!(mode & X_OK) || strchr(ffname, '.') > ffname) { |
110 |
|
return core_getpath(ffname, searchpath, mode); |
111 |
|
} |
112 |
|
|