|
@@ -33,38 +33,47 @@
|
|
|
*/
|
|
|
/* copyright --> */
|
|
|
#include "console.h"
|
|
|
+#include "NullOutputFile.h"
|
|
|
+#ifdef __MINGW32__
|
|
|
+# include "WinConsoleFile.h"
|
|
|
+#else // !__MINGW32__
|
|
|
+# include "BufferedFile.h"
|
|
|
+#endif // !__MINGW32__
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
|
namespace global {
|
|
|
|
|
|
-#ifdef __MINGW32__
|
|
|
-const SharedHandle<WinConsoleFile>& cout()
|
|
|
+namespace {
|
|
|
+Console consoleCout;
|
|
|
+Console consoleCerr;
|
|
|
+};
|
|
|
+
|
|
|
+void initConsole(bool suppress)
|
|
|
{
|
|
|
- static SharedHandle<WinConsoleFile> f(new WinConsoleFile(STD_OUTPUT_HANDLE));
|
|
|
- return f;
|
|
|
-}
|
|
|
+ if(suppress) {
|
|
|
+ consoleCerr.reset(new NullOutputFile());
|
|
|
+ consoleCout.reset(new NullOutputFile());
|
|
|
+ } else {
|
|
|
+#ifdef __MINGW32__
|
|
|
+ consoleCout.reset(new WinConsoleFile(STD_OUTPUT_HANDLE));
|
|
|
+ consoleCerr.reset(new WinConsoleFile(STD_ERROR_HANDLE));
|
|
|
#else // !__MINGW32__
|
|
|
-const SharedHandle<BufferedFile>& cout()
|
|
|
-{
|
|
|
- static SharedHandle<BufferedFile> f(new BufferedFile(stdout));
|
|
|
- return f;
|
|
|
-}
|
|
|
+ consoleCout.reset(new BufferedFile(stdout));
|
|
|
+ consoleCerr.reset(new BufferedFile(stderr));
|
|
|
#endif // !__MINGW32__
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-#ifdef __MINGW32__
|
|
|
-const SharedHandle<WinConsoleFile>& cerr()
|
|
|
+const Console& cout()
|
|
|
{
|
|
|
- static SharedHandle<WinConsoleFile> f(new WinConsoleFile(STD_ERROR_HANDLE));
|
|
|
- return f;
|
|
|
+ return consoleCout;
|
|
|
}
|
|
|
-#else // !__MINGW32__
|
|
|
-const SharedHandle<BufferedFile>& cerr()
|
|
|
+
|
|
|
+const Console& cerr()
|
|
|
{
|
|
|
- static SharedHandle<BufferedFile> f(new BufferedFile(stderr));
|
|
|
- return f;
|
|
|
+ return consoleCerr;
|
|
|
}
|
|
|
-#endif // !__MINGW32__
|
|
|
|
|
|
} // namespace global
|
|
|
|