| 83 | #endif |
| 84 | |
| 85 | static char *find_file_in_path(char *to, const char *name) |
| 86 | { |
| 87 | char *path,*pos,dir[2]; |
| 88 | const char *ext=""; |
| 89 | |
| 90 | if (!(path=getenv("PATH"))) |
| 91 | return NullS; |
| 92 | dir[0]=FN_LIBCHAR; dir[1]=0; |
| 93 | #ifdef PROGRAM_EXTENSION |
| 94 | if (!fn_ext(name)[0]) |
| 95 | ext=PROGRAM_EXTENSION; |
| 96 | #endif |
| 97 | |
| 98 | for (pos=path ; (pos=strchr(pos,PATH_SEP)) ; path= ++pos) |
| 99 | { |
| 100 | if (path != pos) |
| 101 | { |
| 102 | strxmov(strnmov(to,path,(uint) (pos-path)),dir,name,ext,NullS); |
| 103 | if (!access(to,F_OK)) |
| 104 | { |
| 105 | to[(uint) (pos-path)+1]=0; /* Return path only */ |
| 106 | return to; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | #ifdef __WIN__ |
| 111 | to[0]=FN_CURLIB; |
| 112 | strxmov(to+1,dir,name,ext,NullS); |
| 113 | if (!access(to,F_OK)) /* Test in current dir */ |
| 114 | { |
| 115 | to[2]=0; /* Leave ".\" */ |
| 116 | return to; |
| 117 | } |
| 118 | #endif |
| 119 | return NullS; /* File not found */ |
| 120 | } |