| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 Socket _stdin; | 5 final int _STDIO_HANDLE_TYPE_TERMINAL = 0; |
| 6 final int _STDIO_HANDLE_TYPE_PIPE = 1; |
| 7 final int _STDIO_HANDLE_TYPE_FILE = 2; |
| 8 final int _STDIO_HANDLE_TYPE_OTHER = 3; |
| 9 |
| 10 |
| 11 InputStream _stdin; |
| 12 OutputStream _stdout; |
| 13 OutputStream _stderr; |
| 14 |
| 15 |
| 16 InputStream _getStdioInputStream() { |
| 17 switch (_getStdioHandleType(0)) { |
| 18 case _STDIO_HANDLE_TYPE_TERMINAL: |
| 19 case _STDIO_HANDLE_TYPE_PIPE: |
| 20 Socket s = new _Socket._internalReadOnly(); |
| 21 _getStdioHandle(s, 0); |
| 22 return s.inputStream; |
| 23 case _STDIO_HANDLE_TYPE_FILE: |
| 24 return new _FileInputStream.fromStdio(0); |
| 25 default: |
| 26 throw new FileIOException("Unsupported stdin type"); |
| 27 } |
| 28 } |
| 29 |
| 30 |
| 31 OutputStream _getStdioOutputStream(int fd) { |
| 32 assert(fd == 1 || fd == 2); |
| 33 switch (_getStdioHandleType(fd)) { |
| 34 case _STDIO_HANDLE_TYPE_TERMINAL: |
| 35 case _STDIO_HANDLE_TYPE_PIPE: |
| 36 Socket s = new _Socket._internalWriteOnly(); |
| 37 _getStdioHandle(s, fd); |
| 38 return s.outputStream; |
| 39 case _STDIO_HANDLE_TYPE_FILE: |
| 40 return new _FileOutputStream.fromStdio(fd); |
| 41 default: |
| 42 throw new FileIOException("Unsupported stdin type"); |
| 43 } |
| 44 } |
| 45 |
| 46 |
| 6 InputStream get stdin() { | 47 InputStream get stdin() { |
| 7 if (_stdin == null) { | 48 if (_stdin == null) { |
| 8 _stdin = new _Socket._internalReadOnly(); | 49 _stdin = _getStdioInputStream(); |
| 9 _getStdioHandle(_stdin, 0); | |
| 10 } | 50 } |
| 11 return _stdin.inputStream; | 51 return _stdin; |
| 12 } | 52 } |
| 13 | 53 |
| 14 Socket _stdout; | 54 |
| 15 OutputStream get stdout() { | 55 OutputStream get stdout() { |
| 16 if (_stdout == null) { | 56 if (_stdout == null) { |
| 17 _stdout = new _Socket._internalWriteOnly(); | 57 _stdout = _getStdioOutputStream(1); |
| 18 _getStdioHandle(_stdout, 1); | |
| 19 } | 58 } |
| 20 return _stdout.outputStream; | 59 return _stdout; |
| 21 } | 60 } |
| 22 | 61 |
| 23 Socket _stderr; | 62 |
| 24 OutputStream get stderr() { | 63 OutputStream get stderr() { |
| 25 if (_stderr == null) { | 64 if (_stderr == null) { |
| 26 _stderr = new _Socket._internalWriteOnly(); | 65 _stderr = _getStdioOutputStream(2); |
| 27 _getStdioHandle(_stderr, 2); | |
| 28 } | 66 } |
| 29 return _stderr.outputStream; | 67 return _stderr; |
| 30 } | 68 } |
| 31 | 69 |
| 32 _getStdioHandle(Socket socket, int num) native "Socket_GetStdioHandle"; | 70 _getStdioHandle(Socket socket, int num) native "Socket_GetStdioHandle"; |
| 71 _getStdioHandleType(int num) native "File_GetStdioHandleType"; |
| OLD | NEW |