Skip to content

Instantly share code, notes, and snippets.

@nopcoder
Created December 22, 2008 16:09
Show Gist options
  • Save nopcoder/39031 to your computer and use it in GitHub Desktop.
Save nopcoder/39031 to your computer and use it in GitHub Desktop.
path = getenv("PATH");
if (path != NULL) {
path = strdup(path);
for (dir = strtok(path, ":"); dir != NULL; dir = strtok(NULL, ":")) {
strcpy(candidate, dir);
strcat(candidate, "/");
strcat(candidate, argv[0]);
if (access(candidate, X_OK) == 0) {
printf("executable is '%s' (from PATH).\n", candidate);
return 0;
}
}
free(path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment