amatrix

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
git clone git://git.kocotian.pl/amatrix.git
Log | Files | Refs | README | LICENSE

commit 93fd3575a04b61e8b7fbc227de9c91891bd9a085
parent de94079f19982a10e5634e8926e82f4c6f1ab15d
Author: Yu-Jie Lin <livibetter@gmail.com>
Date:   Fri,  2 Feb 2018 16:25:52 +0800

only restore TERM when needed, and use putenv (#36)

Only when `-f` force `TERM=linux` is used and there was a change of
`$TERM`.

Since, the forcing the TERM uses `putenv(3)`, replaced `system(3)` call
to be consistent and to get rid of compilation warning of ignoring the
return value.

Note: using `setenv(3)` is cleaner, as we only needs to keep preserved
TERM value, no need to format a `"TERM=foobar"` string.  However, as the
comment L388 stated that `putenv` is more common on non-Linux, so
keeping this way.
Diffstat:
Mcmatrix.c | 10++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/cmatrix.c b/cmatrix.c @@ -297,7 +297,7 @@ int main(int argc, char *argv[]) { int pause = 0; char *oldtermname; - char *syscmd = NULL; + char *oldterm = NULL; time_t t; srand((unsigned) time(&t)); @@ -745,9 +745,11 @@ if (console) { } napms(update * 10); } - syscmd = nmalloc(sizeof (char *) * (strlen(oldtermname) + 15)); - sprintf(syscmd, "putenv TERM=%s", oldtermname); - system(syscmd); + if (force && strcmp(oldtermname, getenv("TERM"))) { + oldterm = nmalloc(sizeof (char *) * (strlen(oldtermname) + 6)); + sprintf(oldterm, "TERM=%s", oldtermname); + putenv(oldterm); + } finish(); }