| 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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
| 6 | 6 |
| 7 #include "bin/file.h" | 7 #include "bin/file.h" |
| 8 | 8 |
| 9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
| 10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 static const int kFileNativeFieldIndex = 0; | 21 static const int kFileNativeFieldIndex = 0; |
| 22 static const int kMSPerSecond = 1000; | 22 static const int kMSPerSecond = 1000; |
| 23 | 23 |
| 24 // The file pointer has been passed into Dart as an intptr_t and it is safe | 24 // The file pointer has been passed into Dart as an intptr_t and it is safe |
| 25 // to pull it out of Dart as a 64-bit integer, cast it to an intptr_t and | 25 // to pull it out of Dart as a 64-bit integer, cast it to an intptr_t and |
| 26 // from there to a File pointer. | 26 // from there to a File pointer. |
| 27 static File* GetFile(Dart_NativeArguments args) { | 27 static File* GetFile(Dart_NativeArguments args) { |
| 28 File* file; | 28 File* file; |
| 29 Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0)); | 29 Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0)); |
| 30 ASSERT(Dart_IsInstance(dart_this)); | 30 ASSERT(Dart_IsInstance(dart_this)); |
| 31 ThrowIfError(Dart_GetNativeInstanceField( | 31 ThrowIfError(Dart_GetNativeInstanceField(dart_this, kFileNativeFieldIndex, |
| 32 dart_this, | 32 reinterpret_cast<intptr_t*>(&file))); |
| 33 kFileNativeFieldIndex, | |
| 34 reinterpret_cast<intptr_t*>(&file))); | |
| 35 return file; | 33 return file; |
| 36 } | 34 } |
| 37 | 35 |
| 38 | 36 |
| 39 static void SetFile(Dart_Handle dart_this, intptr_t file_pointer) { | 37 static void SetFile(Dart_Handle dart_this, intptr_t file_pointer) { |
| 40 Dart_Handle result = Dart_SetNativeInstanceField( | 38 Dart_Handle result = Dart_SetNativeInstanceField( |
| 41 dart_this, | 39 dart_this, kFileNativeFieldIndex, file_pointer); |
| 42 kFileNativeFieldIndex, | |
| 43 file_pointer); | |
| 44 if (Dart_IsError(result)) { | 40 if (Dart_IsError(result)) { |
| 45 Log::PrintErr("SetNativeInstanceField in SetFile() failed\n"); | 41 Log::PrintErr("SetNativeInstanceField in SetFile() failed\n"); |
| 46 Dart_PropagateError(result); | 42 Dart_PropagateError(result); |
| 47 } | 43 } |
| 48 } | 44 } |
| 49 | 45 |
| 50 | 46 |
| 51 void FUNCTION_NAME(File_GetPointer)(Dart_NativeArguments args) { | 47 void FUNCTION_NAME(File_GetPointer)(Dart_NativeArguments args) { |
| 52 File* file = GetFile(args); | 48 File* file = GetFile(args); |
| 53 // If the file is already closed, GetFile() will return NULL. | 49 // If the file is already closed, GetFile() will return NULL. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 dart_args[0] = external_array; | 172 dart_args[0] = external_array; |
| 177 dart_args[1] = Dart_NewInteger(0); | 173 dart_args[1] = Dart_NewInteger(0); |
| 178 dart_args[2] = Dart_NewInteger(bytes_read); | 174 dart_args[2] = Dart_NewInteger(bytes_read); |
| 179 // TODO(sgjesse): Cache the _makeUint8ListView function somewhere. | 175 // TODO(sgjesse): Cache the _makeUint8ListView function somewhere. |
| 180 Dart_Handle io_lib = | 176 Dart_Handle io_lib = |
| 181 Dart_LookupLibrary(DartUtils::NewString("dart:io")); | 177 Dart_LookupLibrary(DartUtils::NewString("dart:io")); |
| 182 if (Dart_IsError(io_lib)) { | 178 if (Dart_IsError(io_lib)) { |
| 183 Dart_PropagateError(io_lib); | 179 Dart_PropagateError(io_lib); |
| 184 } | 180 } |
| 185 Dart_Handle array_view = | 181 Dart_Handle array_view = |
| 186 Dart_Invoke(io_lib, | 182 Dart_Invoke(io_lib, DartUtils::NewString("_makeUint8ListView"), |
| 187 DartUtils::NewString("_makeUint8ListView"), | 183 kNumArgs, dart_args); |
| 188 kNumArgs, | |
| 189 dart_args); | |
| 190 Dart_SetReturnValue(args, array_view); | 184 Dart_SetReturnValue(args, array_view); |
| 191 } else { | 185 } else { |
| 192 Dart_SetReturnValue(args, external_array); | 186 Dart_SetReturnValue(args, external_array); |
| 193 } | 187 } |
| 194 } | 188 } |
| 195 } else { | 189 } else { |
| 196 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | 190 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| 197 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); | 191 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
| 198 } | 192 } |
| 199 } | 193 } |
| 200 | 194 |
| 201 | 195 |
| 202 void FUNCTION_NAME(File_ReadInto)(Dart_NativeArguments args) { | 196 void FUNCTION_NAME(File_ReadInto)(Dart_NativeArguments args) { |
| 203 File* file = GetFile(args); | 197 File* file = GetFile(args); |
| 204 ASSERT(file != NULL); | 198 ASSERT(file != NULL); |
| 205 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 199 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 206 ASSERT(Dart_IsList(buffer_obj)); | 200 ASSERT(Dart_IsList(buffer_obj)); |
| 207 // start and end arguments are checked in Dart code to be | 201 // start and end arguments are checked in Dart code to be |
| 208 // integers and have the property that end <= | 202 // integers and have the property that end <= |
| 209 // list.length. Therefore, it is safe to extract their value as | 203 // list.length. Therefore, it is safe to extract their value as |
| 210 // intptr_t. | 204 // intptr_t. |
| 211 intptr_t start = | 205 intptr_t start = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); |
| 212 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); | 206 intptr_t end = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); |
| 213 intptr_t end = | |
| 214 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); | |
| 215 intptr_t length = end - start; | 207 intptr_t length = end - start; |
| 216 intptr_t array_len = 0; | 208 intptr_t array_len = 0; |
| 217 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); | 209 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); |
| 218 if (Dart_IsError(result)) { | 210 if (Dart_IsError(result)) { |
| 219 Dart_PropagateError(result); | 211 Dart_PropagateError(result); |
| 220 } | 212 } |
| 221 ASSERT(end <= array_len); | 213 ASSERT(end <= array_len); |
| 222 uint8_t* buffer = Dart_ScopeAllocate(length); | 214 uint8_t* buffer = Dart_ScopeAllocate(length); |
| 223 int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); | 215 int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); |
| 224 if (bytes_read >= 0) { | 216 if (bytes_read >= 0) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 237 void FUNCTION_NAME(File_WriteFrom)(Dart_NativeArguments args) { | 229 void FUNCTION_NAME(File_WriteFrom)(Dart_NativeArguments args) { |
| 238 File* file = GetFile(args); | 230 File* file = GetFile(args); |
| 239 ASSERT(file != NULL); | 231 ASSERT(file != NULL); |
| 240 | 232 |
| 241 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 233 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 242 | 234 |
| 243 // Offset and length arguments are checked in Dart code to be | 235 // Offset and length arguments are checked in Dart code to be |
| 244 // integers and have the property that (offset + length) <= | 236 // integers and have the property that (offset + length) <= |
| 245 // list.length. Therefore, it is safe to extract their value as | 237 // list.length. Therefore, it is safe to extract their value as |
| 246 // intptr_t. | 238 // intptr_t. |
| 247 intptr_t start = | 239 intptr_t start = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); |
| 248 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); | 240 intptr_t end = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); |
| 249 intptr_t end = | |
| 250 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); | |
| 251 | 241 |
| 252 // The buffer object passed in has to be an Int8List or Uint8List object. | 242 // The buffer object passed in has to be an Int8List or Uint8List object. |
| 253 // Acquire a direct pointer to the data area of the buffer object. | 243 // Acquire a direct pointer to the data area of the buffer object. |
| 254 Dart_TypedData_Type type; | 244 Dart_TypedData_Type type; |
| 255 intptr_t length = end - start; | 245 intptr_t length = end - start; |
| 256 intptr_t buffer_len = 0; | 246 intptr_t buffer_len = 0; |
| 257 void* buffer = NULL; | 247 void* buffer = NULL; |
| 258 Dart_Handle result = | 248 Dart_Handle result = |
| 259 Dart_TypedDataAcquireData(buffer_obj, &type, &buffer, &buffer_len); | 249 Dart_TypedDataAcquireData(buffer_obj, &type, &buffer, &buffer_len); |
| 260 if (Dart_IsError(result)) { | 250 if (Dart_IsError(result)) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 int64_t return_value = file->Length(); | 324 int64_t return_value = file->Length(); |
| 335 if (return_value >= 0) { | 325 if (return_value >= 0) { |
| 336 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 326 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 337 } else { | 327 } else { |
| 338 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 328 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 339 } | 329 } |
| 340 } | 330 } |
| 341 | 331 |
| 342 | 332 |
| 343 void FUNCTION_NAME(File_LengthFromPath)(Dart_NativeArguments args) { | 333 void FUNCTION_NAME(File_LengthFromPath)(Dart_NativeArguments args) { |
| 344 const char* path = | 334 const char* path = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 345 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | |
| 346 int64_t return_value = File::LengthFromPath(path); | 335 int64_t return_value = File::LengthFromPath(path); |
| 347 if (return_value >= 0) { | 336 if (return_value >= 0) { |
| 348 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 337 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 349 } else { | 338 } else { |
| 350 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 339 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 351 } | 340 } |
| 352 } | 341 } |
| 353 | 342 |
| 354 | 343 |
| 355 void FUNCTION_NAME(File_LastModified)(Dart_NativeArguments args) { | 344 void FUNCTION_NAME(File_LastModified)(Dart_NativeArguments args) { |
| 356 const char* name = | 345 const char* name = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 357 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | |
| 358 int64_t return_value = File::LastModified(name); | 346 int64_t return_value = File::LastModified(name); |
| 359 if (return_value >= 0) { | 347 if (return_value >= 0) { |
| 360 Dart_SetReturnValue(args, Dart_NewInteger(return_value * kMSPerSecond)); | 348 Dart_SetReturnValue(args, Dart_NewInteger(return_value * kMSPerSecond)); |
| 361 } else { | 349 } else { |
| 362 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 350 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 363 } | 351 } |
| 364 } | 352 } |
| 365 | 353 |
| 366 | 354 |
| 367 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { | 355 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { |
| 368 File* file = GetFile(args); | 356 File* file = GetFile(args); |
| 369 ASSERT(file != NULL); | 357 ASSERT(file != NULL); |
| 370 if (file->Flush()) { | 358 if (file->Flush()) { |
| 371 Dart_SetReturnValue(args, Dart_True()); | 359 Dart_SetReturnValue(args, Dart_True()); |
| 372 } else { | 360 } else { |
| 373 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 361 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 374 } | 362 } |
| 375 } | 363 } |
| 376 | 364 |
| 377 | 365 |
| 378 void FUNCTION_NAME(File_Lock)(Dart_NativeArguments args) { | 366 void FUNCTION_NAME(File_Lock)(Dart_NativeArguments args) { |
| 379 File* file = GetFile(args); | 367 File* file = GetFile(args); |
| 380 ASSERT(file != NULL); | 368 ASSERT(file != NULL); |
| 381 int64_t lock; | 369 int64_t lock; |
| 382 int64_t start; | 370 int64_t start; |
| 383 int64_t end; | 371 int64_t end; |
| 384 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &lock) && | 372 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &lock) && |
| 385 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &start) && | 373 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &start) && |
| 386 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 3), &end)) { | 374 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 3), &end)) { |
| 387 if ((lock >= File::kLockMin) && (lock <= File::kLockMax) && | 375 if ((lock >= File::kLockMin) && (lock <= File::kLockMax) && (start >= 0) && |
| 388 (start >= 0) && (end == -1 || end > start)) { | 376 (end == -1 || end > start)) { |
| 389 if (file->Lock(static_cast<File::LockType>(lock), start, end)) { | 377 if (file->Lock(static_cast<File::LockType>(lock), start, end)) { |
| 390 Dart_SetReturnValue(args, Dart_True()); | 378 Dart_SetReturnValue(args, Dart_True()); |
| 391 } else { | 379 } else { |
| 392 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 380 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 393 } | 381 } |
| 394 return; | 382 return; |
| 395 } | 383 } |
| 396 } | 384 } |
| 397 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | 385 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| 398 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); | 386 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
| 399 } | 387 } |
| 400 | 388 |
| 401 | 389 |
| 402 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { | 390 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { |
| 403 const char* str = | 391 const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 404 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | |
| 405 bool result = File::Create(str); | 392 bool result = File::Create(str); |
| 406 if (result) { | 393 if (result) { |
| 407 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 394 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| 408 } else { | 395 } else { |
| 409 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 396 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 410 } | 397 } |
| 411 } | 398 } |
| 412 | 399 |
| 413 | 400 |
| 414 void FUNCTION_NAME(File_CreateLink)(Dart_NativeArguments args) { | 401 void FUNCTION_NAME(File_CreateLink)(Dart_NativeArguments args) { |
| 415 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) && | 402 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) && |
| 416 Dart_IsString(Dart_GetNativeArgument(args, 1))) { | 403 Dart_IsString(Dart_GetNativeArgument(args, 1))) { |
| 417 const char* name = | 404 const char* name = |
| 418 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 405 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 419 const char* target = | 406 const char* target = |
| 420 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); | 407 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
| 421 if (!File::CreateLink(name, target)) { | 408 if (!File::CreateLink(name, target)) { |
| 422 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 409 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 423 } | 410 } |
| 424 } else { | 411 } else { |
| 425 Dart_Handle err = DartUtils::NewDartArgumentError( | 412 Dart_Handle err = |
| 426 "Non-string argument to Link.create"); | 413 DartUtils::NewDartArgumentError("Non-string argument to Link.create"); |
| 427 Dart_SetReturnValue(args, err); | 414 Dart_SetReturnValue(args, err); |
| 428 } | 415 } |
| 429 } | 416 } |
| 430 | 417 |
| 431 | 418 |
| 432 void FUNCTION_NAME(File_LinkTarget)(Dart_NativeArguments args) { | 419 void FUNCTION_NAME(File_LinkTarget)(Dart_NativeArguments args) { |
| 433 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) { | 420 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) { |
| 434 const char* name = | 421 const char* name = |
| 435 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 422 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 436 const char* target = File::LinkTarget(name); | 423 const char* target = File::LinkTarget(name); |
| 437 if (target == NULL) { | 424 if (target == NULL) { |
| 438 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 425 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 439 } else { | 426 } else { |
| 440 Dart_SetReturnValue(args, DartUtils::NewString(target)); | 427 Dart_SetReturnValue(args, DartUtils::NewString(target)); |
| 441 } | 428 } |
| 442 } else { | 429 } else { |
| 443 Dart_Handle err = DartUtils::NewDartArgumentError( | 430 Dart_Handle err = |
| 444 "Non-string argument to Link.target"); | 431 DartUtils::NewDartArgumentError("Non-string argument to Link.target"); |
| 445 Dart_SetReturnValue(args, err); | 432 Dart_SetReturnValue(args, err); |
| 446 } | 433 } |
| 447 } | 434 } |
| 448 | 435 |
| 449 | 436 |
| 450 void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) { | 437 void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) { |
| 451 const char* str = | 438 const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 452 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | |
| 453 bool result = File::Delete(str); | 439 bool result = File::Delete(str); |
| 454 if (result) { | 440 if (result) { |
| 455 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 441 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| 456 } else { | 442 } else { |
| 457 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 443 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 458 } | 444 } |
| 459 } | 445 } |
| 460 | 446 |
| 461 | 447 |
| 462 void FUNCTION_NAME(File_DeleteLink)(Dart_NativeArguments args) { | 448 void FUNCTION_NAME(File_DeleteLink)(Dart_NativeArguments args) { |
| 463 const char* str = | 449 const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 464 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | |
| 465 bool result = File::DeleteLink(str); | 450 bool result = File::DeleteLink(str); |
| 466 if (result) { | 451 if (result) { |
| 467 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 452 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| 468 } else { | 453 } else { |
| 469 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 454 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 470 } | 455 } |
| 471 } | 456 } |
| 472 | 457 |
| 473 | 458 |
| 474 void FUNCTION_NAME(File_Rename)(Dart_NativeArguments args) { | 459 void FUNCTION_NAME(File_Rename)(Dart_NativeArguments args) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 bool result = File::Copy(old_path, new_path); | 492 bool result = File::Copy(old_path, new_path); |
| 508 if (result) { | 493 if (result) { |
| 509 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 494 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| 510 } else { | 495 } else { |
| 511 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 496 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 512 } | 497 } |
| 513 } | 498 } |
| 514 | 499 |
| 515 | 500 |
| 516 void FUNCTION_NAME(File_ResolveSymbolicLinks)(Dart_NativeArguments args) { | 501 void FUNCTION_NAME(File_ResolveSymbolicLinks)(Dart_NativeArguments args) { |
| 517 const char* str = | 502 const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 518 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | |
| 519 const char* path = File::GetCanonicalPath(str); | 503 const char* path = File::GetCanonicalPath(str); |
| 520 if (path != NULL) { | 504 if (path != NULL) { |
| 521 Dart_SetReturnValue(args, DartUtils::NewString(path)); | 505 Dart_SetReturnValue(args, DartUtils::NewString(path)); |
| 522 } else { | 506 } else { |
| 523 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 507 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 524 } | 508 } |
| 525 } | 509 } |
| 526 | 510 |
| 527 | 511 |
| 528 void FUNCTION_NAME(File_OpenStdio)(Dart_NativeArguments args) { | 512 void FUNCTION_NAME(File_OpenStdio)(Dart_NativeArguments args) { |
| 529 int64_t fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 513 int64_t fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 530 ASSERT((fd == STDIN_FILENO) || | 514 ASSERT((fd == STDIN_FILENO) || (fd == STDOUT_FILENO) || |
| 531 (fd == STDOUT_FILENO) || | |
| 532 (fd == STDERR_FILENO)); | 515 (fd == STDERR_FILENO)); |
| 533 File* file = File::OpenStdio(static_cast<int>(fd)); | 516 File* file = File::OpenStdio(static_cast<int>(fd)); |
| 534 Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file))); | 517 Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file))); |
| 535 } | 518 } |
| 536 | 519 |
| 537 | 520 |
| 538 void FUNCTION_NAME(File_GetStdioHandleType)(Dart_NativeArguments args) { | 521 void FUNCTION_NAME(File_GetStdioHandleType)(Dart_NativeArguments args) { |
| 539 int64_t fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 522 int64_t fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 540 ASSERT((fd == STDIN_FILENO) || | 523 ASSERT((fd == STDIN_FILENO) || (fd == STDOUT_FILENO) || |
| 541 (fd == STDOUT_FILENO) || | |
| 542 (fd == STDERR_FILENO)); | 524 (fd == STDERR_FILENO)); |
| 543 File::StdioHandleType type = File::GetStdioHandleType(static_cast<int>(fd)); | 525 File::StdioHandleType type = File::GetStdioHandleType(static_cast<int>(fd)); |
| 544 Dart_SetReturnValue(args, Dart_NewInteger(type)); | 526 Dart_SetReturnValue(args, Dart_NewInteger(type)); |
| 545 } | 527 } |
| 546 | 528 |
| 547 | 529 |
| 548 void FUNCTION_NAME(File_GetType)(Dart_NativeArguments args) { | 530 void FUNCTION_NAME(File_GetType)(Dart_NativeArguments args) { |
| 549 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) && | 531 if (Dart_IsString(Dart_GetNativeArgument(args, 0)) && |
| 550 Dart_IsBoolean(Dart_GetNativeArgument(args, 1))) { | 532 Dart_IsBoolean(Dart_GetNativeArgument(args, 1))) { |
| 551 const char* str = | 533 const char* str = |
| 552 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 534 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 553 bool follow_links = | 535 bool follow_links = |
| 554 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 1)); | 536 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 1)); |
| 555 File::Type type = File::GetType(str, follow_links); | 537 File::Type type = File::GetType(str, follow_links); |
| 556 Dart_SetReturnValue(args, Dart_NewInteger(static_cast<int>(type))); | 538 Dart_SetReturnValue(args, Dart_NewInteger(static_cast<int>(type))); |
| 557 } else { | 539 } else { |
| 558 Dart_Handle err = DartUtils::NewDartArgumentError( | 540 Dart_Handle err = DartUtils::NewDartArgumentError( |
| 559 "Non-string argument to FileSystemEntity.type"); | 541 "Non-string argument to FileSystemEntity.type"); |
| 560 Dart_SetReturnValue(args, err); | 542 Dart_SetReturnValue(args, err); |
| 561 } | 543 } |
| 562 } | 544 } |
| 563 | 545 |
| 564 | 546 |
| 565 void FUNCTION_NAME(File_Stat)(Dart_NativeArguments args) { | 547 void FUNCTION_NAME(File_Stat)(Dart_NativeArguments args) { |
| 566 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) { | 548 if (Dart_IsString(Dart_GetNativeArgument(args, 0))) { |
| 567 const char* path = | 549 const char* path = |
| 568 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 550 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 569 | 551 |
| 570 int64_t stat_data[File::kStatSize]; | 552 int64_t stat_data[File::kStatSize]; |
| 571 File::Stat(path, stat_data); | 553 File::Stat(path, stat_data); |
| 572 if (stat_data[File::kType] == File::kDoesNotExist) { | 554 if (stat_data[File::kType] == File::kDoesNotExist) { |
| 573 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 555 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 574 } else { | 556 } else { |
| 575 Dart_Handle returned_data = Dart_NewTypedData(Dart_TypedData_kInt64, | 557 Dart_Handle returned_data = |
| 576 File::kStatSize); | 558 Dart_NewTypedData(Dart_TypedData_kInt64, File::kStatSize); |
| 577 if (Dart_IsError(returned_data)) { | 559 if (Dart_IsError(returned_data)) { |
| 578 Dart_PropagateError(returned_data); | 560 Dart_PropagateError(returned_data); |
| 579 } | 561 } |
| 580 Dart_TypedData_Type data_type_unused; | 562 Dart_TypedData_Type data_type_unused; |
| 581 void* data_location; | 563 void* data_location; |
| 582 intptr_t data_length_unused; | 564 intptr_t data_length_unused; |
| 583 Dart_Handle status = Dart_TypedDataAcquireData(returned_data, | 565 Dart_Handle status = |
| 584 &data_type_unused, | 566 Dart_TypedDataAcquireData(returned_data, &data_type_unused, |
| 585 &data_location, | 567 &data_location, &data_length_unused); |
| 586 &data_length_unused); | |
| 587 if (Dart_IsError(status)) { | 568 if (Dart_IsError(status)) { |
| 588 Dart_PropagateError(status); | 569 Dart_PropagateError(status); |
| 589 } | 570 } |
| 590 memmove(data_location, stat_data, File::kStatSize * sizeof(int64_t)); | 571 memmove(data_location, stat_data, File::kStatSize * sizeof(int64_t)); |
| 591 status = Dart_TypedDataReleaseData(returned_data); | 572 status = Dart_TypedDataReleaseData(returned_data); |
| 592 if (Dart_IsError(status)) { | 573 if (Dart_IsError(status)) { |
| 593 Dart_PropagateError(status); | 574 Dart_PropagateError(status); |
| 594 } | 575 } |
| 595 Dart_SetReturnValue(args, returned_data); | 576 Dart_SetReturnValue(args, returned_data); |
| 596 } | 577 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 608 const char* path_1 = | 589 const char* path_1 = |
| 609 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 590 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 610 const char* path_2 = | 591 const char* path_2 = |
| 611 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); | 592 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
| 612 File::Identical result = File::AreIdentical(path_1, path_2); | 593 File::Identical result = File::AreIdentical(path_1, path_2); |
| 613 if (result == File::kError) { | 594 if (result == File::kError) { |
| 614 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 595 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 615 } else { | 596 } else { |
| 616 Dart_SetReturnValue(args, Dart_NewBoolean(result == File::kIdentical)); | 597 Dart_SetReturnValue(args, Dart_NewBoolean(result == File::kIdentical)); |
| 617 } | 598 } |
| 618 } else { | 599 } else { |
| 619 Dart_Handle err = DartUtils::NewDartArgumentError( | 600 Dart_Handle err = DartUtils::NewDartArgumentError( |
| 620 "Non-string argument to FileSystemEntity.identical"); | 601 "Non-string argument to FileSystemEntity.identical"); |
| 621 Dart_SetReturnValue(args, err); | 602 Dart_SetReturnValue(args, err); |
| 622 } | 603 } |
| 623 } | 604 } |
| 624 | 605 |
| 625 | 606 |
| 626 static int64_t CObjectInt32OrInt64ToInt64(CObject* cobject) { | 607 static int64_t CObjectInt32OrInt64ToInt64(CObject* cobject) { |
| 627 ASSERT(cobject->IsInt32OrInt64()); | 608 ASSERT(cobject->IsInt32OrInt64()); |
| 628 int64_t result; | 609 int64_t result; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 } else { | 643 } else { |
| 663 return CObject::NewOSError(); | 644 return CObject::NewOSError(); |
| 664 } | 645 } |
| 665 } | 646 } |
| 666 return CObject::IllegalArgumentError(); | 647 return CObject::IllegalArgumentError(); |
| 667 } | 648 } |
| 668 | 649 |
| 669 | 650 |
| 670 CObject* File::OpenRequest(const CObjectArray& request) { | 651 CObject* File::OpenRequest(const CObjectArray& request) { |
| 671 File* file = NULL; | 652 File* file = NULL; |
| 672 if ((request.Length() == 2) && | 653 if ((request.Length() == 2) && request[0]->IsString() && |
| 673 request[0]->IsString() && | |
| 674 request[1]->IsInt32()) { | 654 request[1]->IsInt32()) { |
| 675 CObjectString filename(request[0]); | 655 CObjectString filename(request[0]); |
| 676 CObjectInt32 mode(request[1]); | 656 CObjectInt32 mode(request[1]); |
| 677 File::DartFileOpenMode dart_file_mode = | 657 File::DartFileOpenMode dart_file_mode = |
| 678 static_cast<File::DartFileOpenMode>(mode.Value()); | 658 static_cast<File::DartFileOpenMode>(mode.Value()); |
| 679 File::FileOpenMode file_mode = File::DartModeToFileMode(dart_file_mode); | 659 File::FileOpenMode file_mode = File::DartModeToFileMode(dart_file_mode); |
| 680 file = File::Open(filename.CString(), file_mode); | 660 file = File::Open(filename.CString(), file_mode); |
| 681 if (file != NULL) { | 661 if (file != NULL) { |
| 682 return new CObjectIntptr( | 662 return new CObjectIntptr( |
| 683 CObject::NewIntptr(reinterpret_cast<intptr_t>(file))); | 663 CObject::NewIntptr(reinterpret_cast<intptr_t>(file))); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 697 return CObject::True(); | 677 return CObject::True(); |
| 698 } else { | 678 } else { |
| 699 return CObject::NewOSError(); | 679 return CObject::NewOSError(); |
| 700 } | 680 } |
| 701 } | 681 } |
| 702 return CObject::False(); | 682 return CObject::False(); |
| 703 } | 683 } |
| 704 | 684 |
| 705 | 685 |
| 706 CObject* File::RenameRequest(const CObjectArray& request) { | 686 CObject* File::RenameRequest(const CObjectArray& request) { |
| 707 if ((request.Length() == 2) && | 687 if ((request.Length() == 2) && request[0]->IsString() && |
| 708 request[0]->IsString() && | |
| 709 request[1]->IsString()) { | 688 request[1]->IsString()) { |
| 710 CObjectString old_path(request[0]); | 689 CObjectString old_path(request[0]); |
| 711 CObjectString new_path(request[1]); | 690 CObjectString new_path(request[1]); |
| 712 bool completed = File::Rename(old_path.CString(), new_path.CString()); | 691 bool completed = File::Rename(old_path.CString(), new_path.CString()); |
| 713 if (completed) { | 692 if (completed) { |
| 714 return CObject::True(); | 693 return CObject::True(); |
| 715 } | 694 } |
| 716 return CObject::NewOSError(); | 695 return CObject::NewOSError(); |
| 717 } | 696 } |
| 718 return CObject::IllegalArgumentError(); | 697 return CObject::IllegalArgumentError(); |
| 719 } | 698 } |
| 720 | 699 |
| 721 | 700 |
| 722 CObject* File::CopyRequest(const CObjectArray& request) { | 701 CObject* File::CopyRequest(const CObjectArray& request) { |
| 723 if ((request.Length() == 2) && | 702 if ((request.Length() == 2) && request[0]->IsString() && |
| 724 request[0]->IsString() && | |
| 725 request[1]->IsString()) { | 703 request[1]->IsString()) { |
| 726 CObjectString old_path(request[0]); | 704 CObjectString old_path(request[0]); |
| 727 CObjectString new_path(request[1]); | 705 CObjectString new_path(request[1]); |
| 728 bool completed = File::Copy(old_path.CString(), new_path.CString()); | 706 bool completed = File::Copy(old_path.CString(), new_path.CString()); |
| 729 if (completed) { | 707 if (completed) { |
| 730 return CObject::True(); | 708 return CObject::True(); |
| 731 } | 709 } |
| 732 return CObject::NewOSError(); | 710 return CObject::NewOSError(); |
| 733 } | 711 } |
| 734 return CObject::IllegalArgumentError(); | 712 return CObject::IllegalArgumentError(); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 return -1; | 1017 return -1; |
| 1040 } | 1018 } |
| 1041 | 1019 |
| 1042 | 1020 |
| 1043 CObject* File::WriteFromRequest(const CObjectArray& request) { | 1021 CObject* File::WriteFromRequest(const CObjectArray& request) { |
| 1044 if ((request.Length() >= 1) && request[0]->IsIntptr()) { | 1022 if ((request.Length() >= 1) && request[0]->IsIntptr()) { |
| 1045 File* file = CObjectToFilePointer(request[0]); | 1023 File* file = CObjectToFilePointer(request[0]); |
| 1046 RefCntReleaseScope<File> rs(file); | 1024 RefCntReleaseScope<File> rs(file); |
| 1047 if ((request.Length() == 4) && | 1025 if ((request.Length() == 4) && |
| 1048 (request[1]->IsTypedData() || request[1]->IsArray()) && | 1026 (request[1]->IsTypedData() || request[1]->IsArray()) && |
| 1049 request[2]->IsInt32OrInt64() && | 1027 request[2]->IsInt32OrInt64() && request[3]->IsInt32OrInt64()) { |
| 1050 request[3]->IsInt32OrInt64()) { | |
| 1051 if (!file->IsClosed()) { | 1028 if (!file->IsClosed()) { |
| 1052 int64_t start = CObjectInt32OrInt64ToInt64(request[2]); | 1029 int64_t start = CObjectInt32OrInt64ToInt64(request[2]); |
| 1053 int64_t end = CObjectInt32OrInt64ToInt64(request[3]); | 1030 int64_t end = CObjectInt32OrInt64ToInt64(request[3]); |
| 1054 int64_t length = end - start; | 1031 int64_t length = end - start; |
| 1055 uint8_t* buffer_start; | 1032 uint8_t* buffer_start; |
| 1056 if (request[1]->IsTypedData()) { | 1033 if (request[1]->IsTypedData()) { |
| 1057 CObjectTypedData typed_data(request[1]); | 1034 CObjectTypedData typed_data(request[1]); |
| 1058 start = start * SizeInBytes(typed_data.Type()); | 1035 start = start * SizeInBytes(typed_data.Type()); |
| 1059 length = length * SizeInBytes(typed_data.Type()); | 1036 length = length * SizeInBytes(typed_data.Type()); |
| 1060 buffer_start = typed_data.Buffer() + start; | 1037 buffer_start = typed_data.Buffer() + start; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1084 } | 1061 } |
| 1085 } else { | 1062 } else { |
| 1086 return CObject::IllegalArgumentError(); | 1063 return CObject::IllegalArgumentError(); |
| 1087 } | 1064 } |
| 1088 } | 1065 } |
| 1089 return CObject::IllegalArgumentError(); | 1066 return CObject::IllegalArgumentError(); |
| 1090 } | 1067 } |
| 1091 | 1068 |
| 1092 | 1069 |
| 1093 CObject* File::CreateLinkRequest(const CObjectArray& request) { | 1070 CObject* File::CreateLinkRequest(const CObjectArray& request) { |
| 1094 if ((request.Length() != 2) || | 1071 if ((request.Length() != 2) || !request[0]->IsString() || |
| 1095 !request[0]->IsString() || | |
| 1096 !request[1]->IsString()) { | 1072 !request[1]->IsString()) { |
| 1097 return CObject::IllegalArgumentError(); | 1073 return CObject::IllegalArgumentError(); |
| 1098 } | 1074 } |
| 1099 CObjectString link_name(request[0]); | 1075 CObjectString link_name(request[0]); |
| 1100 CObjectString target_name(request[1]); | 1076 CObjectString target_name(request[1]); |
| 1101 if (File::CreateLink(link_name.CString(), target_name.CString())) { | 1077 if (File::CreateLink(link_name.CString(), target_name.CString())) { |
| 1102 return CObject::True(); | 1078 return CObject::True(); |
| 1103 } else { | 1079 } else { |
| 1104 return CObject::NewOSError(); | 1080 return CObject::NewOSError(); |
| 1105 } | 1081 } |
| 1106 } | 1082 } |
| 1107 | 1083 |
| 1108 | 1084 |
| 1109 CObject* File::DeleteLinkRequest(const CObjectArray& request) { | 1085 CObject* File::DeleteLinkRequest(const CObjectArray& request) { |
| 1110 if ((request.Length() == 1) && request[0]->IsString()) { | 1086 if ((request.Length() == 1) && request[0]->IsString()) { |
| 1111 CObjectString link_path(request[0]); | 1087 CObjectString link_path(request[0]); |
| 1112 bool result = File::DeleteLink(link_path.CString()); | 1088 bool result = File::DeleteLink(link_path.CString()); |
| 1113 if (result) { | 1089 if (result) { |
| 1114 return CObject::True(); | 1090 return CObject::True(); |
| 1115 } else { | 1091 } else { |
| 1116 return CObject::NewOSError(); | 1092 return CObject::NewOSError(); |
| 1117 } | 1093 } |
| 1118 } | 1094 } |
| 1119 return CObject::IllegalArgumentError(); | 1095 return CObject::IllegalArgumentError(); |
| 1120 } | 1096 } |
| 1121 | 1097 |
| 1122 | 1098 |
| 1123 CObject* File::RenameLinkRequest(const CObjectArray& request) { | 1099 CObject* File::RenameLinkRequest(const CObjectArray& request) { |
| 1124 if ((request.Length() == 2) && | 1100 if ((request.Length() == 2) && request[0]->IsString() && |
| 1125 request[0]->IsString() && | |
| 1126 request[1]->IsString()) { | 1101 request[1]->IsString()) { |
| 1127 CObjectString old_path(request[0]); | 1102 CObjectString old_path(request[0]); |
| 1128 CObjectString new_path(request[1]); | 1103 CObjectString new_path(request[1]); |
| 1129 bool completed = File::RenameLink(old_path.CString(), new_path.CString()); | 1104 bool completed = File::RenameLink(old_path.CString(), new_path.CString()); |
| 1130 if (completed) { | 1105 if (completed) { |
| 1131 return CObject::True(); | 1106 return CObject::True(); |
| 1132 } | 1107 } |
| 1133 return CObject::NewOSError(); | 1108 return CObject::NewOSError(); |
| 1134 } | 1109 } |
| 1135 return CObject::IllegalArgumentError(); | 1110 return CObject::IllegalArgumentError(); |
| 1136 } | 1111 } |
| 1137 | 1112 |
| 1138 | 1113 |
| 1139 CObject* File::LinkTargetRequest(const CObjectArray& request) { | 1114 CObject* File::LinkTargetRequest(const CObjectArray& request) { |
| 1140 if ((request.Length() == 1) && request[0]->IsString()) { | 1115 if ((request.Length() == 1) && request[0]->IsString()) { |
| 1141 CObjectString link_path(request[0]); | 1116 CObjectString link_path(request[0]); |
| 1142 const char* target = File::LinkTarget(link_path.CString()); | 1117 const char* target = File::LinkTarget(link_path.CString()); |
| 1143 if (target != NULL) { | 1118 if (target != NULL) { |
| 1144 CObject* result = new CObjectString(CObject::NewString(target)); | 1119 CObject* result = new CObjectString(CObject::NewString(target)); |
| 1145 return result; | 1120 return result; |
| 1146 } else { | 1121 } else { |
| 1147 return CObject::NewOSError(); | 1122 return CObject::NewOSError(); |
| 1148 } | 1123 } |
| 1149 } | 1124 } |
| 1150 return CObject::IllegalArgumentError(); | 1125 return CObject::IllegalArgumentError(); |
| 1151 } | 1126 } |
| 1152 | 1127 |
| 1153 | 1128 |
| 1154 CObject* File::TypeRequest(const CObjectArray& request) { | 1129 CObject* File::TypeRequest(const CObjectArray& request) { |
| 1155 if ((request.Length() == 2) && | 1130 if ((request.Length() == 2) && request[0]->IsString() && |
| 1156 request[0]->IsString() && | |
| 1157 request[1]->IsBool()) { | 1131 request[1]->IsBool()) { |
| 1158 CObjectString path(request[0]); | 1132 CObjectString path(request[0]); |
| 1159 CObjectBool follow_links(request[1]); | 1133 CObjectBool follow_links(request[1]); |
| 1160 File::Type type = File::GetType(path.CString(), follow_links.Value()); | 1134 File::Type type = File::GetType(path.CString(), follow_links.Value()); |
| 1161 return new CObjectInt32(CObject::NewInt32(type)); | 1135 return new CObjectInt32(CObject::NewInt32(type)); |
| 1162 } | 1136 } |
| 1163 return CObject::IllegalArgumentError(); | 1137 return CObject::IllegalArgumentError(); |
| 1164 } | 1138 } |
| 1165 | 1139 |
| 1166 | 1140 |
| 1167 CObject* File::IdenticalRequest(const CObjectArray& request) { | 1141 CObject* File::IdenticalRequest(const CObjectArray& request) { |
| 1168 if ((request.Length() == 2) && | 1142 if ((request.Length() == 2) && request[0]->IsString() && |
| 1169 request[0]->IsString() && | |
| 1170 request[1]->IsString()) { | 1143 request[1]->IsString()) { |
| 1171 CObjectString path1(request[0]); | 1144 CObjectString path1(request[0]); |
| 1172 CObjectString path2(request[1]); | 1145 CObjectString path2(request[1]); |
| 1173 File::Identical result = File::AreIdentical(path1.CString(), | 1146 File::Identical result = |
| 1174 path2.CString()); | 1147 File::AreIdentical(path1.CString(), path2.CString()); |
| 1175 if (result == File::kError) { | 1148 if (result == File::kError) { |
| 1176 return CObject::NewOSError(); | 1149 return CObject::NewOSError(); |
| 1177 } else if (result == File::kIdentical) { | 1150 } else if (result == File::kIdentical) { |
| 1178 return CObject::True(); | 1151 return CObject::True(); |
| 1179 } else { | 1152 } else { |
| 1180 return CObject::False(); | 1153 return CObject::False(); |
| 1181 } | 1154 } |
| 1182 } | 1155 } |
| 1183 return CObject::IllegalArgumentError(); | 1156 return CObject::IllegalArgumentError(); |
| 1184 } | 1157 } |
| 1185 | 1158 |
| 1186 | 1159 |
| 1187 CObject* File::StatRequest(const CObjectArray& request) { | 1160 CObject* File::StatRequest(const CObjectArray& request) { |
| 1188 if ((request.Length() == 1) && request[0]->IsString()) { | 1161 if ((request.Length() == 1) && request[0]->IsString()) { |
| 1189 int64_t data[File::kStatSize]; | 1162 int64_t data[File::kStatSize]; |
| 1190 CObjectString path(request[0]); | 1163 CObjectString path(request[0]); |
| 1191 File::Stat(path.CString(), data); | 1164 File::Stat(path.CString(), data); |
| 1192 if (data[File::kType] == File::kDoesNotExist) { | 1165 if (data[File::kType] == File::kDoesNotExist) { |
| 1193 return CObject::NewOSError(); | 1166 return CObject::NewOSError(); |
| 1194 } | 1167 } |
| 1195 CObjectArray* result = | 1168 CObjectArray* result = new CObjectArray(CObject::NewArray(File::kStatSize)); |
| 1196 new CObjectArray(CObject::NewArray(File::kStatSize)); | |
| 1197 for (int i = 0; i < File::kStatSize; ++i) { | 1169 for (int i = 0; i < File::kStatSize; ++i) { |
| 1198 result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i]))); | 1170 result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i]))); |
| 1199 } | 1171 } |
| 1200 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); | 1172 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); |
| 1201 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); | 1173 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); |
| 1202 wrapper->SetAt(1, result); | 1174 wrapper->SetAt(1, result); |
| 1203 return wrapper; | 1175 return wrapper; |
| 1204 } | 1176 } |
| 1205 return CObject::IllegalArgumentError(); | 1177 return CObject::IllegalArgumentError(); |
| 1206 } | 1178 } |
| 1207 | 1179 |
| 1208 | 1180 |
| 1209 CObject* File::LockRequest(const CObjectArray& request) { | 1181 CObject* File::LockRequest(const CObjectArray& request) { |
| 1210 if ((request.Length() >= 1) && request[0]->IsIntptr()) { | 1182 if ((request.Length() >= 1) && request[0]->IsIntptr()) { |
| 1211 File* file = CObjectToFilePointer(request[0]); | 1183 File* file = CObjectToFilePointer(request[0]); |
| 1212 RefCntReleaseScope<File> rs(file); | 1184 RefCntReleaseScope<File> rs(file); |
| 1213 if ((request.Length() == 4) && | 1185 if ((request.Length() == 4) && request[1]->IsInt32OrInt64() && |
| 1214 request[1]->IsInt32OrInt64() && | 1186 request[2]->IsInt32OrInt64() && request[3]->IsInt32OrInt64()) { |
| 1215 request[2]->IsInt32OrInt64() && | |
| 1216 request[3]->IsInt32OrInt64()) { | |
| 1217 if (!file->IsClosed()) { | 1187 if (!file->IsClosed()) { |
| 1218 int64_t lock = CObjectInt32OrInt64ToInt64(request[1]); | 1188 int64_t lock = CObjectInt32OrInt64ToInt64(request[1]); |
| 1219 int64_t start = CObjectInt32OrInt64ToInt64(request[2]); | 1189 int64_t start = CObjectInt32OrInt64ToInt64(request[2]); |
| 1220 int64_t end = CObjectInt32OrInt64ToInt64(request[3]); | 1190 int64_t end = CObjectInt32OrInt64ToInt64(request[3]); |
| 1221 if (file->Lock(static_cast<File::LockType>(lock), start, end)) { | 1191 if (file->Lock(static_cast<File::LockType>(lock), start, end)) { |
| 1222 return CObject::True(); | 1192 return CObject::True(); |
| 1223 } else { | 1193 } else { |
| 1224 return CObject::NewOSError(); | 1194 return CObject::NewOSError(); |
| 1225 } | 1195 } |
| 1226 } else { | 1196 } else { |
| 1227 return CObject::FileClosedError(); | 1197 return CObject::FileClosedError(); |
| 1228 } | 1198 } |
| 1229 } else { | 1199 } else { |
| 1230 return CObject::IllegalArgumentError(); | 1200 return CObject::IllegalArgumentError(); |
| 1231 } | 1201 } |
| 1232 } | 1202 } |
| 1233 return CObject::IllegalArgumentError(); | 1203 return CObject::IllegalArgumentError(); |
| 1234 } | 1204 } |
| 1235 | 1205 |
| 1236 } // namespace bin | 1206 } // namespace bin |
| 1237 } // namespace dart | 1207 } // namespace dart |
| 1238 | 1208 |
| 1239 #endif // !defined(DART_IO_DISABLED) | 1209 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |