Chromium Code Reviews| Index: runtime/bin/file.cc |
| diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc |
| index c4c417b8603351b6e2526410c3cef8f9d267de06..715f7223f27f1cd0a27a9e6d1bac32153e9bbdc3 100644 |
| --- a/runtime/bin/file.cc |
| +++ b/runtime/bin/file.cc |
| @@ -266,16 +266,26 @@ void FUNCTION_NAME(File_WriteFrom)(Dart_NativeArguments args) { |
| ASSERT(end <= buffer_len); |
| ASSERT(buffer != NULL); |
| - // Write the data out into the file. |
| - int64_t bytes_written = file->Write(buffer, length); |
| + // Write all the data out into the file. |
| + int64_t remaining = length; |
| + while (remaining > 0) { |
| + int64_t written = file->Write(buffer, remaining); |
|
Anders Johnsen
2015/03/18 10:11:13
Use file->WriteFully instead?
Søren Gjesse
2015/03/19 10:12:44
Forgot about that. Done.
|
| + if (written < 0) { |
| + break; |
| + } |
| + remaining -= written; |
| + buffer = reinterpret_cast<uint8_t*>(buffer) + written; |
| + } |
| // Release the direct pointer acquired above. |
| result = Dart_TypedDataReleaseData(buffer_obj); |
| if (Dart_IsError(result)) Dart_PropagateError(result); |
| - if (bytes_written != length) { |
| + if (remaining > 0) { |
| Dart_Handle err = DartUtils::NewDartOSError(); |
| if (Dart_IsError(err)) Dart_PropagateError(err); |
| Dart_SetReturnValue(args, err); |
| + } else { |
| + Dart_SetReturnValue(args, Dart_Null()); |
| } |
| } |