Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: runtime/bin/file.cc

Issue 10065013: Support length operation without opening file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix error message and fix Windows port Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/file.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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/thread.h" 9 #include "bin/thread.h"
10 #include "bin/utils.h" 10 #include "bin/utils.h"
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 if (Dart_IsError(err)) { 344 if (Dart_IsError(err)) {
345 Dart_PropagateError(err); 345 Dart_PropagateError(err);
346 } 346 }
347 Dart_SetReturnValue(args, err); 347 Dart_SetReturnValue(args, err);
348 } 348 }
349 } 349 }
350 Dart_ExitScope(); 350 Dart_ExitScope();
351 } 351 }
352 352
353 353
354 void FUNCTION_NAME(File_LengthFromName)(Dart_NativeArguments args) {
355 Dart_EnterScope();
356 const char* name =
357 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
358 intptr_t return_value = File::LengthFromName(name);
359 if (return_value >= 0) {
360 Dart_SetReturnValue(args, Dart_NewInteger(return_value));
361 } else {
362 Dart_Handle err = DartUtils::NewDartOSError();
363 if (Dart_IsError(err)) {
364 Dart_PropagateError(err);
365 }
366 Dart_SetReturnValue(args, err);
367 }
368 Dart_ExitScope();
369 }
370
371
354 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { 372 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) {
355 Dart_EnterScope(); 373 Dart_EnterScope();
356 intptr_t value = 374 intptr_t value =
357 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); 375 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
358 File* file = reinterpret_cast<File*>(value); 376 File* file = reinterpret_cast<File*>(value);
359 if (file != NULL) { 377 if (file != NULL) {
360 if (file->Flush()) { 378 if (file->Flush()) {
361 Dart_SetReturnValue(args, Dart_True()); 379 Dart_SetReturnValue(args, Dart_True());
362 } else { 380 } else {
363 Dart_Handle err = DartUtils::NewDartOSError(); 381 Dart_Handle err = DartUtils::NewDartOSError();
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 return CObject::NewOSError(); 678 return CObject::NewOSError();
661 } 679 }
662 } else { 680 } else {
663 return CObject::FileClosedError(); 681 return CObject::FileClosedError();
664 } 682 }
665 } 683 }
666 return CObject::IllegalArgumentError(); 684 return CObject::IllegalArgumentError();
667 } 685 }
668 686
669 687
688 static CObject* FileLengthFromNameRequest(const CObjectArray& request) {
689 if (request.Length() == 2 && request[1]->IsString()) {
690 CObjectString filename(request[1]);
691 intptr_t return_value = File::LengthFromName(filename.CString());
692 if (return_value >= 0) {
693 return new CObjectIntptr(CObject::NewIntptr(return_value));
694 } else {
695 return CObject::NewOSError();
696 }
697 }
698 return CObject::IllegalArgumentError();
699 }
700
701
670 static CObject* FileFlushRequest(const CObjectArray& request) { 702 static CObject* FileFlushRequest(const CObjectArray& request) {
671 intptr_t return_value = -1; 703 intptr_t return_value = -1;
672 if (request.Length() == 2 && request[1]->IsIntptr()) { 704 if (request.Length() == 2 && request[1]->IsIntptr()) {
673 File* file = CObjectToFilePointer(request[1]); 705 File* file = CObjectToFilePointer(request[1]);
674 if (file != NULL && !file->IsClosed()) { 706 if (file != NULL && !file->IsClosed()) {
675 if (file->Flush()) { 707 if (file->Flush()) {
676 return CObject::True(); 708 return CObject::True();
677 } else { 709 } else {
678 return CObject::NewOSError(); 710 return CObject::NewOSError();
679 } 711 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 break; 889 break;
858 case File::kSetPositionRequest: 890 case File::kSetPositionRequest:
859 response = FileSetPositionRequest(request); 891 response = FileSetPositionRequest(request);
860 break; 892 break;
861 case File::kTruncateRequest: 893 case File::kTruncateRequest:
862 response = FileTruncateRequest(request); 894 response = FileTruncateRequest(request);
863 break; 895 break;
864 case File::kLengthRequest: 896 case File::kLengthRequest:
865 response = FileLengthRequest(request); 897 response = FileLengthRequest(request);
866 break; 898 break;
899 case File::kLengthFromNameRequest:
900 response = FileLengthFromNameRequest(request);
901 break;
867 case File::kFlushRequest: 902 case File::kFlushRequest:
868 response = FileFlushRequest(request); 903 response = FileFlushRequest(request);
869 break; 904 break;
870 case File::kReadByteRequest: 905 case File::kReadByteRequest:
871 response = FileReadByteRequest(request); 906 response = FileReadByteRequest(request);
872 break; 907 break;
873 case File::kWriteByteRequest: 908 case File::kWriteByteRequest:
874 response = FileWriteByteRequest(request); 909 response = FileWriteByteRequest(request);
875 break; 910 break;
876 case File::kReadListRequest: 911 case File::kReadListRequest:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 Dart_EnterScope(); 956 Dart_EnterScope();
922 Dart_SetReturnValue(args, Dart_Null()); 957 Dart_SetReturnValue(args, Dart_Null());
923 Dart_Port service_port = File::GetServicePort(); 958 Dart_Port service_port = File::GetServicePort();
924 if (service_port != kIllegalPort) { 959 if (service_port != kIllegalPort) {
925 // Return a send port for the service port. 960 // Return a send port for the service port.
926 Dart_Handle send_port = Dart_NewSendPort(service_port); 961 Dart_Handle send_port = Dart_NewSendPort(service_port);
927 Dart_SetReturnValue(args, send_port); 962 Dart_SetReturnValue(args, send_port);
928 } 963 }
929 Dart_ExitScope(); 964 Dart_ExitScope();
930 } 965 }
OLDNEW
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/file.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698