Chromium Code Reviews| Index: runtime/bin/file.cc |
| diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc |
| index a98ff3de909423d1f20b4b52284ecf8e5524c786..709ac252ee7f2b7e2ac6dbb5c74e50a87afcf45e 100644 |
| --- a/runtime/bin/file.cc |
| +++ b/runtime/bin/file.cc |
| @@ -391,6 +391,36 @@ void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { |
| } |
| +void FUNCTION_NAME(File_Lock)(Dart_NativeArguments args) { |
| + File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); |
| + ASSERT(file != NULL); |
| + int64_t lock; |
|
Lasse Reichstein Nielsen
2015/01/08 11:59:22
Is this the type on all platforms? There is no loc
Søren Gjesse
2015/01/09 13:06:19
The int64_t type is used to get the Dart int argum
|
| + // Lock type arguments are checked in Dart code to be legal. |
|
Lasse Reichstein Nielsen
2015/01/08 11:59:21
legal -> valid.
It's not a law.
Don't trust Dart
Søren Gjesse
2015/01/09 13:06:19
I an also checking here. It they are not integers
|
| + if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &lock)) { |
| + int64_t start; |
| + int64_t end; |
| + if (lock >= File::kLockMin && |
| + lock <= File::kLockMax && |
| + DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &start) && |
| + DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 3), &end)) { |
| + if (file->Lock(static_cast<File::LockType>(lock), start, end)) { |
| + Dart_SetReturnValue(args, Dart_True()); |
| + } else { |
| + Dart_Handle err = DartUtils::NewDartOSError(); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| + } |
| + return; |
| + } |
| + } |
| + |
| + OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| + Dart_Handle err = DartUtils::NewDartOSError(&os_error); |
| + if (Dart_IsError(err)) Dart_PropagateError(err); |
| + Dart_SetReturnValue(args, err); |
| +} |
| + |
| + |
| void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { |
| const char* str = |
| DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| @@ -1196,5 +1226,30 @@ CObject* File::StatRequest(const CObjectArray& request) { |
| return CObject::IllegalArgumentError(); |
| } |
| + |
| +CObject* File::LockRequest(const CObjectArray& request) { |
| + if (request.Length() == 4 && |
| + request[0]->IsIntptr() && |
| + request[1]->IsInt32OrInt64() && |
| + request[2]->IsInt32OrInt64() && |
| + request[3]->IsInt32OrInt64()) { |
| + File* file = CObjectToFilePointer(request[0]); |
| + ASSERT(file != NULL); |
| + if (!file->IsClosed()) { |
| + int64_t lock = CObjectInt32OrInt64ToInt64(request[1]); |
| + int64_t start = CObjectInt32OrInt64ToInt64(request[2]); |
| + int64_t end = CObjectInt32OrInt64ToInt64(request[3]); |
| + if (file->Lock(static_cast<File::LockType>(lock), start, end)) { |
| + return CObject::True(); |
| + } else { |
| + return CObject::NewOSError(); |
| + } |
| + } else { |
| + return CObject::FileClosedError(); |
| + } |
| + } |
| + return CObject::IllegalArgumentError(); |
| +} |
| + |
| } // namespace bin |
| } // namespace dart |