9 #include "resourcesconfig.h" 12 #if defined(HAVE_UNISTD_H) && defined(STDC_HEADERS) 24 #define MAXPATHLEN 1024 28 #define ABSOLUTE_FILENAME_P(fname) (fname[0] == '/') 36 static char * omFindExec_link (
const char *name,
char* executable)
46 if (ABSOLUTE_FILENAME_P(name))
49 if (! access (name, X_OK))
51 strcpy(executable, name);
53 strcat(executable,
".exe");
60 if (((name[0] ==
'.') && (name[1] ==
'/')) ||
61 ((name[0] ==
'.') && (name[1] ==
'.') && (name[2] ==
'/')) ||
62 strchr(name,
'/') !=
NULL)
74 if (! access(tbuf, X_OK))
76 strcpy(executable, tbuf);
78 strcat(executable,
".exe");
89 if (p ==
NULL || strlen(p) < 2)
93 extra = (
char*)
malloc((search !=
NULL ? strlen(search) : 0) + 3);
95 if (search !=
NULL) strcat(extra, search);
111 while (*p && *p !=
':')
115 if ((tbuf[0] ==
'.' && tbuf[1] ==
'\0') || tbuf[0] ==
'\0') {
125 if (tbuf[strlen(tbuf)-1] !=
'/') strcat(tbuf,
"/");
129 if (! access (tbuf, F_OK))
135 strcpy(executable, tbuf);
137 strcat(executable,
".exe");
158 static int my_readlink(
const char* name,
char*
buf,
size_t bufsize)
163 if ((ret = readlink(name, buf2, bufsize)) > 0)
166 if (*name ==
'/' && *buf2 !=
'/')
168 char*
last = strrchr(name,
'/');
170 while (&(name[i]) != last)
177 strcpy(&(buf[i]), buf2);
188 #define MAX_LINK_LEVEL 10 192 static int full_readlink(
const char* name,
char* buf,
size_t bufsize)
196 if ((ret=my_readlink(name, buf, bufsize)) > 0)
204 if ((ret2 = my_readlink(buf, buf2,
MAXPATHLEN)) > 0)
216 while (i<MAX_LINK_LEVEL);
222 char * _omFindExec (
const char *name,
char* exec);
224 char*
omFindExec(
const char *name,
char* exec)
227 if (strstr(name,
".exe") ==
NULL)
233 ret = _omFindExec(buf, exec);
234 if (ret !=
NULL)
return ret;
236 return _omFindExec(name, exec);
239 #define _omFindExec omFindExec 242 char * _omFindExec (
const char *name,
char* exec)
244 char * link = omFindExec_link(name, exec);
248 if (link ==
NULL && (ret=full_readlink(name, buf,
MAXPATHLEN)) > 0)
251 link = omFindExec_link(buf, exec);
253 if (link !=
NULL && (ret=full_readlink(link, buf,
MAXPATHLEN)) > 0)
255 char *p = strrchr(link,
'/');
258 if(p!=
NULL) *(p+1)=
'\0';
int search(const CFArray &A, const CanonicalForm &F, int i, int j)
search for F in A between index i and j
int status int void * buf
void * malloc(size_t size)
char name(const Variable &v)
char * omFindExec(const char *name, char *exec)