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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 if (file->Flush()) { | 384 if (file->Flush()) { |
385 Dart_SetReturnValue(args, Dart_True()); | 385 Dart_SetReturnValue(args, Dart_True()); |
386 } else { | 386 } else { |
387 Dart_Handle err = DartUtils::NewDartOSError(); | 387 Dart_Handle err = DartUtils::NewDartOSError(); |
388 if (Dart_IsError(err)) Dart_PropagateError(err); | 388 if (Dart_IsError(err)) Dart_PropagateError(err); |
389 Dart_SetReturnValue(args, err); | 389 Dart_SetReturnValue(args, err); |
390 } | 390 } |
391 } | 391 } |
392 | 392 |
393 | 393 |
| 394 void FUNCTION_NAME(File_Lock)(Dart_NativeArguments args) { |
| 395 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); |
| 396 ASSERT(file != NULL); |
| 397 int64_t lock; |
| 398 int64_t start; |
| 399 int64_t end; |
| 400 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &lock) && |
| 401 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &start) && |
| 402 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 3), &end)) { |
| 403 if ((lock >= File::kLockMin) && (lock <= File::kLockMax) && |
| 404 (start >= 0) && (end == -1 || end > start)) { |
| 405 if (file->Lock(static_cast<File::LockType>(lock), start, end)) { |
| 406 Dart_SetReturnValue(args, Dart_True()); |
| 407 } else { |
| 408 Dart_Handle err = DartUtils::NewDartOSError(); |
| 409 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 410 Dart_SetReturnValue(args, err); |
| 411 } |
| 412 return; |
| 413 } |
| 414 } |
| 415 |
| 416 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| 417 Dart_Handle err = DartUtils::NewDartOSError(&os_error); |
| 418 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 419 Dart_SetReturnValue(args, err); |
| 420 } |
| 421 |
| 422 |
394 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { | 423 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { |
395 const char* str = | 424 const char* str = |
396 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 425 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
397 bool result = File::Create(str); | 426 bool result = File::Create(str); |
398 if (result) { | 427 if (result) { |
399 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 428 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
400 } else { | 429 } else { |
401 Dart_Handle err = DartUtils::NewDartOSError(); | 430 Dart_Handle err = DartUtils::NewDartOSError(); |
402 if (Dart_IsError(err)) Dart_PropagateError(err); | 431 if (Dart_IsError(err)) Dart_PropagateError(err); |
403 Dart_SetReturnValue(args, err); | 432 Dart_SetReturnValue(args, err); |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i]))); | 1218 result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i]))); |
1190 } | 1219 } |
1191 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); | 1220 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); |
1192 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); | 1221 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); |
1193 wrapper->SetAt(1, result); | 1222 wrapper->SetAt(1, result); |
1194 return wrapper; | 1223 return wrapper; |
1195 } | 1224 } |
1196 return CObject::IllegalArgumentError(); | 1225 return CObject::IllegalArgumentError(); |
1197 } | 1226 } |
1198 | 1227 |
| 1228 |
| 1229 CObject* File::LockRequest(const CObjectArray& request) { |
| 1230 if (request.Length() == 4 && |
| 1231 request[0]->IsIntptr() && |
| 1232 request[1]->IsInt32OrInt64() && |
| 1233 request[2]->IsInt32OrInt64() && |
| 1234 request[3]->IsInt32OrInt64()) { |
| 1235 File* file = CObjectToFilePointer(request[0]); |
| 1236 ASSERT(file != NULL); |
| 1237 if (!file->IsClosed()) { |
| 1238 int64_t lock = CObjectInt32OrInt64ToInt64(request[1]); |
| 1239 int64_t start = CObjectInt32OrInt64ToInt64(request[2]); |
| 1240 int64_t end = CObjectInt32OrInt64ToInt64(request[3]); |
| 1241 if (file->Lock(static_cast<File::LockType>(lock), start, end)) { |
| 1242 return CObject::True(); |
| 1243 } else { |
| 1244 return CObject::NewOSError(); |
| 1245 } |
| 1246 } else { |
| 1247 return CObject::FileClosedError(); |
| 1248 } |
| 1249 } |
| 1250 return CObject::IllegalArgumentError(); |
| 1251 } |
| 1252 |
1199 } // namespace bin | 1253 } // namespace bin |
1200 } // namespace dart | 1254 } // namespace dart |
OLD | NEW |