Changeset ea35599 in git
- Timestamp:
- May 20, 1998, 6:23:49 PM (25 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- c052d0e90b6b3a3f99f5c70b1e90b6d8f020865e
- Parents:
- 651b4646ed535e81739179b38258acc14067c72b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/find_exec.c
r651b46 rea35599 51 51 searches the directories in the PATH environment variable if PROG 52 52 has no directory components. */ 53 char * 54 find_executable (const char *name) 53 #ifndef HAVE_READLINK 54 char * find_executable (const char *name) 55 #else 56 char * find_executable_link (const char *name) 57 #endif 55 58 { 56 59 char *search; … … 60 63 61 64 if (ABSOLUTE_FILENAME_P(name)) { 62 /* If we can execute the named file, and it is normal, then return it. */ 63 if (! access (name, X_OK)) { 64 struct stat stat_temp; 65 char buf[MAXPATHLEN]; 66 int ret; 67 68 if (stat (name, &stat_temp)) 69 return 0; 70 71 #ifdef HAVE_READLINK 72 if( (ret=readlink(name, buf, MAXPATHLEN))>0) { 73 char *p = strrchr(name, '/'); 74 if(p!=NULL) *(p+1)='\0'; 75 buf[ret]='\0'; 76 if(buf[0]=='/') return(find_executable(buf)); 77 strcat(name, buf); 78 return(find_executable(name)); 79 } 80 #endif /* HAVE_READLINK */ 81 #ifndef STAT_MACROS_BROKEN 82 if (! S_ISREG(stat_temp.st_mode)) 83 return 0; 84 #endif 85 65 /* If we can execute the named file then return it. */ 66 if (! access (name, X_OK)) 86 67 return copy_of (name); 87 }88 68 } 89 69 else { … … 185 165 strcat (tbuf, name); 186 166 187 /* If we can execute the named file, and it is normal,then return it. */167 /* If we can execute the named file, then return it. */ 188 168 if (! access (tbuf, X_OK)) { 189 struct stat stat_temp;190 char buf[MAXPATHLEN];191 int ret;192 193 if (stat (tbuf, &stat_temp))194 continue;195 196 #ifdef HAVE_READLINK197 if( (ret=readlink(tbuf, buf, MAXPATHLEN))>0) {198 char *p = strrchr(tbuf, '/');199 if(p!=NULL) *(p+1)='\0';200 buf[ret]='\0';201 if(buf[0]=='/') return(find_executable(buf));202 strcat(tbuf, buf);203 return(find_executable(tbuf));204 }205 #endif /* HAVE_READLINK */206 #ifndef STAT_MACROS_BROKEN207 if (! S_ISREG(stat_temp.st_mode))208 continue;209 #endif210 169 #ifdef WINNT 211 170 if (extra != NULL) … … 219 178 return NULL; 220 179 } 180 181 #ifdef HAVE_READLINK 182 char * find_executable (const char *name) 183 { 184 char * link = find_executable_link(name); 185 char buf[MAXPATHLEN]; 186 int ret; 187 188 if (link == NULL && (ret=readlink(name, buf, MAXPATHLEN)) > 0) 189 { 190 buf[ret] ='\0'; 191 link = find_executable_link(buf); 192 } 193 // follow, if we have a link 194 if (link != NULL && (ret=readlink(link, buf, MAXPATHLEN)) > 0) 195 { 196 char *p = strrchr(link, '/'); 197 char *executable; 198 199 200 if(p!=NULL) *(p+1)='\0'; 201 buf[ret]='\0'; 202 203 if (buf[0] != '/') 204 { 205 executable = (char*) AllocL(strlen(link) + ret); 206 strcpy(executable, link); 207 strcat(executable, buf); 208 } 209 else 210 { 211 executable = copy_of(buf); 212 } 213 214 FreeL(link); 215 return executable; 216 } 217 return link; 218 } 219 #endif /* HAVE_READLINK */ 221 220 222 221 #else
Note: See TracChangeset
for help on using the changeset viewer.