summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-11-02 09:38:47 +0000
committerAlexey Samsonov <samsonov@google.com>2012-11-02 09:38:47 +0000
commitf3457cb9c3e1ddbbea07ee97b22ca387687b72e0 (patch)
tree918eef5674fe71afc4937003898f8658f0be215e
parentac8564e7ce11e31b1d29e92dbbcfa1a5d36bc596 (diff)
downloadcompiler-rt-f3457cb9c3e1ddbbea07ee97b22ca387687b72e0.tar.gz
[Sanitizer] Use kStderrFd constant instead of hardcoded 2
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@167291 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/sanitizer_common/sanitizer_common.cc19
-rw-r--r--lib/sanitizer_common/sanitizer_libc.h3
-rw-r--r--lib/sanitizer_common/sanitizer_win.cc2
-rw-r--r--lib/tsan/rtl/tsan_flags.cc2
4 files changed, 15 insertions, 11 deletions
diff --git a/lib/sanitizer_common/sanitizer_common.cc b/lib/sanitizer_common/sanitizer_common.cc
index e6526f524..96db316d1 100644
--- a/lib/sanitizer_common/sanitizer_common.cc
+++ b/lib/sanitizer_common/sanitizer_common.cc
@@ -18,7 +18,7 @@ namespace __sanitizer {
// By default, dump to stderr. If report_fd is kInvalidFd, try to obtain file
// descriptor by opening file in report_path.
-static fd_t report_fd = 2;
+static fd_t report_fd = kStderrFd;
static char report_path[4096]; // Set via __sanitizer_set_report_path.
static void (*DieCallback)(void);
@@ -54,7 +54,7 @@ void RawWrite(const char *buffer) {
if (report_fd == kInvalidFd) {
fd_t fd = internal_open(report_path, true);
if (fd == kInvalidFd) {
- report_fd = 2;
+ report_fd = kStderrFd;
Report("ERROR: Can't open file: %s\n", report_path);
Die();
}
@@ -147,21 +147,22 @@ extern "C" {
void __sanitizer_set_report_path(const char *path) {
if (!path) return;
uptr len = internal_strlen(path);
- if (len > sizeof(__sanitizer::report_path) - 100) {
+ if (len > sizeof(report_path) - 100) {
Report("ERROR: Path is too long: %c%c%c%c%c%c%c%c...\n",
path[0], path[1], path[2], path[3],
path[4], path[5], path[6], path[7]);
Die();
}
- internal_snprintf(__sanitizer::report_path,
- sizeof(__sanitizer::report_path), "%s.%d", path, GetPid());
- __sanitizer::report_fd = kInvalidFd;
+ internal_snprintf(report_path, sizeof(report_path), "%s.%d", path, GetPid());
+ report_fd = kInvalidFd;
}
void __sanitizer_set_report_fd(int fd) {
- if (__sanitizer::report_fd > 2 && __sanitizer::report_fd != kInvalidFd)
- internal_close(__sanitizer::report_fd);
- __sanitizer::report_fd = fd;
+ if (report_fd != kStdoutFd &&
+ report_fd != kStderrFd &&
+ report_fd != kInvalidFd)
+ internal_close(report_fd);
+ report_fd = fd;
}
} // extern "C"
diff --git a/lib/sanitizer_common/sanitizer_libc.h b/lib/sanitizer_common/sanitizer_libc.h
index ec0b06130..af16cff5d 100644
--- a/lib/sanitizer_common/sanitizer_libc.h
+++ b/lib/sanitizer_common/sanitizer_libc.h
@@ -55,6 +55,9 @@ int internal_munmap(void *addr, uptr length);
// I/O
typedef int fd_t;
const fd_t kInvalidFd = -1;
+const fd_t kStdinFd = 0;
+const fd_t kStdoutFd = 1;
+const fd_t kStderrFd = 2;
int internal_close(fd_t fd);
fd_t internal_open(const char *filename, bool write);
uptr internal_read(fd_t fd, void *buf, uptr count);
diff --git a/lib/sanitizer_common/sanitizer_win.cc b/lib/sanitizer_common/sanitizer_win.cc
index dbacc5a64..8919341f0 100644
--- a/lib/sanitizer_common/sanitizer_win.cc
+++ b/lib/sanitizer_common/sanitizer_win.cc
@@ -163,7 +163,7 @@ uptr internal_read(fd_t fd, void *buf, uptr count) {
}
uptr internal_write(fd_t fd, const void *buf, uptr count) {
- if (fd != 2)
+ if (fd != kStderrFd)
UNIMPLEMENTED();
HANDLE err = GetStdHandle(STD_ERROR_HANDLE);
if (err == 0)
diff --git a/lib/tsan/rtl/tsan_flags.cc b/lib/tsan/rtl/tsan_flags.cc
index a854d7aa6..eb3de9ef6 100644
--- a/lib/tsan/rtl/tsan_flags.cc
+++ b/lib/tsan/rtl/tsan_flags.cc
@@ -47,7 +47,7 @@ void InitializeFlags(Flags *f, const char *env) {
f->strip_path_prefix = "";
f->suppressions = "";
f->exitcode = 66;
- f->log_fileno = 2;
+ f->log_fileno = kStderrFd;
f->atexit_sleep_ms = 1000;
f->verbosity = 0;
f->profile_memory = "";