#include "findfile.h"

int findfile(char *fName) {
	char *path = strdup(getenv("PATH"));
	char *dir;
	int ret = 0;

	dir = strtok(path, ":");
	while (dir) {
		struct stat buf;

		char *fullPath = (char *)malloc(strlen(dir) + strlen(fName) + 2);
		sprintf(fullPath, "%s/%s", dir, fName);

		if (!stat(fullPath,&buf)) {
			if (S_IXOTH & buf.st_mode) 
				ret = 1;
		}
			
		free(fullPath);

		dir = strtok(NULL, ":");
	}

	free(path);

	return ret;
}



syntax highlighted by Code2HTML, v. 0.9.1