Repository: dotnet/runtime
File: src/libraries/System.Console/src/System/ConsolePal.Wasi.cs (C#)

Code before:
    {
        public static Stream OpenStandardInput()
        {
            return new UnixConsoleStream(OpenStandardInputHandle(), FileAccess.Read,
                                         useReadLine: !Console.IsInputRedirected);
        }

        public static Stream OpenStandardOutput()
        {
            return new UnixConsoleStream(OpenStandardOutputHandle(), FileAccess.Write);
        }

        public static Stream OpenStandardError()
        {
            return new UnixConsoleStream(OpenStandardErrorHandle(), FileAccess.Write);
        }

        public static SafeFileHandle OpenStandardInputHandle(bool verifyFd = true) => OpenStandardHandle(0, FileAccess.Read, verifyFd);

        public static SafeFileHandle OpenStandardOutputHandle(bool verifyFd = true) => OpenStandardHandle(1, FileAccess.Write, verifyFd);

        public static SafeFileHandle OpenStandardErrorHandle(bool verifyFd = true) => OpenStandardHandle(2, FileAccess.Write, verifyFd);

        private static SafeFileHandle OpenStandardHandle(IntPtr fd, FileAccess access, bool verifyFd)
        {
            if (verifyFd && Interop.Sys.Fcntl.CheckAccess(fd, (int)access) == -1)
            {
                throw new InvalidOperationException(SR.InvalidOperation_InvalidHandle);
            }

            return new SafeFileHandle(fd, ownsHandle: false);
        }

        public static Encoding InputEncoding
        {
            get { return GetConsoleEncoding(); }
        }

        public static Encoding OutputEncoding
        {
            get { return GetConsoleEncoding(); }
        }

        internal static TextReader GetOrCreateReader()
        {
            Stream inputStream = OpenStandardInput();
            return inputStream == Stream.Null ?
                StreamReader.Null :
                new StreamReader(
                    stream: inputStream,
                    encoding: Console.InputEncoding,

Review comment (bug):
I am not sure whether it is good idea to do these additional checks for the new APIs. What is the failure mode for the new APIs when these additional checks are omitted? 

I think these additional checks just get into way if folks just want to pass through the console handles to child process.

Code after:
    {
        public static Stream OpenStandardInput()
        {
            return new UnixConsoleStream(OpenStandardInputHandle(), FileAccess.Read,
                                         useReadLine: !Console.IsInputRedirected);
        }

        public static Stream OpenStandardOutput()
        {
            return new UnixConsoleStream(OpenStandardOutputHandle(), FileAccess.Write);
        }

        public static Stream OpenStandardError()
        {
            return new UnixConsoleStream(OpenStandardErrorHandle(), FileAccess.Write);
        }

        public static SafeFileHandle OpenStandardInputHandle() => OpenStandardHandle(0);

        public static SafeFileHandle OpenStandardOutputHandle() => OpenStandardHandle(1);

        public static SafeFileHandle OpenStandardErrorHandle() => OpenStandardHandle(2);

        private static SafeFileHandle OpenStandardHandle(IntPtr fd) => new SafeFileHandle(fd, ownsHandle: false);

        public static Encoding InputEncoding
        {
            get { return GetConsoleEncoding(); }
        }

        public static Encoding OutputEncoding
        {
            get { return GetConsoleEncoding(); }
        }

        internal static TextReader GetOrCreateReader()
        {
            Stream inputStream = OpenStandardInput();
            return inputStream == Stream.Null ?
                StreamReader.Null :
                new StreamReader(
                    stream: inputStream,
                    encoding: Console.InputEncoding,
                    detectEncodingFromByteOrderMarks: false,
                    bufferSize: Console.ReadBufferSize,
                    leaveOpen: true);
        }

        public static bool KeyAvailable => false;

        public static ConsoleKeyInfo ReadKey(bool intercept) => throw new PlatformNotSupportedException();