Files
sdk/runtime/bin/stdio_patch.dart
T
sgjesse@google.com e40ce105af Fix a number of issues with determining the type of stdio
* Fix checked mode exception when _getSocketType returns an OSError
 * Treat any character device as terminal (this includes /dev/null)
 * Fix detecting of file redirection af file
 * Don't turn an unkonwn device type into an OSError (wth value for an unknown was -1)

Expanded an existing test to catch some of this.

R=ager@google.com

BUG=https://code.google.com/p/dart/issues/detail?id=9637

Review URL: https://codereview.chromium.org//13636003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20960 260f80e4-7a28-3924-810f-c04153c831b5
2013-04-05 11:13:24 +00:00

46 lines
1.5 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
patch class _StdIOUtils {
static Stream<List<int>> _getStdioInputStream() {
switch (_getStdioHandleType(0)) {
case _STDIO_HANDLE_TYPE_TERMINAL:
case _STDIO_HANDLE_TYPE_PIPE:
case _STDIO_HANDLE_TYPE_SOCKET:
return new _Socket._readPipe(0);
case _STDIO_HANDLE_TYPE_FILE:
return new _FileStream.forStdin();
default:
throw new FileIOException("Unsupported stdin type");
}
}
static IOSink _getStdioOutputStream(int fd) {
assert(fd == 1 || fd == 2);
switch (_getStdioHandleType(fd)) {
case _STDIO_HANDLE_TYPE_TERMINAL:
case _STDIO_HANDLE_TYPE_PIPE:
case _STDIO_HANDLE_TYPE_SOCKET:
return new _Socket._writePipe(fd);
case _STDIO_HANDLE_TYPE_FILE:
return new IOSink(new _FileStreamConsumer.fromStdio(fd));
default:
throw new FileIOException("Unsupported stdin type");
}
}
static int _socketType(nativeSocket) {
var result = _getSocketType(nativeSocket);
if (result is OSError) {
throw new FileIOException("Error retreiving socket type", result);
}
return result;
}
}
_getStdioHandle(_NativeSocket socket, int num) native "Socket_GetStdioHandle";
_getStdioHandleType(int num) native "File_GetStdioHandleType";
_getSocketType(_NativeSocket nativeSocket) native "Socket_GetType";