Index: lib/Support/Unix/Process.inc =================================================================== --- lib/Support/Unix/Process.inc +++ lib/Support/Unix/Process.inc @@ -331,9 +331,8 @@ // We manually declare these extern functions because finding the correct // headers from various terminfo, curses, or other sources is harder than // writing their specs down. +extern struct term *cur_term; extern "C" int setupterm(char *term, int filedes, int *errret); -extern "C" struct term *set_curterm(struct term *termp); -extern "C" int del_curterm(struct term *termp); extern "C" int tigetnum(char *capname); #endif @@ -347,7 +346,7 @@ MutexGuard G(*TermColorMutex); int errret = 0; - if (setupterm((char *)nullptr, fd, &errret) != 0) + if (!cur_term && setupterm(nullptr, fd, &errret) != 0) // Regardless of why, if we can't get terminfo, we shouldn't try to print // colors. return false; @@ -365,16 +364,7 @@ // // The 'tigetnum' routine returns -2 or -1 on errors, and might return 0 if // the terminfo says that no colors are supported. - bool HasColors = tigetnum(const_cast("colors")) > 0; - - // Now extract the structure allocated by setupterm and free its memory - // through a really silly dance. - struct term *termp = set_curterm((struct term *)nullptr); - (void)del_curterm(termp); // Drop any errors here. - - // Return true if we found a color capabilities for the current terminal. - if (HasColors) - return true; + return tigetnum(const_cast("colors")) > 0; #endif // Otherwise, be conservative.