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, F_OK))
49 strcpy(executable, name);
55 if (((name[0] ==
'.') && (name[1] ==
'/')) ||
56 ((name[0] ==
'.') && (name[1] ==
'.') && (name[2] ==
'/')) ||
57 strchr(name,
'/') !=
NULL)
69 if (! access(tbuf, F_OK))
71 strcpy(executable, tbuf);
91 while (*p && *p !=
':')
95 if ((tbuf[0] ==
'.' && tbuf[1] ==
'\0') || tbuf[0] ==
'\0') {
105 if (tbuf[strlen(tbuf)-1] !=
'/') strcat(tbuf,
"/");
109 if (! access (tbuf, F_OK))
111 strcpy(executable, tbuf);
131 static int my_readlink(
const char* name,
char*
buf,
size_t bufsize)
136 if ((ret = readlink(name, buf2, bufsize)) > 0)
139 if (*name ==
'/' && *buf2 !=
'/')
141 char*
last = strrchr(name,
'/');
143 while (&(name[i]) != last)
150 strcpy(&(buf[i]), buf2);
161 #define MAX_LINK_LEVEL 10 165 static int full_readlink(
const char* name,
char* buf,
size_t bufsize)
169 if ((ret=my_readlink(name, buf, bufsize)) > 0)
177 if ((ret2 = my_readlink(buf, buf2,
MAXPATHLEN)) > 0)
189 while (i<MAX_LINK_LEVEL);
196 char * _omFindExec (
const char *name,
char* exec);
197 char*
omFindExec(
const char *name,
char* exec)
200 if (strstr(name,
".exe") ==
NULL)
206 ret = _omFindExec(buf, exec);
207 if (ret !=
NULL)
return ret;
209 return _omFindExec(name, exec);
212 #define _omFindExec omFindExec 215 char * _omFindExec (
const char *name,
char* exec)
217 char * link = omFindExec_link(name, exec);
221 if (link ==
NULL && (ret=full_readlink(name, buf,
MAXPATHLEN)) > 0)
224 link = omFindExec_link(buf, exec);
226 if (link !=
NULL && (ret=full_readlink(link, buf,
MAXPATHLEN)) > 0)
228 char *p = strrchr(link,
'/');
231 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)