- while(argc-- > 0 && *(argv++) != '\0' && strlen(*argv)) {
- for( test=path_list; (tmp=strchr(test, ':')) && (tmp+1)!=NULL; test=++tmp) {
- DIR *dir;
- *tmp='\0';
- //printf("Checking directory '%s'\n", test);
- dir = opendir(test);
- if (!dir)
- continue;
- while ((next = readdir(dir)) != NULL) {
- //printf("Checking file '%s'\n", next->d_name);
- if ((strcmp(next->d_name, *argv) == 0)) {
- printf("%s/%s\n", test, next->d_name);
- exit(TRUE);
- }
+ /* Replace colons with zeros in path_parsed and count them */
+ for(i=strlen(path_list); i > 0; i--)
+ if (path_list[i]==':') {
+ path_list[i]=0;
+ count++;
+ }
+
+ while(argc-- > 0) {
+ path_n = path_list;
+ argv++;
+ found = 0;
+ for (i = 0; i < count; i++) {
+ char buf[strlen(path_n)+1+strlen(*argv)];
+ strcpy (buf, path_n);
+ strcat (buf, "/");
+ strcat (buf, *argv);
+ if (stat (buf, &filestat) == 0
+ && filestat.st_mode & S_IXUSR)
+ {
+ printf ("%s\n", buf);
+ found = 1;
+ break;