OLD | NEW |
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 #include "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 | 9 |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 Dart_Handle str = Dart_NewStringFromUTF8(buffer, | 357 Dart_Handle str = Dart_NewStringFromUTF8(buffer, |
358 bufferLen); | 358 bufferLen); |
359 free(buffer); | 359 free(buffer); |
360 return str; | 360 return str; |
361 } | 361 } |
362 | 362 |
363 | 363 |
364 static const uint8_t* ReadFileFully(const char* filename, | 364 static const uint8_t* ReadFileFully(const char* filename, |
365 intptr_t* file_len, | 365 intptr_t* file_len, |
366 const char** error_msg) { | 366 const char** error_msg) { |
| 367 *file_len = -1; |
367 void* stream = DartUtils::OpenFile(filename, false); | 368 void* stream = DartUtils::OpenFile(filename, false); |
368 if (stream == NULL) { | 369 if (stream == NULL) { |
369 SET_ERROR_MSG(error_msg, "Unable to open file: %s", filename); | 370 SET_ERROR_MSG(error_msg, "Unable to open file: %s", filename); |
370 return NULL; | 371 return NULL; |
371 } | 372 } |
372 *file_len = -1; | |
373 const uint8_t* text_buffer = NULL; | 373 const uint8_t* text_buffer = NULL; |
374 DartUtils::ReadFile(&text_buffer, file_len, stream); | 374 DartUtils::ReadFile(&text_buffer, file_len, stream); |
375 if (text_buffer == NULL || *file_len == -1) { | 375 if (text_buffer == NULL || *file_len == -1) { |
376 *error_msg = "Unable to read file contents"; | 376 *error_msg = "Unable to read file contents"; |
377 text_buffer = NULL; | 377 text_buffer = NULL; |
378 } | 378 } |
379 DartUtils::CloseFile(stream); | 379 DartUtils::CloseFile(stream); |
380 return text_buffer; | 380 return text_buffer; |
381 } | 381 } |
382 | 382 |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 new CObjectString(CObject::NewString(os_error->message())); | 1003 new CObjectString(CObject::NewString(os_error->message())); |
1004 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1004 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
1005 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1005 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
1006 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1006 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
1007 result->SetAt(2, error_message); | 1007 result->SetAt(2, error_message); |
1008 return result; | 1008 return result; |
1009 } | 1009 } |
1010 | 1010 |
1011 } // namespace bin | 1011 } // namespace bin |
1012 } // namespace dart | 1012 } // namespace dart |
OLD | NEW |