diff options
author | Stefan Metzmacher <metze@samba.org> | 2013-11-13 14:17:32 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2013-11-13 14:18:52 +0100 |
commit | f087a8e2b81fae82fa571ef09d2d1cb682cc8ff8 (patch) | |
tree | d4a6b14a1594958150b733180d995b5c32025017 /ctdb/lib/popt/findme.c | |
parent | e80a5aba3db8e81173fa443991e08ef4a300ea5c (diff) | |
parent | 25f3c8b5269863aadbe72e304da7012782ef5b25 (diff) | |
download | samba-f087a8e2b81fae82fa571ef09d2d1cb682cc8ff8.tar.gz samba-f087a8e2b81fae82fa571ef09d2d1cb682cc8ff8.tar.xz samba-f087a8e2b81fae82fa571ef09d2d1cb682cc8ff8.zip |
Merge branch 'master' of ctdb into 'master' of samba
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'ctdb/lib/popt/findme.c')
-rw-r--r-- | ctdb/lib/popt/findme.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/ctdb/lib/popt/findme.c b/ctdb/lib/popt/findme.c new file mode 100644 index 00000000000..a950e50018b --- /dev/null +++ b/ctdb/lib/popt/findme.c @@ -0,0 +1,50 @@ +/** \ingroup popt + * \file popt/findme.c + */ + +/* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING + file accompanying popt source distributions, available from + ftp://ftp.rpm.org/pub/rpm/dist. */ + +#include "system.h" +#include "findme.h" + +const char * findProgramPath(const char * argv0) { + char * path = getenv("PATH"); + char * pathbuf; + char * start, * chptr; + char * buf; + + if (argv0 == NULL) return NULL; /* XXX can't happen */ + /* If there is a / in the argv[0], it has to be an absolute path */ + if (strchr(argv0, '/')) + return xstrdup(argv0); + + if (path == NULL) return NULL; + + start = pathbuf = alloca(strlen(path) + 1); + buf = malloc(strlen(path) + strlen(argv0) + sizeof("/")); + if (buf == NULL) return NULL; /* XXX can't happen */ + strcpy(pathbuf, path); + + chptr = NULL; + /*@-branchstate@*/ + 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); + /*@=branchstate@*/ + + free(buf); + + return NULL; +} |