diff options
Diffstat (limited to 'g10/exec.c')
-rw-r--r-- | g10/exec.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/g10/exec.c b/g10/exec.c index 46990f29c..db440f656 100644 --- a/g10/exec.c +++ b/g10/exec.c @@ -51,7 +51,7 @@ int exec_write(struct exec_info **info,const char *program, int exec_read(struct exec_info *info) { return G10ERR_GENERAL; } int exec_finish(struct exec_info *info) { return G10ERR_GENERAL; } -int set_exec_path(const char *path) { return G10ERR_GENERAL; } +int set_exec_path(const char *path,int method) { return G10ERR_GENERAL; } #else /* ! NO_EXEC */ @@ -91,13 +91,31 @@ static int win_system(const char *command) } #endif -int set_exec_path(const char *path) +/* method==0 to replace current $PATH, and 1 to append to current + $PATH. */ +int set_exec_path(const char *path,int method) { - /* Notice that path is never freed. That is intentional due to the - way putenv() works. */ - char *p=m_alloc(5+strlen(path)+1); + char *p,*curpath=NULL; + size_t curlen=0; + + if(method==1 && (curpath=getenv("PATH"))) + curlen=strlen(curpath)+1; + + p=m_alloc(5+curlen+strlen(path)+1); strcpy(p,"PATH="); + + if(curpath) + { + strcat(p,curpath); + strcat(p,":"); + } + strcat(p,path); + + /* Notice that path is never freed. That is intentional due to the + way putenv() works. This leaks a few bytes if we call + set_exec_path multiple times. */ + if(putenv(p)!=0) return G10ERR_GENERAL; else @@ -313,7 +331,7 @@ int exec_write(struct exec_info **info,const char *program, BUG(); #ifdef FIXED_EXEC_PATH - set_exec_path(FIXED_EXEC_PATH); + set_exec_path(FIXED_EXEC_PATH,0); #endif *info=m_alloc_clear(sizeof(struct exec_info)); |