X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=2be6772539647d56b1fb132e38c82d703792821d;hb=e8b18dd97b34d29670484b3850c315213f01dfa5;hp=3829e73836202e4d82699585c96a0fde0d5cd6c1;hpb=af75c433e56e74d2ad7a315d504a9303ea532f18;p=st.git diff --git a/st.c b/st.c index 3829e73..2be6772 100644 --- a/st.c +++ b/st.c @@ -247,7 +247,7 @@ static CSIEscape escseq; static int cmdfd; static pid_t pid; static Selection sel; -static char *opt_cmd = NULL; +static char **opt_cmd = NULL; static char *opt_title = NULL; static char *opt_class = NULL; @@ -545,13 +545,14 @@ die(const char *errstr, ...) { void execsh(void) { - char *args[] = {getenv("SHELL"), "-i", NULL}; - if(opt_cmd) - args[0] = opt_cmd, args[1] = NULL; - else - DEFAULT(args[0], SHELL); + char **args; + char *envshell = getenv("SHELL"); + + DEFAULT(envshell, "sh"); putenv("TERM="TNAME); + args = opt_cmd ? opt_cmd : (char*[]){envshell, "-i", NULL}; execvp(args[0], args); + exit(EXIT_FAILURE); } void @@ -630,7 +631,7 @@ ttyread(void) { } /* keep any uncomplete utf8 char for the next call */ - memcpy(buf, ptr, buflen); + memmove(buf, ptr, buflen); } void @@ -1851,12 +1852,15 @@ main(int argc, char *argv[]) { if(++i < argc) opt_class = argv[i]; break; case 'e': - if(++i < argc) opt_cmd = argv[i]; + if(++i < argc) opt_cmd = &argv[i]; break; case 'v': default: die(USAGE); } + /* -e eats every remaining arguments */ + if(opt_cmd) + break; } setlocale(LC_CTYPE, ""); tnew(80, 24);