*** empty log message ***
authorewt <devnull@localhost>
Mon, 27 Jul 1998 18:53:42 +0000 (18:53 +0000)
committerewt <devnull@localhost>
Mon, 27 Jul 1998 18:53:42 +0000 (18:53 +0000)
CVS patchset: 2194
CVS date: 1998/07/27 18:53:42

popt/CHANGES
popt/findme.c [new file with mode: 0644]
popt/findme.h [new file with mode: 0644]

index 3525827..04ae84c 100644 (file)
@@ -4,6 +4,8 @@
          trouble)
        - added test script
        - added support for exec
+       - removed support for *_POPT_ALIASES env variable -- it was a bad
+         idea
 
 1.0 -> 1.1
        - moved to autoconf (Fred Fish)
diff --git a/popt/findme.c b/popt/findme.c
new file mode 100644 (file)
index 0000000..f2e764e
--- /dev/null
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#if HAVE_ALLOCA_H
+# include <alloca.h>
+#endif
+
+#include "findme.h"
+
+char * findProgramPath(char * argv0) {
+    char * path = getenv("PATH");
+    char * pathbuf;
+    char * start, * chptr;
+    char * buf;
+
+    /* If there is a / in the argv[0], it has to be an absolute
+       path */
+    if (strchr(argv0, '/'))
+       return strdup(argv0);
+
+    if (!path) return NULL;
+
+    start = pathbuf = alloca(strlen(path) + 1);
+    buf = malloc(strlen(path) + strlen(argv0) + 2);
+    strcpy(pathbuf, path);
+
+    chptr = NULL;
+    do {
+       if ((chptr = strchr(start, ':')))
+           *chptr = '\0';
+       sprintf(buf, "%s/%s", start, argv0);
+
+       if (access(buf, X_OK))
+           return buf;
+
+       if (chptr) 
+           start = chptr + 1;
+       else
+           start = NULL;
+    } while (start && *start);
+
+    free(buf);
+
+    return NULL;
+}
diff --git a/popt/findme.h b/popt/findme.h
new file mode 100644 (file)
index 0000000..b4f790a
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef H_FINDME
+#define H_FINDME
+
+char * findProgramPath(char * argv0);
+
+#endif