1 #include "print.h"
2 #include <stdarg.h>
3 #include <algorithm>
4
5 const static char* name = "/dev/null";
6 static FILE* std_file = fopen(name, "w");
7
8 bool replace()
9 {
10 if (std_file) {
11 fflush(stdout);
12 std::swap(stdout->_fileno, std_file->_fileno);
13 return true;
14 }
15 return false;
16 }
17
18 ReplaceStdout::ReplaceStdout():
19 _ok(replace())
20 {
21 }
22
23 ReplaceStdout::~ReplaceStdout()
24 {
25 replace();
26 }
27
28 void print(const char* format, ...)
29 {
30 va_list args;
31 va_start(args, format);
32 vfprintf(1 == stdout->_fileno ? stdout : std_file,
33 format, args);
34 va_end(args);
35 }