diff options
Diffstat (limited to 'src/pathexec.c')
-rw-r--r-- | src/pathexec.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/src/pathexec.c b/src/pathexec.c index 2c1e7d1..343b4ba 100644 --- a/src/pathexec.c +++ b/src/pathexec.c @@ -1,11 +1,13 @@ +#include "pathexec.h" + #include <unistd.h> + #include "alloc.h" -#include "error.h" -#include "stralloc.h" -#include "str.h" #include "byte.h" #include "env.h" -#include "pathexec.h" +#include "error.h" +#include "str.h" +#include "stralloc.h" /** @file pathexec.c @@ -17,25 +19,25 @@ static stralloc plus; static stralloc tmp; -int pathexec_env(const char *s,const char *t) +int pathexec_env(const char *s, const char *t) { if (!s) return 1; - if (!stralloc_copys(&tmp,s)) return 0; + if (!stralloc_copys(&tmp, s)) return 0; if (t) { - if (!stralloc_cats(&tmp,"=")) return 0; - if (!stralloc_cats(&tmp,t)) return 0; + if (!stralloc_cats(&tmp, "=")) return 0; + if (!stralloc_cats(&tmp, t)) return 0; } if (!stralloc_0(&tmp)) return 0; - return stralloc_cat(&plus,&tmp); + return stralloc_cat(&plus, &tmp); } int pathexec_multienv(stralloc *sa) { if (!sa) return 1; - return stralloc_cat(&plus,sa); + return stralloc_cat(&plus, sa); } -void pathexec(char * const *argv) +void pathexec(char *const *argv) { char **e; unsigned int elen; @@ -44,51 +46,47 @@ void pathexec(char * const *argv) unsigned int split; unsigned int t; - if (!stralloc_cats(&plus,"")) return; + if (!stralloc_cats(&plus, "")) return; elen = 0; - for (i = 0; environ[i]; ++i) - ++elen; + for (i = 0; environ[i]; ++i) ++elen; for (i = 0; i < plus.len; ++i) - if (!plus.s[i]) - ++elen; + if (!plus.s[i]) ++elen; - e = (char **) alloc((elen + 1) * sizeof(char *)); + e = (char **)alloc((elen + 1) * sizeof(char *)); if (!e) return; elen = 0; - for (i = 0; environ[i]; ++i) - e[elen++] = environ[i]; + for (i = 0; environ[i]; ++i) e[elen++] = environ[i]; j = 0; for (i = 0; i < plus.len; ++i) if (!plus.s[i]) { - split = str_chr(plus.s + j,'='); + split = str_chr(plus.s + j, '='); for (t = 0; t < elen; ++t) - if (byte_equal(plus.s + j,split,e[t])) + if (byte_equal(plus.s + j, split, e[t])) if (e[t][split] == '=') { --elen; e[t] = e[elen]; break; } - if (plus.s[j + split]) - e[elen++] = plus.s + j; + if (plus.s[j + split]) e[elen++] = plus.s + j; j = i + 1; } e[elen] = 0; - pathexec_run(*argv,argv,e); + pathexec_run(*argv, argv, e); alloc_free(e); } -void pathexec_run(const char *file,char *const *argv,char *const *envp) +void pathexec_run(const char *file, char *const *argv, char *const *envp) { char *path; unsigned int split; int savederrno; - if (file[str_chr(file,'/')]) { - execve(file,argv,envp); + if (file[str_chr(file, '/')]) { + execve(file, argv, envp); return; } @@ -97,15 +95,15 @@ void pathexec_run(const char *file,char *const *argv,char *const *envp) savederrno = 0; for (;;) { - split = str_chr(path,':'); - if (!stralloc_copyb(&tmp,path,split)) return; + split = str_chr(path, ':'); + if (!stralloc_copyb(&tmp, path, split)) return; if (!split) - if (!stralloc_cats(&tmp,".")) return; - if (!stralloc_cats(&tmp,"/")) return; - if (!stralloc_cats(&tmp,file)) return; + if (!stralloc_cats(&tmp, ".")) return; + if (!stralloc_cats(&tmp, "/")) return; + if (!stralloc_cats(&tmp, file)) return; if (!stralloc_0(&tmp)) return; - execve(tmp.s,argv,envp); + execve(tmp.s, argv, envp); if (errno != ENOENT) { savederrno = errno; if ((errno != EACCES) && (errno != EPERM) && (errno != EISDIR)) return; |