[Sanitizer] Use kStderrFd constant instead of hardcoded 2
authorAlexey Samsonov <samsonov@google.com>
Fri, 2 Nov 2012 09:38:47 +0000 (09:38 +0000)
committerAlexey Samsonov <samsonov@google.com>
Fri, 2 Nov 2012 09:38:47 +0000 (09:38 +0000)
llvm-svn: 167291

compiler-rt/lib/sanitizer_common/sanitizer_common.cc
compiler-rt/lib/sanitizer_common/sanitizer_libc.h
compiler-rt/lib/sanitizer_common/sanitizer_win.cc
compiler-rt/lib/tsan/rtl/tsan_flags.cc

index e6526f5..96db316 100644 (file)
@@ -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"
index ec0b061..af16cff 100644 (file)
@@ -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);
index dbacc5a..8919341 100644 (file)
@@ -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)
index a854d7a..eb3de9e 100644 (file)
@@ -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 = "";