| 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 #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/io_buffer.h" | 9 #include "bin/io_buffer.h" |
| 10 #include "bin/thread.h" | 10 #include "bin/thread.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 static File* GetFilePointer(Dart_Handle handle) { | 24 static File* GetFilePointer(Dart_Handle handle) { |
| 25 intptr_t value = DartUtils::GetIntptrValue(handle); | 25 intptr_t value = DartUtils::GetIntptrValue(handle); |
| 26 return reinterpret_cast<File*>(value); | 26 return reinterpret_cast<File*>(value); |
| 27 } | 27 } |
| 28 | 28 |
| 29 | 29 |
| 30 bool File::ReadFully(void* buffer, int64_t num_bytes) { | 30 bool File::ReadFully(void* buffer, int64_t num_bytes) { |
| 31 int64_t remaining = num_bytes; | 31 int64_t remaining = num_bytes; |
| 32 char* current_buffer = reinterpret_cast<char*>(buffer); | 32 char* current_buffer = reinterpret_cast<char*>(buffer); |
| 33 while (remaining > 0) { | 33 while (remaining > 0) { |
| 34 int bytes_read = Read(current_buffer, remaining); | 34 int64_t bytes_read = Read(current_buffer, remaining); |
| 35 if (bytes_read <= 0) { | 35 if (bytes_read <= 0) { |
| 36 return false; | 36 return false; |
| 37 } | 37 } |
| 38 remaining -= bytes_read; // Reduce the number of remaining bytes. | 38 remaining -= bytes_read; // Reduce the number of remaining bytes. |
| 39 current_buffer += bytes_read; // Move the buffer forward. | 39 current_buffer += bytes_read; // Move the buffer forward. |
| 40 } | 40 } |
| 41 return true; | 41 return true; |
| 42 } | 42 } |
| 43 | 43 |
| 44 | 44 |
| 45 bool File::WriteFully(const void* buffer, int64_t num_bytes) { | 45 bool File::WriteFully(const void* buffer, int64_t num_bytes) { |
| 46 int64_t remaining = num_bytes; | 46 int64_t remaining = num_bytes; |
| 47 const char* current_buffer = reinterpret_cast<const char*>(buffer); | 47 const char* current_buffer = reinterpret_cast<const char*>(buffer); |
| 48 while (remaining > 0) { | 48 while (remaining > 0) { |
| 49 int bytes_read = Write(current_buffer, remaining); | 49 int64_t bytes_read = Write(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 |
| (...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); | 1185 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); |
| 1186 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); | 1186 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); |
| 1187 wrapper->SetAt(1, result); | 1187 wrapper->SetAt(1, result); |
| 1188 return wrapper; | 1188 return wrapper; |
| 1189 } | 1189 } |
| 1190 return CObject::IllegalArgumentError(); | 1190 return CObject::IllegalArgumentError(); |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 } // namespace bin | 1193 } // namespace bin |
| 1194 } // namespace dart | 1194 } // namespace dart |
| OLD | NEW |