Chromium Code Reviews| 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/utils.h" | 10 #include "bin/utils.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 intptr_t buffer_len = 0; | 259 intptr_t buffer_len = 0; |
| 260 void* buffer = NULL; | 260 void* buffer = NULL; |
| 261 Dart_Handle result = | 261 Dart_Handle result = |
| 262 Dart_TypedDataAcquireData(buffer_obj, &type, &buffer, &buffer_len); | 262 Dart_TypedDataAcquireData(buffer_obj, &type, &buffer, &buffer_len); |
| 263 if (Dart_IsError(result)) Dart_PropagateError(result); | 263 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 264 | 264 |
| 265 ASSERT(type == Dart_TypedData_kUint8 || type == Dart_TypedData_kInt8); | 265 ASSERT(type == Dart_TypedData_kUint8 || type == Dart_TypedData_kInt8); |
| 266 ASSERT(end <= buffer_len); | 266 ASSERT(end <= buffer_len); |
| 267 ASSERT(buffer != NULL); | 267 ASSERT(buffer != NULL); |
| 268 | 268 |
| 269 // Write the data out into the file. | 269 // Write all the data out into the file. |
| 270 int64_t bytes_written = file->Write(buffer, length); | 270 int64_t remaining = length; |
| 271 while (remaining > 0) { | |
| 272 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.
| |
| 273 if (written < 0) { | |
| 274 break; | |
| 275 } | |
| 276 remaining -= written; | |
| 277 buffer = reinterpret_cast<uint8_t*>(buffer) + written; | |
| 278 } | |
| 271 // Release the direct pointer acquired above. | 279 // Release the direct pointer acquired above. |
| 272 result = Dart_TypedDataReleaseData(buffer_obj); | 280 result = Dart_TypedDataReleaseData(buffer_obj); |
| 273 if (Dart_IsError(result)) Dart_PropagateError(result); | 281 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 274 | 282 |
| 275 if (bytes_written != length) { | 283 if (remaining > 0) { |
| 276 Dart_Handle err = DartUtils::NewDartOSError(); | 284 Dart_Handle err = DartUtils::NewDartOSError(); |
| 277 if (Dart_IsError(err)) Dart_PropagateError(err); | 285 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 278 Dart_SetReturnValue(args, err); | 286 Dart_SetReturnValue(args, err); |
| 287 } else { | |
| 288 Dart_SetReturnValue(args, Dart_Null()); | |
| 279 } | 289 } |
| 280 } | 290 } |
| 281 | 291 |
| 282 | 292 |
| 283 void FUNCTION_NAME(File_Position)(Dart_NativeArguments args) { | 293 void FUNCTION_NAME(File_Position)(Dart_NativeArguments args) { |
| 284 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); | 294 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); |
| 285 ASSERT(file != NULL); | 295 ASSERT(file != NULL); |
| 286 intptr_t return_value = file->Position(); | 296 intptr_t return_value = file->Position(); |
| 287 if (return_value >= 0) { | 297 if (return_value >= 0) { |
| 288 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 298 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1086 buffer_start[i] = static_cast<uint8_t>(value & 0xFF); | 1096 buffer_start[i] = static_cast<uint8_t>(value & 0xFF); |
| 1087 } else { | 1097 } else { |
| 1088 // Unsupported type. | 1098 // Unsupported type. |
| 1089 delete[] buffer_start; | 1099 delete[] buffer_start; |
| 1090 return CObject::IllegalArgumentError(); | 1100 return CObject::IllegalArgumentError(); |
| 1091 } | 1101 } |
| 1092 } | 1102 } |
| 1093 start = 0; | 1103 start = 0; |
| 1094 } | 1104 } |
| 1095 int64_t bytes_written = | 1105 int64_t bytes_written = |
| 1096 file->Write(reinterpret_cast<void*>(buffer_start), length); | 1106 file->Write(reinterpret_cast<void*>(buffer_start), length); |
|
Anders Johnsen
2015/03/18 10:11:13
Problem here too?
Søren Gjesse
2015/03/19 10:12:44
Yes. Fixed here as well. Also did it for the write
| |
| 1097 if (!request[1]->IsTypedData()) { | 1107 if (!request[1]->IsTypedData()) { |
| 1098 delete[] buffer_start; | 1108 delete[] buffer_start; |
| 1099 } | 1109 } |
| 1100 if (bytes_written >= 0) { | 1110 if (bytes_written >= 0) { |
| 1101 return new CObjectInt64(CObject::NewInt64(bytes_written)); | 1111 return new CObjectInt64(CObject::NewInt64(bytes_written)); |
| 1102 } else { | 1112 } else { |
| 1103 return CObject::NewOSError(); | 1113 return CObject::NewOSError(); |
| 1104 } | 1114 } |
| 1105 } else { | 1115 } else { |
| 1106 return CObject::FileClosedError(); | 1116 return CObject::FileClosedError(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1245 } | 1255 } |
| 1246 } else { | 1256 } else { |
| 1247 return CObject::FileClosedError(); | 1257 return CObject::FileClosedError(); |
| 1248 } | 1258 } |
| 1249 } | 1259 } |
| 1250 return CObject::IllegalArgumentError(); | 1260 return CObject::IllegalArgumentError(); |
| 1251 } | 1261 } |
| 1252 | 1262 |
| 1253 } // namespace bin | 1263 } // namespace bin |
| 1254 } // namespace dart | 1264 } // namespace dart |
| OLD | NEW |