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

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

Issue 9360040: Handle stdio redirection in standalone VM (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert test change Created 8 years, 10 months 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
« no previous file with comments | « runtime/bin/file.cc ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 class _FileInputStream extends _BaseDataInputStream implements InputStream { 5 class _FileInputStream extends _BaseDataInputStream implements InputStream {
6 _FileInputStream(File file) { 6 _FileInputStream(File file) {
7 _file = file.openSync(); 7 _file = file.openSync();
8 _length = _file.lengthSync(); 8 _length = _file.lengthSync();
9 _streamMarkedClosed = true; 9 _streamMarkedClosed = true;
10 _checkScheduleCallbacks(); 10 _checkScheduleCallbacks();
11 } 11 }
12 12
13 _FileInputStream.fromStdio(int fd) {
14 assert(fd == 0);
15 _file = _File._openStdioSync(fd);
16 _length = _file.lengthSync();
17 _streamMarkedClosed = true;
18 _checkScheduleCallbacks();
19 }
20
13 int available() { 21 int available() {
14 return _closed ? 0 : _length - _file.positionSync(); 22 return _closed ? 0 : _length - _file.positionSync();
15 } 23 }
16 24
17 void pipe(OutputStream output, [bool close = true]) { 25 void pipe(OutputStream output, [bool close = true]) {
18 _pipe(this, output, close: close); 26 _pipe(this, output, close: close);
19 } 27 }
20 28
21 List<int> _read(int bytesToRead) { 29 List<int> _read(int bytesToRead) {
22 ByteArray result = new ByteArray(bytesToRead); 30 ByteArray result = new ByteArray(bytesToRead);
(...skipping 23 matching lines...) Expand all
46 int _length; 54 int _length;
47 bool _closed = false; 55 bool _closed = false;
48 } 56 }
49 57
50 58
51 class _FileOutputStream implements OutputStream { 59 class _FileOutputStream implements OutputStream {
52 _FileOutputStream(File file, FileMode mode) { 60 _FileOutputStream(File file, FileMode mode) {
53 _file = file.openSync(mode); 61 _file = file.openSync(mode);
54 } 62 }
55 63
64 _FileOutputStream.fromStdio(int fd) {
65 assert(1 <= fd && fd <= 2);
66 _file = _File._openStdioSync(fd);
67 }
68
56 bool write(List<int> buffer, [bool copyBuffer = false]) { 69 bool write(List<int> buffer, [bool copyBuffer = false]) {
57 return _write(buffer, 0, buffer.length); 70 return _write(buffer, 0, buffer.length);
58 } 71 }
59 72
60 bool writeFrom(List<int> buffer, [int offset = 0, int len]) { 73 bool writeFrom(List<int> buffer, [int offset = 0, int len]) {
61 return _write( 74 return _write(
62 buffer, offset, (len == null) ? buffer.length - offset : len); 75 buffer, offset, (len == null) ? buffer.length - offset : len);
63 } 76 }
64 77
65 void close() { 78 void close() {
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 return writeListNative(id, outBuffer, outOffset, bytes); 458 return writeListNative(id, outBuffer, outOffset, bytes);
446 } 459 }
447 static int writeListNative(int id, List<int> buffer, int offset, int bytes) 460 static int writeListNative(int id, List<int> buffer, int offset, int bytes)
448 native "File_WriteList"; 461 native "File_WriteList";
449 static int writeString(int id, String string) native "File_WriteString"; 462 static int writeString(int id, String string) native "File_WriteString";
450 static int position(int id) native "File_Position"; 463 static int position(int id) native "File_Position";
451 static bool setPosition(int id, int position) native "File_SetPosition"; 464 static bool setPosition(int id, int position) native "File_SetPosition";
452 static bool truncate(int id, int length) native "File_Truncate"; 465 static bool truncate(int id, int length) native "File_Truncate";
453 static int length(int id) native "File_Length"; 466 static int length(int id) native "File_Length";
454 static int flush(int id) native "File_Flush"; 467 static int flush(int id) native "File_Flush";
468 static int openStdio(int fd) native "File_OpenStdio";
455 469
456 static int checkedOpen(String name, int mode) { 470 static int checkedOpen(String name, int mode) {
457 if (name is !String || mode is !int) return 0; 471 if (name is !String || mode is !int) return 0;
458 return open(name, mode); 472 return open(name, mode);
459 } 473 }
460 474
461 static bool checkedCreate(String name) { 475 static bool checkedCreate(String name) {
462 if (name is !String) return false; 476 if (name is !String) return false;
463 return create(name); 477 return create(name);
464 } 478 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 throw new FileIOException("Unknown file mode. Use FileMode.READ, " + 625 throw new FileIOException("Unknown file mode. Use FileMode.READ, " +
612 "FileMode.WRITE or FileMode.APPEND."); 626 "FileMode.WRITE or FileMode.APPEND.");
613 } 627 }
614 var id = _FileUtils.checkedOpen(_name, mode._mode); 628 var id = _FileUtils.checkedOpen(_name, mode._mode);
615 if (id == 0) { 629 if (id == 0) {
616 throw new FileIOException("Cannot open file: $_name"); 630 throw new FileIOException("Cannot open file: $_name");
617 } 631 }
618 return new _RandomAccessFile(id, _name); 632 return new _RandomAccessFile(id, _name);
619 } 633 }
620 634
635 static RandomAccessFile _openStdioSync(int fd) {
636 var id = _FileUtils.openStdio(fd);
637 if (id == 0) {
638 throw new FileIOException("Cannot open stdio file for: $fd");
639 }
640 return new _RandomAccessFile(id, "");
641 }
642
621 void fullPath() { 643 void fullPath() {
622 _asyncUsed = true; 644 _asyncUsed = true;
623 var handleFullPathResult = (result, ignored) { 645 var handleFullPathResult = (result, ignored) {
624 var handler = _fullPathHandler; 646 var handler = _fullPathHandler;
625 if (handler == null) handler = (path) => null; 647 if (handler == null) handler = (path) => null;
626 if (result != null) { 648 if (result != null) {
627 handler(result); 649 handler(result);
628 } else if (_errorHandler != null) { 650 } else if (_errorHandler != null) {
629 _errorHandler("fullPath failed"); 651 _errorHandler("fullPath failed");
630 } 652 }
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 var _readByteHandler; 1119 var _readByteHandler;
1098 var _readListHandler; 1120 var _readListHandler;
1099 var _noPendingWriteHandler; 1121 var _noPendingWriteHandler;
1100 var _positionHandler; 1122 var _positionHandler;
1101 var _setPositionHandler; 1123 var _setPositionHandler;
1102 var _truncateHandler; 1124 var _truncateHandler;
1103 var _lengthHandler; 1125 var _lengthHandler;
1104 var _flushHandler; 1126 var _flushHandler;
1105 var _errorHandler; 1127 var _errorHandler;
1106 } 1128 }
OLDNEW
« no previous file with comments | « runtime/bin/file.cc ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698