| OLD | NEW | 
|    1 // Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file |    1 // Copyright (c) 2011, 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  |    9  | 
|   10 #include "include/dart_api.h" |   10 #include "include/dart_api.h" | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|   34       return false; |   34       return false; | 
|   35     } |   35     } | 
|   36     remaining -= bytes_read;  // Reduce the number of remaining bytes. |   36     remaining -= bytes_read;  // Reduce the number of remaining bytes. | 
|   37     current_buffer += bytes_read;  // Move the buffer forward. |   37     current_buffer += bytes_read;  // Move the buffer forward. | 
|   38   } |   38   } | 
|   39   return true; |   39   return true; | 
|   40 } |   40 } | 
|   41  |   41  | 
|   42  |   42  | 
|   43 void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) { |   43 void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) { | 
 |   44   // These values have to be kept in sync with the mode values of | 
 |   45   // FileMode.READ, FileMode.WRITE and FileMode.APPEND in file.dart. | 
 |   46   static const int kRead = 0; | 
 |   47   static const int kWrite = 1; | 
 |   48   static const int kAppend = 2; | 
 |   49  | 
|   44   Dart_EnterScope(); |   50   Dart_EnterScope(); | 
|   45   const char* filename = |   51   const char* filename = | 
|   46       DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |   52       DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 
|   47   bool writable = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 1)); |   53   int mode = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 
|   48   File* file = File::Open(filename, writable); |   54   ASSERT(mode == kRead || mode == kWrite || mode == kAppend); | 
 |   55   File::FileOpenMode file_mode = File::kRead; | 
 |   56   if (mode == kWrite) { | 
 |   57     file_mode = File::kWriteTruncate; | 
 |   58   } | 
 |   59   if (mode == kAppend) { | 
 |   60     file_mode = File::kWrite; | 
 |   61   } | 
 |   62   File* file = File::Open(filename, file_mode); | 
|   49   Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file))); |   63   Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file))); | 
|   50   Dart_ExitScope(); |   64   Dart_ExitScope(); | 
|   51 } |   65 } | 
|   52  |   66  | 
|   53  |   67  | 
|   54 void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) { |   68 void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) { | 
|   55   Dart_EnterScope(); |   69   Dart_EnterScope(); | 
|   56   const char* filename = |   70   const char* filename = | 
|   57       DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |   71       DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 
|   58   bool exists = File::Exists(filename); |   72   bool exists = File::Exists(filename); | 
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  303   Dart_EnterScope(); |  317   Dart_EnterScope(); | 
|  304   const char* str = |  318   const char* str = | 
|  305       DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |  319       DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 
|  306   char* path = File::GetCanonicalPath(str); |  320   char* path = File::GetCanonicalPath(str); | 
|  307   if (path != NULL) { |  321   if (path != NULL) { | 
|  308     Dart_SetReturnValue(args, Dart_NewString(path)); |  322     Dart_SetReturnValue(args, Dart_NewString(path)); | 
|  309     free(path); |  323     free(path); | 
|  310   } |  324   } | 
|  311   Dart_ExitScope(); |  325   Dart_ExitScope(); | 
|  312 } |  326 } | 
| OLD | NEW |