| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 const int _STDIO_HANDLE_TYPE_TERMINAL = 0; | 7 const int _STDIO_HANDLE_TYPE_TERMINAL = 0; |
| 8 const int _STDIO_HANDLE_TYPE_PIPE = 1; | 8 const int _STDIO_HANDLE_TYPE_PIPE = 1; |
| 9 const int _STDIO_HANDLE_TYPE_FILE = 2; | 9 const int _STDIO_HANDLE_TYPE_FILE = 2; |
| 10 const int _STDIO_HANDLE_TYPE_SOCKET = 3; | 10 const int _STDIO_HANDLE_TYPE_SOCKET = 3; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 266 } |
| 267 return _stderr; | 267 return _stderr; |
| 268 } | 268 } |
| 269 | 269 |
| 270 | 270 |
| 271 /// For a stream, returns whether it is attached to a file, pipe, terminal, or | 271 /// For a stream, returns whether it is attached to a file, pipe, terminal, or |
| 272 /// something else. | 272 /// something else. |
| 273 StdioType stdioType(object) { | 273 StdioType stdioType(object) { |
| 274 if (object is _StdStream) { | 274 if (object is _StdStream) { |
| 275 object = object._stream; | 275 object = object._stream; |
| 276 } else if (object is _StdSink) { | 276 } else if (object == stdout || object == stderr) { |
| 277 object = object._sink; | 277 switch (_StdIOUtils._getStdioHandleType(object == stdout ? 1 : 2)) { |
| 278 case _STDIO_HANDLE_TYPE_TERMINAL: return StdioType.TERMINAL; |
| 279 case _STDIO_HANDLE_TYPE_PIPE: return StdioType.PIPE; |
| 280 case _STDIO_HANDLE_TYPE_FILE: return StdioType.FILE; |
| 281 } |
| 278 } | 282 } |
| 279 if (object is _FileStream) { | 283 if (object is _FileStream) { |
| 280 return StdioType.FILE; | 284 return StdioType.FILE; |
| 281 } | 285 } |
| 282 if (object is Socket) { | 286 if (object is Socket) { |
| 283 switch (_StdIOUtils._socketType(object._nativeSocket)) { | 287 switch (_StdIOUtils._socketType(object._nativeSocket)) { |
| 284 case _STDIO_HANDLE_TYPE_TERMINAL: return StdioType.TERMINAL; | 288 case _STDIO_HANDLE_TYPE_TERMINAL: return StdioType.TERMINAL; |
| 285 case _STDIO_HANDLE_TYPE_PIPE: return StdioType.PIPE; | 289 case _STDIO_HANDLE_TYPE_PIPE: return StdioType.PIPE; |
| 286 case _STDIO_HANDLE_TYPE_FILE: return StdioType.FILE; | 290 case _STDIO_HANDLE_TYPE_FILE: return StdioType.FILE; |
| 287 } | 291 } |
| 288 } | 292 } |
| 289 if (object is IOSink) { | 293 if (object is IOSink) { |
| 290 try { | 294 try { |
| 291 if (object._target is _FileStreamConsumer) { | 295 if (object._target is _FileStreamConsumer) { |
| 292 return StdioType.FILE; | 296 return StdioType.FILE; |
| 293 } | 297 } |
| 294 } catch (e) { | 298 } catch (e) { |
| 295 // Only the interface implemented, _sink not available. | 299 // Only the interface implemented, _sink not available. |
| 296 } | 300 } |
| 297 } | 301 } |
| 298 return StdioType.OTHER; | 302 return StdioType.OTHER; |
| 299 } | 303 } |
| 300 | 304 |
| 301 | 305 |
| 302 class _StdIOUtils { | 306 class _StdIOUtils { |
| 303 external static _getStdioOutputStream(int fd); | 307 external static _getStdioOutputStream(int fd); |
| 304 external static Stdin _getStdioInputStream(); | 308 external static Stdin _getStdioInputStream(); |
| 305 external static int _socketType(nativeSocket); | 309 external static int _socketType(nativeSocket); |
| 310 external static _getStdioHandleType(int fd); |
| 306 } | 311 } |
| OLD | NEW |