Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: runtime/bin/stdio.dart

Issue 11337019: Use patching for dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 const int _STDIO_HANDLE_TYPE_TERMINAL = 0;
6 const int _STDIO_HANDLE_TYPE_PIPE = 1;
7 const int _STDIO_HANDLE_TYPE_FILE = 2;
8 const int _STDIO_HANDLE_TYPE_SOCKET = 3;
9 const int _STDIO_HANDLE_TYPE_OTHER = -1;
10
11
12 InputStream _stdin;
13 OutputStream _stdout;
14 OutputStream _stderr;
15
16
17 InputStream _getStdioInputStream() {
18 switch (_getStdioHandleType(0)) {
19 case _STDIO_HANDLE_TYPE_TERMINAL:
20 case _STDIO_HANDLE_TYPE_PIPE:
21 case _STDIO_HANDLE_TYPE_SOCKET:
22 Socket s = new _Socket._internalReadOnly();
23 _getStdioHandle(s, 0);
24 s._closed = false;
25 return s.inputStream;
26 case _STDIO_HANDLE_TYPE_FILE:
27 return new _FileInputStream.fromStdio(0);
28 default:
29 throw new FileIOException("Unsupported stdin type");
30 }
31 }
32
33
34 OutputStream _getStdioOutputStream(int fd) {
35 assert(fd == 1 || fd == 2);
36 switch (_getStdioHandleType(fd)) {
37 case _STDIO_HANDLE_TYPE_TERMINAL:
38 case _STDIO_HANDLE_TYPE_PIPE:
39 case _STDIO_HANDLE_TYPE_SOCKET:
40 Socket s = new _Socket._internalWriteOnly();
41 _getStdioHandle(s, fd);
42 s._closed = false;
43 return s.outputStream;
44 case _STDIO_HANDLE_TYPE_FILE:
45 return new _FileOutputStream.fromStdio(fd);
46 default:
47 throw new FileIOException("Unsupported stdin type");
48 }
49 }
50
51
52 InputStream get stdin {
53 if (_stdin == null) {
54 _stdin = _getStdioInputStream();
55 }
56 return _stdin;
57 }
58
59
60 OutputStream get stdout {
61 if (_stdout == null) {
62 _stdout = _getStdioOutputStream(1);
63 }
64 return _stdout;
65 }
66
67
68 OutputStream get stderr {
69 if (_stderr == null) {
70 _stderr = _getStdioOutputStream(2);
71 }
72 return _stderr;
73 }
74
75 _getStdioHandle(Socket socket, int num) native "Socket_GetStdioHandle";
76 _getStdioHandleType(int num) native "File_GetStdioHandleType";
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698