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

Side by Side Diff: runtime/bin/file_support.cc

Issue 2480793002: clang-format runtime/bin (Closed)
Patch Set: Created 4 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
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | runtime/bin/file_system_watcher.h » ('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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 #include "bin/file.h" 5 #include "bin/file.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 #include "bin/embedded_dart_io.h" 9 #include "bin/embedded_dart_io.h"
10 #include "bin/io_buffer.h" 10 #include "bin/io_buffer.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 44
45 bool File::ReadFully(void* buffer, int64_t num_bytes) { 45 bool File::ReadFully(void* buffer, int64_t num_bytes) {
46 int64_t remaining = num_bytes; 46 int64_t remaining = num_bytes;
47 char* current_buffer = reinterpret_cast<char*>(buffer); 47 char* current_buffer = reinterpret_cast<char*>(buffer);
48 while (remaining > 0) { 48 while (remaining > 0) {
49 int64_t bytes_read = Read(current_buffer, remaining); 49 int64_t bytes_read = Read(current_buffer, remaining);
50 if (bytes_read <= 0) { 50 if (bytes_read <= 0) {
51 return false; 51 return false;
52 } 52 }
53 remaining -= bytes_read; // Reduce the number of remaining bytes. 53 remaining -= bytes_read; // Reduce the number of remaining bytes.
54 current_buffer += bytes_read; // Move the buffer forward. 54 current_buffer += bytes_read; // Move the buffer forward.
55 } 55 }
56 return true; 56 return true;
57 } 57 }
58 58
59 59
60 bool File::WriteFully(const void* buffer, int64_t num_bytes) { 60 bool File::WriteFully(const void* buffer, int64_t num_bytes) {
61 int64_t remaining = num_bytes; 61 int64_t remaining = num_bytes;
62 const char* current_buffer = reinterpret_cast<const char*>(buffer); 62 const char* current_buffer = reinterpret_cast<const char*>(buffer);
63 while (remaining > 0) { 63 while (remaining > 0) {
64 int64_t bytes_written = Write(current_buffer, remaining); 64 int64_t bytes_written = Write(current_buffer, remaining);
65 if (bytes_written < 0) { 65 if (bytes_written < 0) {
66 return false; 66 return false;
67 } 67 }
68 remaining -= bytes_written; // Reduce the number of remaining bytes. 68 remaining -= bytes_written; // Reduce the number of remaining bytes.
69 current_buffer += bytes_written; // Move the buffer forward. 69 current_buffer += bytes_written; // Move the buffer forward.
70 } 70 }
71 if (capture_stdout || capture_stderr) { 71 if (capture_stdout || capture_stderr) {
72 intptr_t fd = GetFD(); 72 intptr_t fd = GetFD();
73 if ((fd == STDOUT_FILENO) && capture_stdout) { 73 if ((fd == STDOUT_FILENO) && capture_stdout) {
74 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", 74 Dart_ServiceSendDataEvent("Stdout", "WriteEvent",
75 reinterpret_cast<const uint8_t*>(buffer), 75 reinterpret_cast<const uint8_t*>(buffer),
76 num_bytes); 76 num_bytes);
77 } else if ((fd == STDERR_FILENO) && capture_stderr) { 77 } else if ((fd == STDERR_FILENO) && capture_stderr) {
78 Dart_ServiceSendDataEvent("Stderr", "WriteEvent", 78 Dart_ServiceSendDataEvent("Stderr", "WriteEvent",
79 reinterpret_cast<const uint8_t*>(buffer), 79 reinterpret_cast<const uint8_t*>(buffer),
80 num_bytes); 80 num_bytes);
81 } 81 }
82 } 82 }
83 return true; 83 return true;
84 } 84 }
85 85
86 86
87 File::FileOpenMode File::DartModeToFileMode(DartFileOpenMode mode) { 87 File::FileOpenMode File::DartModeToFileMode(DartFileOpenMode mode) {
88 ASSERT((mode == File::kDartRead) || 88 ASSERT((mode == File::kDartRead) || (mode == File::kDartWrite) ||
89 (mode == File::kDartWrite) || 89 (mode == File::kDartAppend) || (mode == File::kDartWriteOnly) ||
90 (mode == File::kDartAppend) ||
91 (mode == File::kDartWriteOnly) ||
92 (mode == File::kDartWriteOnlyAppend)); 90 (mode == File::kDartWriteOnlyAppend));
93 if (mode == File::kDartWrite) { 91 if (mode == File::kDartWrite) {
94 return File::kWriteTruncate; 92 return File::kWriteTruncate;
95 } 93 }
96 if (mode == File::kDartAppend) { 94 if (mode == File::kDartAppend) {
97 return File::kWrite; 95 return File::kWrite;
98 } 96 }
99 if (mode == File::kDartWriteOnly) { 97 if (mode == File::kDartWriteOnly) {
100 return File::kWriteOnlyTruncate; 98 return File::kWriteOnlyTruncate;
101 } 99 }
102 if (mode == File::kDartWriteOnlyAppend) { 100 if (mode == File::kDartWriteOnlyAppend) {
103 return File::kWriteOnly; 101 return File::kWriteOnly;
104 } 102 }
105 return File::kRead; 103 return File::kRead;
106 } 104 }
107 105
108 } // namespace bin 106 } // namespace bin
109 } // namespace dart 107 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | runtime/bin/file_system_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698