2013-05-18 00:17:19 +08:00
|
|
|
//===-- sanitizer_common_libcdep.cc ---------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is shared between AddressSanitizer and ThreadSanitizer
|
|
|
|
// run-time libraries.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "sanitizer_common.h"
|
2014-02-26 17:06:59 +08:00
|
|
|
#include "sanitizer_flags.h"
|
2013-05-18 00:17:19 +08:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
bool PrintsToTty() {
|
|
|
|
MaybeOpenReportFile();
|
2013-05-29 22:11:44 +08:00
|
|
|
return internal_isatty(report_fd) != 0;
|
2013-05-18 00:17:19 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 21:31:03 +08:00
|
|
|
bool PrintsToTtyCached() {
|
|
|
|
// FIXME: Add proper Windows support to AnsiColorDecorator and re-enable color
|
|
|
|
// printing on Windows.
|
|
|
|
if (SANITIZER_WINDOWS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
static int cached = 0;
|
|
|
|
static bool prints_to_tty;
|
|
|
|
if (!cached) { // Not thread-safe.
|
|
|
|
prints_to_tty = PrintsToTty();
|
|
|
|
cached = 1;
|
|
|
|
}
|
|
|
|
return prints_to_tty;
|
|
|
|
}
|
2014-02-26 17:06:59 +08:00
|
|
|
|
|
|
|
bool ColorizeReports() {
|
|
|
|
const char *flag = common_flags()->color;
|
|
|
|
return internal_strcmp(flag, "always") == 0 ||
|
|
|
|
(internal_strcmp(flag, "auto") == 0 && PrintsToTtyCached());
|
|
|
|
}
|
2013-05-18 00:17:19 +08:00
|
|
|
} // namespace __sanitizer
|