CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CloseCoutSentry.cc
Go to the documentation of this file.
1 #include "../interface/CloseCoutSentry.h"
2 
3 #include <cstdio>
4 #include <unistd.h>
5 
6 bool CloseCoutSentry::open_ = true;
10 
12  silent_(silent), stdOutIsMine_(false)
13 {
14  if (silent_) {
15  if (open_) {
16  open_ = false;
17  if (fdOut_ == 0 && fdErr_ == 0) {
18  fdOut_ = dup(1);
19  fdErr_ = dup(2);
20  }
21  freopen("/dev/null", "w", stdout);
22  freopen("/dev/null", "w", stderr);
23  } else {
24  silent_ = false;
25  }
26  }
27 }
28 
30 {
31  clear();
32 }
33 
35 {
36  if (stdOutIsMine_) { fclose(trueStdOut_); trueStdOut_ = 0; }
37  if (silent_) {
38  reallyClear();
39  silent_ = false;
40  }
41 }
42 
44 {
45  if (fdOut_ != fdErr_) {
46  char buf[50];
47  sprintf(buf, "/dev/fd/%d", fdOut_); freopen(buf, "w", stdout);
48  sprintf(buf, "/dev/fd/%d", fdErr_); freopen(buf, "w", stderr);
49  open_ = true;
50  fdOut_ = fdErr_ = 0;
51  }
52 }
53 
55 {
56  reallyClear();
57 }
58 
60 {
61  if (open_) return stdout;
62  if (trueStdOut_) return trueStdOut_;
63  stdOutIsMine_ = true;
64  char buf[50];
65  sprintf(buf, "/dev/fd/%d", fdOut_); trueStdOut_ = fopen(buf, "w");
66  return trueStdOut_;
67 }
static FILE * trueStdOut_
static int fdErr_
static void breakFree()
static void reallyClear()
CloseCoutSentry(bool silent=true)
static bool open_
static int fdOut_