From 0f4a66f5d3a9128cf5fdc3d06463ab1c3aeef92a Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Thu, 10 Nov 2016 11:15:23 -0500 Subject: [PATCH] Fix setupterm error evaluation. --- MasterPassword/C/mpw-util.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/MasterPassword/C/mpw-util.c b/MasterPassword/C/mpw-util.c index 9e96775b..32efa1d8 100644 --- a/MasterPassword/C/mpw-util.c +++ b/MasterPassword/C/mpw-util.c @@ -129,16 +129,19 @@ const char *mpw_hex_l(uint32_t number) { #ifdef COLOR static int putvari; static char *putvarc = NULL; -static int termsetup = ERR; +static int termsetup; static int initputvar() { if (!isatty(STDERR_FILENO)) return 0; if (putvarc) free(putvarc); - if (termsetup != OK) - setupterm(NULL, STDERR_FILENO, &termsetup); - if (termsetup != OK) - return 0; + if (!termsetup) { + int status; + if (! (termsetup = (setupterm(NULL, STDERR_FILENO, &status) == OK && status == 1))) { + wrn( "Terminal doesn't support color (setupterm errno %d).\n", status ); + return 0; + } + } putvarc=(char *)calloc(256, sizeof(char)); putvari=0;