9 #include "singular_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)
43 if (ABSOLUTE_FILENAME_P(name))
46 if (! access (name, X_OK))
48 strcpy(executable, name);
54 if (((name[0] ==
'.') && (name[1] ==
'/')) ||
55 ((name[0] ==
'.') && (name[1] ==
'.') && (name[2] ==
'/')) ||
56 strchr(name,
'/') !=
NULL)
68 if (! access(tbuf, X_OK))
70 strcpy(executable, tbuf);
90 while (*p && *p !=
':')
94 if ((tbuf[0] ==
'.' && tbuf[1] ==
'\0') || tbuf[0] ==
'\0') {
104 if (tbuf[strlen(tbuf)-1] !=
'/') strcat(tbuf,
"/");
108 if (! access (tbuf, F_OK))
110 strcpy(executable, tbuf);
130 static int my_readlink(
const char* name,
char*
buf,
size_t bufsize)
135 if ((ret = readlink(name, buf2, bufsize)) > 0)
138 if (*name ==
'/' && *buf2 !=
'/')
140 char*
last = strrchr(name,
'/');
142 while (&(name[i]) != last)
149 strcpy(&(buf[i]), buf2);
160 #define MAX_LINK_LEVEL 10 164 static int full_readlink(
const char* name,
char* buf,
size_t bufsize)
168 if ((ret=my_readlink(name, buf, bufsize)) > 0)
176 if ((ret2 = my_readlink(buf, buf2,
MAXPATHLEN)) > 0)
188 while (i<MAX_LINK_LEVEL);
195 char * _omFindExec (
const char *name,
char* exec);
196 char*
omFindExec(
const char *name,
char* exec)
199 if (strstr(name,
".exe") ==
NULL)
205 ret = _omFindExec(buf, exec);
206 if (ret !=
NULL)
return ret;
208 return _omFindExec(name, exec);
211 #define _omFindExec omFindExec 214 char * _omFindExec (
const char *name,
char* exec)
216 char * link = omFindExec_link(name, exec);
220 if (link ==
NULL && (ret=full_readlink(name, buf,
MAXPATHLEN)) > 0)
223 link = omFindExec_link(buf, exec);
225 if (link !=
NULL && (ret=full_readlink(link, buf,
MAXPATHLEN)) > 0)
227 char *p = strrchr(link,
'/');
230 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
char name(const Variable &v)
char * omFindExec(const char *name, char *exec)