Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2002-10-16 00:55:24 +0000
committerAlain Magloire2002-10-16 00:55:24 +0000
commita509b0baaa93383d96325665dee2a7fd80ca1577 (patch)
treea8d5de9cbf1aa8e265b14bc7ffe4b08dc487cbe4 /core/org.eclipse.cdt.core.linux
parent711b80c01d96445ef4da24abb7fb6903db6e6ff5 (diff)
downloadorg.eclipse.cdt-a509b0baaa93383d96325665dee2a7fd80ca1577.tar.gz
org.eclipse.cdt-a509b0baaa93383d96325665dee2a7fd80ca1577.tar.xz
org.eclipse.cdt-a509b0baaa93383d96325665dee2a7fd80ca1577.zip
Make it a Unix format. Check the path with access().
Diffstat (limited to 'core/org.eclipse.cdt.core.linux')
-rw-r--r--core/org.eclipse.cdt.core.linux/library/pfind.c147
1 files changed, 78 insertions, 69 deletions
diff --git a/core/org.eclipse.cdt.core.linux/library/pfind.c b/core/org.eclipse.cdt.core.linux/library/pfind.c
index 65de2a5cb16..d13dae5f0e2 100644
--- a/core/org.eclipse.cdt.core.linux/library/pfind.c
+++ b/core/org.eclipse.cdt.core.linux/library/pfind.c
@@ -1,69 +1,78 @@
-/*
- * pfind.c - Search for a binary in $PATH.
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-
-#ifndef PATH_MAX
-#define PATH_MAX 1024
-#endif
-
-
-char *pfind(const char *name)
-{
- char *tok;
- char *sp;
- char *path = getenv("PATH" );
- char FullPath[PATH_MAX+1];
-
- if (name == NULL) {
- fprintf(stderr, "pfind(): Null argument.\n");
- return NULL;
- }
-
- if (path == NULL || strlen( path ) <= 0) {
- fprintf(stderr, "Unable to get $PATH.\n");
- return NULL;
- }
-
- // The value return by getenv() is readonly */
- path = strdup(path);
-
- tok = strtok_r(path, ":", &sp);
- while (tok != NULL) {
- //strcpy(FullPath, tok);
- //strcat(FullPath, "/");
- //strcat(FullPath, name);
- snprintf(FullPath, sizeof(FullPath) - 1, "%s/%s", tok, name);
-
- if (access(FullPath, X_OK | R_OK) == 0) {
- free(path);
- return strdup(FullPath);
- }
-
- tok = strtok_r( NULL, ":", &sp );
- }
-
- free(path);
- return NULL;
-}
-
-#ifdef BUILD_WITH_MAIN
-int main(int argc, char **argv)
-{
- int i;
- char *fullpath;
-
- for (i=1; i<argc; i++) {
- fullpath = pfind(argv[i]);
- if (fullpath == NULL)
- printf("Unable to find %s in $PATH.\n", argv[i]);
- else
- printf("Found %s @ %s.\n", argv[i], fullpath);
- }
-}
-#endif
+/*
+ * pfind.c - Search for a binary in $PATH.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#ifndef PATH_MAX
+#define PATH_MAX 1024
+#endif
+
+
+char * pfind(const char *name)
+{
+ char *tok;
+ char *sp;
+ char *path;
+ char fullpath[PATH_MAX+1];
+
+ /* Sanity check. */
+ if (name == NULL) {
+ fprintf(stderr, "pfind(): Null argument.\n");
+ return NULL;
+ }
+
+ /* For absolute name or name with a path, check if it is an executable. */
+ if (name[0] == '/' || name[0] == '.') {
+ if (access(name, X_OK | R_OK) == 0) {
+ return strdup(name);
+ }
+ return NULL;
+ }
+
+ /* Search in the PATH environment. */
+ path = getenv("PATH" );
+
+ if (path == NULL || strlen(path) <= 0) {
+ fprintf(stderr, "Unable to get $PATH.\n");
+ return NULL;
+ }
+
+ /* The value return by getenv() is readonly */
+ path = strdup(path);
+
+ tok = strtok_r(path, ":", &sp);
+ while (tok != NULL) {
+ snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", tok, name);
+
+ if (access(fullpath, X_OK | R_OK) == 0) {
+ free(path);
+ return strdup(fullpath);
+ }
+
+ tok = strtok_r( NULL, ":", &sp );
+ }
+
+ free(path);
+ return NULL;
+}
+
+#ifdef BUILD_WITH_MAIN
+int main(int argc, char **argv)
+{
+ int i;
+ char *fullpath;
+
+ for (i=1; i<argc; i++) {
+ fullpath = pfind(argv[i]);
+ if (fullpath == NULL)
+ printf("Unable to find %s in $PATH.\n", argv[i]);
+ else
+ printf("Found %s @ %s.\n", argv[i], fullpath);
+ }
+}
+#endif

Back to the top