| 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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 | 564 |
| 565 | 565 |
| 566 void FUNCTION_NAME(File_Stat)(Dart_NativeArguments args) { | 566 void FUNCTION_NAME(File_Stat)(Dart_NativeArguments args) { |
| 567 Dart_EnterScope(); | 567 Dart_EnterScope(); |
| 568 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) { | 568 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) { |
| 569 const char* path = | 569 const char* path = |
| 570 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 570 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 571 | 571 |
| 572 int64_t stat_data[File::kStatSize]; | 572 int64_t stat_data[File::kStatSize]; |
| 573 File::Stat(path, stat_data); | 573 File::Stat(path, stat_data); |
| 574 Dart_Handle returned_data = Dart_NewTypedData(Dart_TypedData_kInt64, | 574 if (stat_data[File::kType] == File::kDoesNotExist) { |
| 575 File::kStatSize); | 575 Dart_Handle err = DartUtils::NewDartOSError(); |
| 576 if (Dart_IsError(returned_data)) Dart_PropagateError(returned_data); | 576 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 577 Dart_TypedData_Type data_type_unused; | 577 Dart_SetReturnValue(args, err); |
| 578 void* data_location; | 578 } else { |
| 579 intptr_t data_length_unused; | 579 Dart_Handle returned_data = Dart_NewTypedData(Dart_TypedData_kInt64, |
| 580 Dart_Handle status = Dart_TypedDataAcquireData(returned_data, | 580 File::kStatSize); |
| 581 &data_type_unused, | 581 if (Dart_IsError(returned_data)) Dart_PropagateError(returned_data); |
| 582 &data_location, | 582 Dart_TypedData_Type data_type_unused; |
| 583 &data_length_unused); | 583 void* data_location; |
| 584 if (Dart_IsError(status)) Dart_PropagateError(status); | 584 intptr_t data_length_unused; |
| 585 memmove(data_location, stat_data, File::kStatSize * sizeof(int64_t)); | 585 Dart_Handle status = Dart_TypedDataAcquireData(returned_data, |
| 586 status = Dart_TypedDataReleaseData(returned_data); | 586 &data_type_unused, |
| 587 if (Dart_IsError(status)) Dart_PropagateError(status); | 587 &data_location, |
| 588 Dart_SetReturnValue(args, returned_data); | 588 &data_length_unused); |
| 589 if (Dart_IsError(status)) Dart_PropagateError(status); |
| 590 memmove(data_location, stat_data, File::kStatSize * sizeof(int64_t)); |
| 591 status = Dart_TypedDataReleaseData(returned_data); |
| 592 if (Dart_IsError(status)) Dart_PropagateError(status); |
| 593 Dart_SetReturnValue(args, returned_data); |
| 594 } |
| 589 } else { | 595 } else { |
| 590 Dart_Handle err = DartUtils::NewDartArgumentError( | 596 Dart_Handle err = DartUtils::NewDartArgumentError( |
| 591 "Non-string argument to FileSystemEntity.stat"); | 597 "Non-string argument to FileSystemEntity.stat"); |
| 592 if (Dart_IsError(err)) Dart_PropagateError(err); | 598 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 593 Dart_SetReturnValue(args, err); | 599 Dart_SetReturnValue(args, err); |
| 594 } | 600 } |
| 595 Dart_ExitScope(); | 601 Dart_ExitScope(); |
| 596 } | 602 } |
| 597 | 603 |
| 598 | 604 |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 return CObject::IllegalArgumentError(); | 1123 return CObject::IllegalArgumentError(); |
| 1118 } | 1124 } |
| 1119 | 1125 |
| 1120 | 1126 |
| 1121 static CObject* FileStatRequest(const CObjectArray& request) { | 1127 static CObject* FileStatRequest(const CObjectArray& request) { |
| 1122 if (request.Length() == 2 && | 1128 if (request.Length() == 2 && |
| 1123 request[1]->IsString()) { | 1129 request[1]->IsString()) { |
| 1124 int64_t data[File::kStatSize]; | 1130 int64_t data[File::kStatSize]; |
| 1125 CObjectString path(request[1]); | 1131 CObjectString path(request[1]); |
| 1126 File::Stat(path.CString(), data); | 1132 File::Stat(path.CString(), data); |
| 1133 if (data[File::kType] == File::kDoesNotExist) { |
| 1134 return CObject::NewOSError(); |
| 1135 } |
| 1127 CObjectArray* result = | 1136 CObjectArray* result = |
| 1128 new CObjectArray(CObject::NewArray(File::kStatSize)); | 1137 new CObjectArray(CObject::NewArray(File::kStatSize)); |
| 1129 for (int i = 0; i < File::kStatSize; ++i) { | 1138 for (int i = 0; i < File::kStatSize; ++i) { |
| 1130 result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i]))); | 1139 result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i]))); |
| 1131 } | 1140 } |
| 1132 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); | 1141 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); |
| 1133 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); | 1142 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); |
| 1134 wrapper->SetAt(1, result); | 1143 wrapper->SetAt(1, result); |
| 1135 return wrapper; | 1144 return wrapper; |
| 1136 } | 1145 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 if (service_port != ILLEGAL_PORT) { | 1250 if (service_port != ILLEGAL_PORT) { |
| 1242 // Return a send port for the service port. | 1251 // Return a send port for the service port. |
| 1243 Dart_Handle send_port = Dart_NewSendPort(service_port); | 1252 Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 1244 Dart_SetReturnValue(args, send_port); | 1253 Dart_SetReturnValue(args, send_port); |
| 1245 } | 1254 } |
| 1246 Dart_ExitScope(); | 1255 Dart_ExitScope(); |
| 1247 } | 1256 } |
| 1248 | 1257 |
| 1249 } // namespace bin | 1258 } // namespace bin |
| 1250 } // namespace dart | 1259 } // namespace dart |
| OLD | NEW |