[corlib] Remove local variables inadvertently overriding class variables.
[mono.git] / mcs / class / corlib / System / Console.cs
index c0cc6f85e0775ed821ed52817a241796d73301c3..f75547ab13d55a425298a88f431b885aa0462a08 100644 (file)
@@ -96,11 +96,6 @@ namespace System
 
                static Console ()
                {
-#if NET_2_1
-                       Encoding inputEncoding;
-                       Encoding outputEncoding;
-#endif
-
                        if (Environment.IsRunningOnWindows) {
                                //
                                // On Windows, follow the Windows tradition
@@ -125,11 +120,11 @@ namespace System
                                // UTF-8 ZWNBSP (zero-width non-breaking space).
                                //
                                int code_page = 0;
-                               Encoding.InternalCodePage (ref code_page);
+                               EncodingHelper.InternalCodePage (ref code_page);
 
                                if (code_page != -1 && ((code_page & 0x0fffffff) == 3 // UTF8Encoding.UTF8_CODE_PAGE
                                        || ((code_page & 0x10000000) != 0)))
-                                       inputEncoding = outputEncoding = Encoding.UTF8Unmarked;
+                                       inputEncoding = outputEncoding = EncodingHelper.UTF8Unmarked;
                                else
                                        inputEncoding = outputEncoding = Encoding.Default;
                        }
@@ -141,48 +136,29 @@ namespace System
                {
 #if !NET_2_1
                        if (!Environment.IsRunningOnWindows && ConsoleDriver.IsConsole) {
-                               StreamWriter w = new CStreamWriter (OpenStandardOutput (0), outputEncoding);
-                               w.AutoFlush = true;
-                               stdout = TextWriter.Synchronized (w, true);
-
-                               w = new CStreamWriter (OpenStandardOutput (0), outputEncoding);
-                               w.AutoFlush = true;
-                               stderr = TextWriter.Synchronized (w, true);
-                               
                                stdin = new CStreamReader (OpenStandardInput (0), inputEncoding);
-                       } else {
+                               stdout = TextWriter.Synchronized (new CStreamWriter (OpenStandardOutput (0), outputEncoding, true) { AutoFlush = true });
+                               stderr = TextWriter.Synchronized (new CStreamWriter (OpenStandardError (0), outputEncoding, true) { AutoFlush = true });
+                       } else
 #endif
-// FULL_AOT_RUNTIME is used (instead of MONOTOUCH) since we only want this code when running on 
-// iOS (simulator or devices) and *not* when running tools (e.g. btouch #12179) that needs to use 
-// the mscorlib.dll shipped with Xamarin.iOS
-#if MONOTOUCH && FULL_AOT_RUNTIME
-                               stdout = new NSLogWriter ();
-#else
-                               stdout = new UnexceptionalStreamWriter (OpenStandardOutput (0), outputEncoding);
-                               ((StreamWriter)stdout).AutoFlush = true;
-#endif
-                               stdout = TextWriter.Synchronized (stdout, true);
+                       {
+                               stdin = TextReader.Synchronized (new UnexceptionalStreamReader (OpenStandardInput (0), inputEncoding));
 
-#if MONOTOUCH && FULL_AOT_RUNTIME
+#if MONOTOUCH
+                               stdout = new NSLogWriter ();
                                stderr = new NSLogWriter ();
 #else
-                               stderr = new UnexceptionalStreamWriter (OpenStandardError (0), outputEncoding); 
-                               ((StreamWriter)stderr).AutoFlush = true;
-#endif
-                               stderr = TextWriter.Synchronized (stderr, true);
-
-                               stdin = new UnexceptionalStreamReader (OpenStandardInput (0), inputEncoding);
-                               stdin = TextReader.Synchronized (stdin);
-#if !NET_2_1
-                       }
-#endif
+                               stdout = TextWriter.Synchronized (new UnexceptionalStreamWriter (OpenStandardOutput (0), outputEncoding) { AutoFlush = true });
+                               stderr = TextWriter.Synchronized (new UnexceptionalStreamWriter (OpenStandardError (0), outputEncoding) { AutoFlush = true });
 
 #if MONODROID
-                       if (LogcatTextWriter.IsRunningOnAndroid ()) {
-                               stdout = TextWriter.Synchronized (new LogcatTextWriter ("mono-stdout", stdout));
-                               stderr = TextWriter.Synchronized (new LogcatTextWriter ("mono-stderr", stderr));
+                               if (LogcatTextWriter.IsRunningOnAndroid ()) {
+                                       stdout = TextWriter.Synchronized (new LogcatTextWriter ("mono-stdout", stdout));
+                                       stderr = TextWriter.Synchronized (new LogcatTextWriter ("mono-stderr", stderr));
+                               }
+#endif // MONODROID
+#endif // MONOTOUCH
                        }
-#endif  // MONODROID
 
                        GC.SuppressFinalize (stdout);
                        GC.SuppressFinalize (stderr);
@@ -210,9 +186,10 @@ namespace System
                private static Stream Open (IntPtr handle, FileAccess access, int bufferSize)
                {
                        try {
-                               return new FileStream (handle, access, false, bufferSize, false, bufferSize == 0);
+                               // TODO: Should use __ConsoleStream from reference sources
+                               return new FileStream (handle, access, false, bufferSize, false, true);
                        } catch (IOException) {
-                               return new NullStream ();
+                               return Stream.Null;
                        }
                }
 
@@ -542,7 +519,6 @@ namespace System
 
 #endif
 
-#if !NET_2_1
                // FIXME: Console should use these encodings when changed
                static Encoding inputEncoding;
                static Encoding outputEncoding;
@@ -563,6 +539,7 @@ namespace System
                        }
                }
 
+#if !NET_2_1
                public static ConsoleColor BackgroundColor {
                        get { return ConsoleDriver.BackgroundColor; }
                        set { ConsoleDriver.BackgroundColor = value; }