From c0d30e86e32307a700ed8d2f7fd33040e3cf4c63 Mon Sep 17 00:00:00 2001 From: ewt Date: Wed, 29 Jul 1998 16:02:54 +0000 Subject: [PATCH] added poptSetExecPath() CVS patchset: 2206 CVS date: 1998/07/29 16:02:54 --- popt/popt.c | 20 +++++++++++++++++++- popt/popt.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/popt/popt.c b/popt/popt.c index f71e773..7d16614 100644 --- a/popt/popt.c +++ b/popt/popt.c @@ -47,6 +47,8 @@ struct poptContext_s { int finalArgvCount; int finalArgvAlloced; struct execEntry * doExec; + char * execPath; + int execAbsolute; }; #ifndef HAVE_STRERROR @@ -61,6 +63,12 @@ static char * strerror(int errno) { } #endif +void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) { + if (con->execPath) free(con->execPath); + con->execPath = strdup(con->execPath); + con->execAbsolute = allowAbsolute; +} + poptContext poptGetContext(char * name, int argc, char ** argv, const struct poptOption * options, int flags) { poptContext con = malloc(sizeof(*con)); @@ -184,10 +192,20 @@ static int handleAlias(poptContext con, char * longName, char shortName, static void execCommand(poptContext con) { char ** argv; int pos = 0; + char * script = con->doExec->script; argv = malloc(sizeof(*argv) * (6 + con->numLeftovers + con->finalArgvCount)); - argv[pos++] = con->doExec->script; + + if (!con->execAbsolute && strchr(script, '/')) return; + + if (!strchr(script, '/') && con->execPath) { + argv[pos] = alloca(strlen(con->execPath) + strlen(script) + 2); + sprintf(argv[pos], "%s/%s", con->execPath, script); + } else { + argv[pos] = script; + } + pos++; argv[pos] = findProgramPath(con->os->argv[0]); if (argv[pos]) pos++; diff --git a/popt/popt.h b/popt/popt.h index 55e63a5..850a8cd 100644 --- a/popt/popt.h +++ b/popt/popt.h @@ -65,5 +65,6 @@ int poptReadDefaultConfig(poptContext con, int useEnv); the same as " and both may include \ quotes */ int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr); const char * poptStrerror(const int error); +void poptSetExecPath(poptContext con, const char * path, int allowAbsolute); #endif -- 2.7.4