Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // Common/StdOutStream.cpp
3 #include "StdAfx.h"
5 #include <tchar.h>
7 #include "StdOutStream.h"
8 #include "Common/IntToString.h"
9 #include "Common/StringConvert.h"
11 static const char kNewLineChar = '\n';
13 static const char *kFileOpenMode = "wt";
15 CStdOutStream g_StdOut(stdout);
16 CStdOutStream g_StdErr(stderr);
18 bool CStdOutStream::Open(const char *fileName)
19 {
20 Close();
21 _stream = fopen(fileName, kFileOpenMode);
22 _streamIsOpen = (_stream != 0);
23 return _streamIsOpen;
24 }
26 bool CStdOutStream::Close()
27 {
28 if(!_streamIsOpen)
29 return true;
30 _streamIsOpen = (fclose(_stream) != 0);
31 return !_streamIsOpen;
32 }
34 bool CStdOutStream::Flush()
35 {
36 if(!_streamIsOpen)
37 return false;
38 return (fflush(_stream) == 0);
39 }
41 CStdOutStream::~CStdOutStream ()
42 {
43 Close();
44 }
46 CStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream &))
47 {
48 (*aFunction)(*this);
49 return *this;
50 }
52 CStdOutStream & endl(CStdOutStream & outStream)
53 {
54 return outStream << kNewLineChar;
55 }
57 CStdOutStream & CStdOutStream::operator<<(const char *string)
58 {
59 fputs(string, _stream);
60 return *this;
61 }
63 CStdOutStream & CStdOutStream::operator<<(const wchar_t *string)
64 {
65 *this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP);
66 return *this;
67 }
69 CStdOutStream & CStdOutStream::operator<<(char c)
70 {
71 fputc(c, _stream);
72 return *this;
73 }
75 CStdOutStream & CStdOutStream::operator<<(int number)
76 {
77 char textString[32];
78 ConvertInt64ToString(number, textString);
79 return operator<<(textString);
80 }
82 CStdOutStream & CStdOutStream::operator<<(UInt64 number)
83 {
84 char textString[32];
85 ConvertUInt64ToString(number, textString);
86 return operator<<(textString);
87 }