| 34 | char * omFindExec (const char *name, char* executable) |
| 35 | #else |
| 36 | static char * omFindExec_link (const char *name, char* executable) |
| 37 | #endif |
| 38 | { |
| 39 | char *search; |
| 40 | char *p; |
| 41 | char tbuf[MAXPATHLEN]; |
| 42 | |
| 43 | if (ABSOLUTE_FILENAME_P(name)) |
| 44 | { |
| 45 | /* If the named file exists then return it. */ |
| 46 | if (! access (name, F_OK)) //think of libSingular.so as main binary |
| 47 | // r or x is required |
| 48 | { |
| 49 | strcpy(executable, name); |
| 50 | return executable; |
| 51 | } |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | if (((name[0] == '.') && (name[1] == '/')) || |
| 56 | ((name[0] == '.') && (name[1] == '.') && (name[2] == '/')) || |
| 57 | strchr(name, '/') != NULL) |
| 58 | { |
| 59 | short ok=1; |
| 60 | |
| 61 | #ifdef HAVE_GETCWD |
| 62 | if (getcwd (tbuf, MAXPATHLEN)==NULL) ok=0; |
| 63 | #else |
| 64 | # ifdef HAVE_GETWD |
| 65 | if (getwd (tbuf)==NULL) ok=0; |
| 66 | # endif |
| 67 | #endif |
| 68 | strcat (tbuf, "/"); |
| 69 | strcat (tbuf, name); |
| 70 | if (ok && ! access(tbuf, F_OK)) |
| 71 | { |
| 72 | strcpy(executable, tbuf); |
| 73 | return executable; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | |
| 78 | search = getenv("PATH"); |
| 79 | /* for winnt under msdos, cwd is implictly in the path */ |
| 80 | p = search; |
| 81 | |
| 82 | if (p != NULL) |
| 83 | { |
| 84 | while (1) |
| 85 | { |
| 86 | char *next; |
| 87 | next = tbuf; |
| 88 | |
| 89 | /* Copy directory name into [tbuf]. */ |
| 90 | /* This is somewhat tricky: empty names mean cwd, w.r.t. some |
| 91 | shell spec */ |
| 92 | while (*p && *p != ':') |
| 93 | *next ++ = *p ++; |