summaryrefslogtreecommitdiff
path: root/popt/popt.c
diff options
context:
space:
mode:
authorewt <devnull@localhost>1998-07-29 16:02:54 +0000
committerewt <devnull@localhost>1998-07-29 16:02:54 +0000
commitc0d30e86e32307a700ed8d2f7fd33040e3cf4c63 (patch)
treebe9ac66bb78cfd603065595a03f85e5743ddfe79 /popt/popt.c
parenta9363dbdd1fedd4c7491884a25e5f0ae4b9fc5ad (diff)
downloadlibrpm-tizen-c0d30e86e32307a700ed8d2f7fd33040e3cf4c63.tar.gz
librpm-tizen-c0d30e86e32307a700ed8d2f7fd33040e3cf4c63.tar.bz2
librpm-tizen-c0d30e86e32307a700ed8d2f7fd33040e3cf4c63.zip
added poptSetExecPath()
CVS patchset: 2206 CVS date: 1998/07/29 16:02:54
Diffstat (limited to 'popt/popt.c')
-rw-r--r--popt/popt.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/popt/popt.c b/popt/popt.c
index f71e77315..7d16614d4 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++;