| OLD | NEW |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // reading. This is to prevent the opening of directories as | 72 // reading. This is to prevent the opening of directories as |
| 73 // files. Directories can be opened for reading using the posix | 73 // files. Directories can be opened for reading using the posix |
| 74 // 'open' call. | 74 // 'open' call. |
| 75 File* file = NULL; | 75 File* file = NULL; |
| 76 file = File::Open(filename, file_mode); | 76 file = File::Open(filename, file_mode); |
| 77 if (file != NULL) { | 77 if (file != NULL) { |
| 78 Dart_SetReturnValue(args, | 78 Dart_SetReturnValue(args, |
| 79 Dart_NewInteger(reinterpret_cast<intptr_t>(file))); | 79 Dart_NewInteger(reinterpret_cast<intptr_t>(file))); |
| 80 } else { | 80 } else { |
| 81 Dart_Handle err = DartUtils::NewDartOSError(); | 81 Dart_Handle err = DartUtils::NewDartOSError(); |
| 82 if (Dart_IsError(err)) { | 82 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 83 Dart_PropagateError(err); | |
| 84 } | |
| 85 Dart_SetReturnValue(args, err); | 83 Dart_SetReturnValue(args, err); |
| 86 } | 84 } |
| 87 Dart_ExitScope(); | 85 Dart_ExitScope(); |
| 88 } | 86 } |
| 89 | 87 |
| 90 | 88 |
| 91 void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) { | 89 void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) { |
| 92 Dart_EnterScope(); | 90 Dart_EnterScope(); |
| 93 const char* filename = | 91 const char* filename = |
| 94 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 92 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 95 bool exists = File::Exists(filename); | 93 bool exists = File::Exists(filename); |
| 96 Dart_SetReturnValue(args, Dart_NewBoolean(exists)); | 94 Dart_SetReturnValue(args, Dart_NewBoolean(exists)); |
| 97 Dart_ExitScope(); | 95 Dart_ExitScope(); |
| 98 } | 96 } |
| 99 | 97 |
| 100 | 98 |
| 101 void FUNCTION_NAME(File_Close)(Dart_NativeArguments args) { | 99 void FUNCTION_NAME(File_Close)(Dart_NativeArguments args) { |
| 102 Dart_EnterScope(); | 100 Dart_EnterScope(); |
| 103 intptr_t return_value = -1; | |
| 104 intptr_t value = | 101 intptr_t value = |
| 105 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 102 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 106 File* file = reinterpret_cast<File*>(value); | 103 File* file = reinterpret_cast<File*>(value); |
| 107 if (file != NULL) { | 104 ASSERT(file != NULL); |
| 108 delete file; | 105 delete file; |
| 109 return_value = 0; | 106 Dart_SetReturnValue(args, Dart_NewInteger(0)); |
| 110 } | |
| 111 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | |
| 112 Dart_ExitScope(); | 107 Dart_ExitScope(); |
| 113 } | 108 } |
| 114 | 109 |
| 115 | 110 |
| 116 void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) { | 111 void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) { |
| 117 Dart_EnterScope(); | 112 Dart_EnterScope(); |
| 118 intptr_t value = | 113 intptr_t value = |
| 119 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 114 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 120 File* file = reinterpret_cast<File*>(value); | 115 File* file = reinterpret_cast<File*>(value); |
| 121 if (file != NULL) { | 116 ASSERT(file != NULL); |
| 122 uint8_t buffer; | 117 uint8_t buffer; |
| 123 int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); | 118 int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); |
| 124 if (bytes_read == 1) { | 119 if (bytes_read == 1) { |
| 125 Dart_SetReturnValue(args, Dart_NewInteger(buffer)); | 120 Dart_SetReturnValue(args, Dart_NewInteger(buffer)); |
| 126 } else if (bytes_read == 0) { | 121 } else if (bytes_read == 0) { |
| 127 Dart_SetReturnValue(args, Dart_NewInteger(-1)); | 122 Dart_SetReturnValue(args, Dart_NewInteger(-1)); |
| 128 } else { | 123 } else { |
| 129 Dart_Handle err = DartUtils::NewDartOSError(); | 124 Dart_Handle err = DartUtils::NewDartOSError(); |
| 130 if (Dart_IsError(err)) { | 125 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 131 Dart_PropagateError(err); | 126 Dart_SetReturnValue(args, err); |
| 132 } | |
| 133 Dart_SetReturnValue(args, err); | |
| 134 } | |
| 135 } | 127 } |
| 136 Dart_ExitScope(); | 128 Dart_ExitScope(); |
| 137 } | 129 } |
| 138 | 130 |
| 139 | 131 |
| 140 void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) { | 132 void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) { |
| 141 Dart_EnterScope(); | 133 Dart_EnterScope(); |
| 142 intptr_t value = | 134 intptr_t file_ptr = |
| 143 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 135 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 144 File* file = reinterpret_cast<File*>(value); | 136 File* file = reinterpret_cast<File*>(file_ptr); |
| 145 if (file != NULL) { | 137 ASSERT(file != NULL); |
| 146 int64_t value = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 138 int64_t value = 0; |
| 139 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &value)) { |
| 147 uint8_t buffer = static_cast<uint8_t>(value & 0xff); | 140 uint8_t buffer = static_cast<uint8_t>(value & 0xff); |
| 148 int bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); | 141 int bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); |
| 149 if (bytes_written >= 0) { | 142 if (bytes_written >= 0) { |
| 150 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | 143 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| 151 } else { | 144 } else { |
| 152 Dart_Handle err = DartUtils::NewDartOSError(); | 145 Dart_Handle err = DartUtils::NewDartOSError(); |
| 153 if (Dart_IsError(err)) { | 146 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 154 Dart_PropagateError(err); | |
| 155 } | |
| 156 Dart_SetReturnValue(args, err); | 147 Dart_SetReturnValue(args, err); |
| 157 } | 148 } |
| 149 } else { |
| 150 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| 151 Dart_Handle err = DartUtils::NewDartOSError(&os_error); |
| 152 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 153 Dart_SetReturnValue(args, err); |
| 158 } | 154 } |
| 159 Dart_ExitScope(); | 155 Dart_ExitScope(); |
| 160 } | 156 } |
| 161 | 157 |
| 162 | 158 |
| 163 void FUNCTION_NAME(File_WriteString)(Dart_NativeArguments args) { | 159 void FUNCTION_NAME(File_WriteString)(Dart_NativeArguments args) { |
| 164 Dart_EnterScope(); | 160 Dart_EnterScope(); |
| 165 intptr_t value = | 161 intptr_t value = |
| 166 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 162 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 167 File* file = reinterpret_cast<File*>(value); | 163 File* file = reinterpret_cast<File*>(value); |
| 168 if (file != NULL) { | 164 ASSERT(file != NULL); |
| 169 const char* str = | 165 const char* str = |
| 170 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); | 166 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); |
| 171 int bytes_written = file->Write(reinterpret_cast<const void*>(str), | 167 int bytes_written = file->Write(reinterpret_cast<const void*>(str), |
| 172 strlen(str)); | 168 strlen(str)); |
| 173 if (bytes_written >= 0) { | 169 if (bytes_written >= 0) { |
| 174 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | 170 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| 175 } else { | 171 } else { |
| 176 Dart_Handle err = DartUtils::NewDartOSError(); | 172 Dart_Handle err = DartUtils::NewDartOSError(); |
| 177 if (Dart_IsError(err)) { | 173 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 178 Dart_PropagateError(err); | 174 Dart_SetReturnValue(args, err); |
| 179 } | |
| 180 Dart_SetReturnValue(args, err); | |
| 181 } | |
| 182 } | 175 } |
| 183 Dart_ExitScope(); | 176 Dart_ExitScope(); |
| 184 } | 177 } |
| 185 | 178 |
| 186 | 179 |
| 187 void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) { | 180 void FUNCTION_NAME(File_ReadList)(Dart_NativeArguments args) { |
| 188 Dart_EnterScope(); | 181 Dart_EnterScope(); |
| 189 intptr_t value = | 182 intptr_t value = |
| 190 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 183 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 191 File* file = reinterpret_cast<File*>(value); | 184 File* file = reinterpret_cast<File*>(value); |
| 192 if (file != NULL) { | 185 ASSERT(file != NULL); |
| 193 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 186 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 194 ASSERT(Dart_IsList(buffer_obj)); | 187 ASSERT(Dart_IsList(buffer_obj)); |
| 195 int64_t offset = | 188 int64_t offset = |
| 196 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 189 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 197 int64_t length = | 190 int64_t length = |
| 198 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 191 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 199 intptr_t array_len = 0; | 192 intptr_t array_len = 0; |
| 200 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); | 193 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); |
| 194 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 195 ASSERT((offset + length) <= array_len); |
| 196 uint8_t* buffer = new uint8_t[length]; |
| 197 int bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); |
| 198 if (bytes_read >= 0) { |
| 199 result = Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); |
| 201 if (Dart_IsError(result)) { | 200 if (Dart_IsError(result)) { |
| 201 delete[] buffer; |
| 202 Dart_PropagateError(result); | 202 Dart_PropagateError(result); |
| 203 } | 203 } |
| 204 ASSERT((offset + length) <= array_len); | 204 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); |
| 205 uint8_t* buffer = new uint8_t[length]; | 205 } else { |
| 206 int bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); | 206 Dart_Handle err = DartUtils::NewDartOSError(); |
| 207 if (bytes_read >= 0) { | 207 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 208 result = | 208 Dart_SetReturnValue(args, err); |
| 209 Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); | |
| 210 if (Dart_IsError(result)) { | |
| 211 delete[] buffer; | |
| 212 Dart_PropagateError(result); | |
| 213 } | |
| 214 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); | |
| 215 } else { | |
| 216 Dart_Handle err = DartUtils::NewDartOSError(); | |
| 217 if (Dart_IsError(err)) { | |
| 218 Dart_PropagateError(err); | |
| 219 } | |
| 220 Dart_SetReturnValue(args, err); | |
| 221 } | |
| 222 delete[] buffer; | |
| 223 } | 209 } |
| 210 delete[] buffer; |
| 224 Dart_ExitScope(); | 211 Dart_ExitScope(); |
| 225 } | 212 } |
| 226 | 213 |
| 227 | 214 |
| 228 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { | 215 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { |
| 229 Dart_EnterScope(); | 216 Dart_EnterScope(); |
| 230 intptr_t value = | 217 intptr_t value = |
| 231 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 218 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 232 File* file = reinterpret_cast<File*>(value); | 219 File* file = reinterpret_cast<File*>(value); |
| 233 if (file != NULL) { | 220 ASSERT(file != NULL); |
| 234 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 221 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 235 ASSERT(Dart_IsList(buffer_obj)); | 222 ASSERT(Dart_IsList(buffer_obj)); |
| 236 int64_t offset = | 223 int64_t offset = |
| 237 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 224 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 238 int64_t length = | 225 int64_t length = |
| 239 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 226 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 240 intptr_t buffer_len = 0; | 227 intptr_t buffer_len = 0; |
| 241 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); | 228 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| 242 if (Dart_IsError(result)) { | 229 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 243 Dart_PropagateError(result); | 230 ASSERT((offset + length) <= buffer_len); |
| 244 } | 231 uint8_t* buffer = new uint8_t[length]; |
| 245 ASSERT((offset + length) <= buffer_len); | 232 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); |
| 246 uint8_t* buffer = new uint8_t[length]; | 233 if (Dart_IsError(result)) { |
| 247 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); | |
| 248 if (Dart_IsError(result)) { | |
| 249 delete[] buffer; | |
| 250 Dart_PropagateError(result); | |
| 251 } | |
| 252 int bytes_written = file->Write(reinterpret_cast<void*>(buffer), length); | |
| 253 if (bytes_written >= 0) { | |
| 254 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | |
| 255 } else { | |
| 256 Dart_Handle err = DartUtils::NewDartOSError(); | |
| 257 if (Dart_IsError(err)) { | |
| 258 Dart_PropagateError(err); | |
| 259 } | |
| 260 Dart_SetReturnValue(args, err); | |
| 261 } | |
| 262 delete[] buffer; | 234 delete[] buffer; |
| 235 Dart_PropagateError(result); |
| 263 } | 236 } |
| 237 int bytes_written = file->Write(reinterpret_cast<void*>(buffer), length); |
| 238 if (bytes_written >= 0) { |
| 239 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| 240 } else { |
| 241 Dart_Handle err = DartUtils::NewDartOSError(); |
| 242 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 243 Dart_SetReturnValue(args, err); |
| 244 } |
| 245 delete[] buffer; |
| 264 Dart_ExitScope(); | 246 Dart_ExitScope(); |
| 265 } | 247 } |
| 266 | 248 |
| 267 | 249 |
| 268 void FUNCTION_NAME(File_Position)(Dart_NativeArguments args) { | 250 void FUNCTION_NAME(File_Position)(Dart_NativeArguments args) { |
| 269 Dart_EnterScope(); | 251 Dart_EnterScope(); |
| 270 intptr_t value = | 252 intptr_t value = |
| 271 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 253 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 272 File* file = reinterpret_cast<File*>(value); | 254 File* file = reinterpret_cast<File*>(value); |
| 273 if (file != NULL) { | 255 ASSERT(file != NULL); |
| 274 intptr_t return_value = file->Position(); | 256 intptr_t return_value = file->Position(); |
| 275 if (return_value >= 0) { | 257 if (return_value >= 0) { |
| 276 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 258 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 277 } else { | 259 } else { |
| 278 Dart_Handle err = DartUtils::NewDartOSError(); | 260 Dart_Handle err = DartUtils::NewDartOSError(); |
| 279 if (Dart_IsError(err)) { | 261 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 280 Dart_PropagateError(err); | 262 Dart_SetReturnValue(args, err); |
| 281 } | |
| 282 Dart_SetReturnValue(args, err); | |
| 283 } | |
| 284 } | 263 } |
| 285 Dart_ExitScope(); | 264 Dart_ExitScope(); |
| 286 } | 265 } |
| 287 | 266 |
| 288 | 267 |
| 289 void FUNCTION_NAME(File_SetPosition)(Dart_NativeArguments args) { | 268 void FUNCTION_NAME(File_SetPosition)(Dart_NativeArguments args) { |
| 290 Dart_EnterScope(); | 269 Dart_EnterScope(); |
| 291 intptr_t value = | 270 intptr_t value = |
| 292 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 271 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 293 File* file = reinterpret_cast<File*>(value); | 272 File* file = reinterpret_cast<File*>(value); |
| 294 if (file != NULL) { | 273 ASSERT(file != NULL); |
| 295 int64_t position = | 274 int64_t position = 0; |
| 296 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 275 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &position)) { |
| 297 if (file->SetPosition(position)) { | 276 if (file->SetPosition(position)) { |
| 298 Dart_SetReturnValue(args, Dart_True()); | 277 Dart_SetReturnValue(args, Dart_True()); |
| 299 } else { | 278 } else { |
| 300 Dart_Handle err = DartUtils::NewDartOSError(); | 279 Dart_Handle err = DartUtils::NewDartOSError(); |
| 301 if (Dart_IsError(err)) { | 280 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 302 Dart_PropagateError(err); | |
| 303 } | |
| 304 Dart_SetReturnValue(args, err); | 281 Dart_SetReturnValue(args, err); |
| 305 } | 282 } |
| 283 } else { |
| 284 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| 285 Dart_Handle err = DartUtils::NewDartOSError(&os_error); |
| 286 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 287 Dart_SetReturnValue(args, err); |
| 306 } | 288 } |
| 307 Dart_ExitScope(); | 289 Dart_ExitScope(); |
| 308 } | 290 } |
| 309 | 291 |
| 310 | 292 |
| 311 void FUNCTION_NAME(File_Truncate)(Dart_NativeArguments args) { | 293 void FUNCTION_NAME(File_Truncate)(Dart_NativeArguments args) { |
| 312 Dart_EnterScope(); | 294 Dart_EnterScope(); |
| 313 intptr_t value = | 295 intptr_t value = |
| 314 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 296 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 315 File* file = reinterpret_cast<File*>(value); | 297 File* file = reinterpret_cast<File*>(value); |
| 316 if (file != NULL) { | 298 ASSERT(file != NULL); |
| 317 int64_t length = | 299 int64_t length = |
| 318 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 300 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| 319 if (file->Truncate(length)) { | 301 if (file->Truncate(length)) { |
| 320 Dart_SetReturnValue(args, Dart_True()); | 302 Dart_SetReturnValue(args, Dart_True()); |
| 321 } else { | 303 } else { |
| 322 Dart_Handle err = DartUtils::NewDartOSError(); | 304 Dart_Handle err = DartUtils::NewDartOSError(); |
| 323 if (Dart_IsError(err)) { | 305 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 324 Dart_PropagateError(err); | 306 Dart_SetReturnValue(args, err); |
| 325 } | |
| 326 Dart_SetReturnValue(args, err); | |
| 327 } | |
| 328 } | 307 } |
| 329 Dart_ExitScope(); | 308 Dart_ExitScope(); |
| 330 } | 309 } |
| 331 | 310 |
| 332 | 311 |
| 333 void FUNCTION_NAME(File_Length)(Dart_NativeArguments args) { | 312 void FUNCTION_NAME(File_Length)(Dart_NativeArguments args) { |
| 334 Dart_EnterScope(); | 313 Dart_EnterScope(); |
| 335 intptr_t value = | 314 intptr_t value = |
| 336 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 315 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 337 File* file = reinterpret_cast<File*>(value); | 316 File* file = reinterpret_cast<File*>(value); |
| 338 if (file != NULL) { | 317 ASSERT(file != NULL); |
| 339 intptr_t return_value = file->Length(); | 318 intptr_t return_value = file->Length(); |
| 340 if (return_value >= 0) { | 319 if (return_value >= 0) { |
| 341 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 320 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 342 } else { | 321 } else { |
| 343 Dart_Handle err = DartUtils::NewDartOSError(); | 322 Dart_Handle err = DartUtils::NewDartOSError(); |
| 344 if (Dart_IsError(err)) { | 323 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 345 Dart_PropagateError(err); | 324 Dart_SetReturnValue(args, err); |
| 346 } | |
| 347 Dart_SetReturnValue(args, err); | |
| 348 } | |
| 349 } | 325 } |
| 350 Dart_ExitScope(); | 326 Dart_ExitScope(); |
| 351 } | 327 } |
| 352 | 328 |
| 353 | 329 |
| 354 void FUNCTION_NAME(File_LengthFromName)(Dart_NativeArguments args) { | 330 void FUNCTION_NAME(File_LengthFromName)(Dart_NativeArguments args) { |
| 355 Dart_EnterScope(); | 331 Dart_EnterScope(); |
| 356 const char* name = | 332 const char* name = |
| 357 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 333 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 358 intptr_t return_value = File::LengthFromName(name); | 334 intptr_t return_value = File::LengthFromName(name); |
| 359 if (return_value >= 0) { | 335 if (return_value >= 0) { |
| 360 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 336 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 361 } else { | 337 } else { |
| 362 Dart_Handle err = DartUtils::NewDartOSError(); | 338 Dart_Handle err = DartUtils::NewDartOSError(); |
| 363 if (Dart_IsError(err)) { | 339 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 364 Dart_PropagateError(err); | |
| 365 } | |
| 366 Dart_SetReturnValue(args, err); | 340 Dart_SetReturnValue(args, err); |
| 367 } | 341 } |
| 368 Dart_ExitScope(); | 342 Dart_ExitScope(); |
| 369 } | 343 } |
| 370 | 344 |
| 371 | 345 |
| 372 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { | 346 void FUNCTION_NAME(File_Flush)(Dart_NativeArguments args) { |
| 373 Dart_EnterScope(); | 347 Dart_EnterScope(); |
| 374 intptr_t value = | 348 intptr_t value = |
| 375 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 349 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 376 File* file = reinterpret_cast<File*>(value); | 350 File* file = reinterpret_cast<File*>(value); |
| 377 if (file != NULL) { | 351 ASSERT(file != NULL); |
| 378 if (file->Flush()) { | 352 if (file->Flush()) { |
| 379 Dart_SetReturnValue(args, Dart_True()); | 353 Dart_SetReturnValue(args, Dart_True()); |
| 380 } else { | 354 } else { |
| 381 Dart_Handle err = DartUtils::NewDartOSError(); | 355 Dart_Handle err = DartUtils::NewDartOSError(); |
| 382 if (Dart_IsError(err)) { | 356 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 383 Dart_PropagateError(err); | 357 Dart_SetReturnValue(args, err); |
| 384 } | |
| 385 Dart_SetReturnValue(args, err); | |
| 386 } | |
| 387 } | 358 } |
| 388 Dart_ExitScope(); | 359 Dart_ExitScope(); |
| 389 } | 360 } |
| 390 | 361 |
| 391 | 362 |
| 392 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { | 363 void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) { |
| 393 Dart_EnterScope(); | 364 Dart_EnterScope(); |
| 394 const char* str = | 365 const char* str = |
| 395 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 366 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 396 bool result = File::Create(str); | 367 bool result = File::Create(str); |
| 397 if (result) { | 368 if (result) { |
| 398 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 369 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| 399 } else { | 370 } else { |
| 400 Dart_Handle err = DartUtils::NewDartOSError(); | 371 Dart_Handle err = DartUtils::NewDartOSError(); |
| 401 if (Dart_IsError(err)) { | 372 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 402 Dart_PropagateError(err); | |
| 403 } | |
| 404 Dart_SetReturnValue(args, err); | 373 Dart_SetReturnValue(args, err); |
| 405 } | 374 } |
| 406 Dart_ExitScope(); | 375 Dart_ExitScope(); |
| 407 } | 376 } |
| 408 | 377 |
| 409 | 378 |
| 410 void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) { | 379 void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) { |
| 411 Dart_EnterScope(); | 380 Dart_EnterScope(); |
| 412 const char* str = | 381 const char* str = |
| 413 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 382 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 414 bool result = File::Delete(str); | 383 bool result = File::Delete(str); |
| 415 if (result) { | 384 if (result) { |
| 416 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 385 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| 417 } else { | 386 } else { |
| 418 Dart_Handle err = DartUtils::NewDartOSError(); | 387 Dart_Handle err = DartUtils::NewDartOSError(); |
| 419 if (Dart_IsError(err)) { | 388 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 420 Dart_PropagateError(err); | |
| 421 } | |
| 422 Dart_SetReturnValue(args, err); | 389 Dart_SetReturnValue(args, err); |
| 423 } | 390 } |
| 424 Dart_ExitScope(); | 391 Dart_ExitScope(); |
| 425 } | 392 } |
| 426 | 393 |
| 427 | 394 |
| 428 void FUNCTION_NAME(File_Directory)(Dart_NativeArguments args) { | 395 void FUNCTION_NAME(File_Directory)(Dart_NativeArguments args) { |
| 429 Dart_EnterScope(); | 396 Dart_EnterScope(); |
| 430 const char* str = | 397 const char* str = |
| 431 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 398 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 432 char* str_copy = strdup(str); | 399 char* str_copy = strdup(str); |
| 433 char* path = File::GetContainingDirectory(str_copy); | 400 char* path = File::GetContainingDirectory(str_copy); |
| 434 free(str_copy); | 401 free(str_copy); |
| 435 if (path != NULL) { | 402 if (path != NULL) { |
| 436 Dart_SetReturnValue(args, Dart_NewString(path)); | 403 Dart_SetReturnValue(args, Dart_NewString(path)); |
| 437 free(path); | 404 free(path); |
| 438 } else { | 405 } else { |
| 439 Dart_Handle err = DartUtils::NewDartOSError(); | 406 Dart_Handle err = DartUtils::NewDartOSError(); |
| 440 if (Dart_IsError(err)) { | 407 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 441 Dart_PropagateError(err); | |
| 442 } | |
| 443 Dart_SetReturnValue(args, err); | 408 Dart_SetReturnValue(args, err); |
| 444 } | 409 } |
| 445 Dart_ExitScope(); | 410 Dart_ExitScope(); |
| 446 } | 411 } |
| 447 | 412 |
| 448 | 413 |
| 449 void FUNCTION_NAME(File_FullPath)(Dart_NativeArguments args) { | 414 void FUNCTION_NAME(File_FullPath)(Dart_NativeArguments args) { |
| 450 Dart_EnterScope(); | 415 Dart_EnterScope(); |
| 451 const char* str = | 416 const char* str = |
| 452 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 417 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 453 char* path = File::GetCanonicalPath(str); | 418 char* path = File::GetCanonicalPath(str); |
| 454 if (path != NULL) { | 419 if (path != NULL) { |
| 455 Dart_SetReturnValue(args, Dart_NewString(path)); | 420 Dart_SetReturnValue(args, Dart_NewString(path)); |
| 456 free(path); | 421 free(path); |
| 457 } else { | 422 } else { |
| 458 Dart_Handle err = DartUtils::NewDartOSError(); | 423 Dart_Handle err = DartUtils::NewDartOSError(); |
| 459 if (Dart_IsError(err)) { | 424 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 460 Dart_PropagateError(err); | |
| 461 } | |
| 462 Dart_SetReturnValue(args, err); | 425 Dart_SetReturnValue(args, err); |
| 463 } | 426 } |
| 464 Dart_ExitScope(); | 427 Dart_ExitScope(); |
| 465 } | 428 } |
| 466 | 429 |
| 467 | 430 |
| 468 void FUNCTION_NAME(File_OpenStdio)(Dart_NativeArguments args) { | 431 void FUNCTION_NAME(File_OpenStdio)(Dart_NativeArguments args) { |
| 469 Dart_EnterScope(); | 432 Dart_EnterScope(); |
| 470 int fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 433 int fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 471 File* file = File::OpenStdio(fd); | 434 File* file = File::OpenStdio(fd); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 } | 556 } |
| 594 } | 557 } |
| 595 return CObject::Null(); | 558 return CObject::Null(); |
| 596 } | 559 } |
| 597 | 560 |
| 598 | 561 |
| 599 static CObject* FileCloseRequest(const CObjectArray& request) { | 562 static CObject* FileCloseRequest(const CObjectArray& request) { |
| 600 intptr_t return_value = -1; | 563 intptr_t return_value = -1; |
| 601 if (request.Length() == 2 && request[1]->IsIntptr()) { | 564 if (request.Length() == 2 && request[1]->IsIntptr()) { |
| 602 File* file = CObjectToFilePointer(request[1]); | 565 File* file = CObjectToFilePointer(request[1]); |
| 603 if (file != NULL) { | 566 ASSERT(file != NULL); |
| 604 delete file; | 567 delete file; |
| 605 return_value = 0; | 568 return_value = 0; |
| 606 } | |
| 607 } | 569 } |
| 608 return new CObjectIntptr(CObject::NewIntptr(return_value)); | 570 return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| 609 } | 571 } |
| 610 | 572 |
| 611 | 573 |
| 612 static CObject* FilePositionRequest(const CObjectArray& request) { | 574 static CObject* FilePositionRequest(const CObjectArray& request) { |
| 613 if (request.Length() == 2 && request[1]->IsIntptr()) { | 575 if (request.Length() == 2 && request[1]->IsIntptr()) { |
| 614 File* file = CObjectToFilePointer(request[1]); | 576 File* file = CObjectToFilePointer(request[1]); |
| 615 if (file != NULL && !file->IsClosed()) { | 577 ASSERT(file != NULL); |
| 578 if (!file->IsClosed()) { |
| 616 intptr_t return_value = file->Position(); | 579 intptr_t return_value = file->Position(); |
| 617 if (return_value >= 0) { | 580 if (return_value >= 0) { |
| 618 return new CObjectIntptr(CObject::NewIntptr(return_value)); | 581 return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| 619 } else { | 582 } else { |
| 620 return CObject::NewOSError(); | 583 return CObject::NewOSError(); |
| 621 } | 584 } |
| 622 } else { | 585 } else { |
| 623 return CObject::FileClosedError(); | 586 return CObject::FileClosedError(); |
| 624 } | 587 } |
| 625 } | 588 } |
| 626 return CObject::IllegalArgumentError(); | 589 return CObject::IllegalArgumentError(); |
| 627 } | 590 } |
| 628 | 591 |
| 629 | 592 |
| 630 static CObject* FileSetPositionRequest(const CObjectArray& request) { | 593 static CObject* FileSetPositionRequest(const CObjectArray& request) { |
| 631 if (request.Length() == 3 && | 594 if (request.Length() == 3 && |
| 632 request[1]->IsIntptr() && | 595 request[1]->IsIntptr() && |
| 633 request[2]->IsInt32OrInt64()) { | 596 request[2]->IsInt32OrInt64()) { |
| 634 File* file = CObjectToFilePointer(request[1]); | 597 File* file = CObjectToFilePointer(request[1]); |
| 635 if (file != NULL && !file->IsClosed()) { | 598 ASSERT(file != NULL); |
| 599 if (!file->IsClosed()) { |
| 636 int64_t position = CObjectInt32OrInt64ToInt64(request[2]); | 600 int64_t position = CObjectInt32OrInt64ToInt64(request[2]); |
| 637 if (file->SetPosition(position)) { | 601 if (file->SetPosition(position)) { |
| 638 return CObject::True(); | 602 return CObject::True(); |
| 639 } else { | 603 } else { |
| 640 return CObject::NewOSError(); | 604 return CObject::NewOSError(); |
| 641 } | 605 } |
| 642 } else { | 606 } else { |
| 643 return CObject::FileClosedError(); | 607 return CObject::FileClosedError(); |
| 644 } | 608 } |
| 645 } | 609 } |
| 646 return CObject::IllegalArgumentError(); | 610 return CObject::IllegalArgumentError(); |
| 647 } | 611 } |
| 648 | 612 |
| 649 | 613 |
| 650 static CObject* FileTruncateRequest(const CObjectArray& request) { | 614 static CObject* FileTruncateRequest(const CObjectArray& request) { |
| 651 if (request.Length() == 3 && | 615 if (request.Length() == 3 && |
| 652 request[1]->IsIntptr() && | 616 request[1]->IsIntptr() && |
| 653 request[2]->IsInt32OrInt64()) { | 617 request[2]->IsInt32OrInt64()) { |
| 654 File* file = CObjectToFilePointer(request[1]); | 618 File* file = CObjectToFilePointer(request[1]); |
| 655 if (file != NULL && !file->IsClosed()) { | 619 ASSERT(file != NULL); |
| 620 if (!file->IsClosed()) { |
| 656 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); | 621 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); |
| 657 if (file->Truncate(length)) { | 622 if (file->Truncate(length)) { |
| 658 return CObject::True(); | 623 return CObject::True(); |
| 659 } else { | 624 } else { |
| 660 return CObject::NewOSError(); | 625 return CObject::NewOSError(); |
| 661 } | 626 } |
| 662 } else { | 627 } else { |
| 663 return CObject::FileClosedError(); | 628 return CObject::FileClosedError(); |
| 664 } | 629 } |
| 665 } | 630 } |
| 666 return CObject::IllegalArgumentError(); | 631 return CObject::IllegalArgumentError(); |
| 667 } | 632 } |
| 668 | 633 |
| 669 | 634 |
| 670 static CObject* FileLengthRequest(const CObjectArray& request) { | 635 static CObject* FileLengthRequest(const CObjectArray& request) { |
| 671 if (request.Length() == 2 && request[1]->IsIntptr()) { | 636 if (request.Length() == 2 && request[1]->IsIntptr()) { |
| 672 File* file = CObjectToFilePointer(request[1]); | 637 File* file = CObjectToFilePointer(request[1]); |
| 673 if (file != NULL && !file->IsClosed()) { | 638 ASSERT(file != NULL); |
| 639 if (!file->IsClosed()) { |
| 674 intptr_t return_value = file->Length(); | 640 intptr_t return_value = file->Length(); |
| 675 if (return_value >= 0) { | 641 if (return_value >= 0) { |
| 676 return new CObjectIntptr(CObject::NewIntptr(return_value)); | 642 return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| 677 } else { | 643 } else { |
| 678 return CObject::NewOSError(); | 644 return CObject::NewOSError(); |
| 679 } | 645 } |
| 680 } else { | 646 } else { |
| 681 return CObject::FileClosedError(); | 647 return CObject::FileClosedError(); |
| 682 } | 648 } |
| 683 } | 649 } |
| 684 return CObject::IllegalArgumentError(); | 650 return CObject::IllegalArgumentError(); |
| 685 } | 651 } |
| 686 | 652 |
| 687 | 653 |
| 688 static CObject* FileLengthFromNameRequest(const CObjectArray& request) { | 654 static CObject* FileLengthFromNameRequest(const CObjectArray& request) { |
| 689 if (request.Length() == 2 && request[1]->IsString()) { | 655 if (request.Length() == 2 && request[1]->IsString()) { |
| 690 CObjectString filename(request[1]); | 656 CObjectString filename(request[1]); |
| 691 intptr_t return_value = File::LengthFromName(filename.CString()); | 657 intptr_t return_value = File::LengthFromName(filename.CString()); |
| 692 if (return_value >= 0) { | 658 if (return_value >= 0) { |
| 693 return new CObjectIntptr(CObject::NewIntptr(return_value)); | 659 return new CObjectIntptr(CObject::NewIntptr(return_value)); |
| 694 } else { | 660 } else { |
| 695 return CObject::NewOSError(); | 661 return CObject::NewOSError(); |
| 696 } | 662 } |
| 697 } | 663 } |
| 698 return CObject::IllegalArgumentError(); | 664 return CObject::IllegalArgumentError(); |
| 699 } | 665 } |
| 700 | 666 |
| 701 | 667 |
| 702 static CObject* FileFlushRequest(const CObjectArray& request) { | 668 static CObject* FileFlushRequest(const CObjectArray& request) { |
| 703 intptr_t return_value = -1; | |
| 704 if (request.Length() == 2 && request[1]->IsIntptr()) { | 669 if (request.Length() == 2 && request[1]->IsIntptr()) { |
| 705 File* file = CObjectToFilePointer(request[1]); | 670 File* file = CObjectToFilePointer(request[1]); |
| 706 if (file != NULL && !file->IsClosed()) { | 671 ASSERT(file != NULL); |
| 672 if (!file->IsClosed()) { |
| 707 if (file->Flush()) { | 673 if (file->Flush()) { |
| 708 return CObject::True(); | 674 return CObject::True(); |
| 709 } else { | 675 } else { |
| 710 return CObject::NewOSError(); | 676 return CObject::NewOSError(); |
| 711 } | 677 } |
| 712 } else { | 678 } else { |
| 713 return CObject::FileClosedError(); | 679 return CObject::FileClosedError(); |
| 714 } | 680 } |
| 715 } | 681 } |
| 716 return CObject::IllegalArgumentError(); | 682 return CObject::IllegalArgumentError(); |
| 717 return new CObjectIntptr(CObject::NewIntptr(return_value)); | |
| 718 } | 683 } |
| 719 | 684 |
| 720 | 685 |
| 721 static CObject* FileReadByteRequest(const CObjectArray& request) { | 686 static CObject* FileReadByteRequest(const CObjectArray& request) { |
| 722 if (request.Length() == 2 && request[1]->IsIntptr()) { | 687 if (request.Length() == 2 && request[1]->IsIntptr()) { |
| 723 File* file = CObjectToFilePointer(request[1]); | 688 File* file = CObjectToFilePointer(request[1]); |
| 724 if (file != NULL && !file->IsClosed()) { | 689 ASSERT(file != NULL); |
| 690 if (!file->IsClosed()) { |
| 725 uint8_t buffer; | 691 uint8_t buffer; |
| 726 int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); | 692 int bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); |
| 727 if (bytes_read > 0) { | 693 if (bytes_read > 0) { |
| 728 return new CObjectIntptr(CObject::NewIntptr(buffer)); | 694 return new CObjectIntptr(CObject::NewIntptr(buffer)); |
| 729 } else if (bytes_read == 0) { | 695 } else if (bytes_read == 0) { |
| 730 return new CObjectIntptr(CObject::NewIntptr(-1)); | 696 return new CObjectIntptr(CObject::NewIntptr(-1)); |
| 731 } else { | 697 } else { |
| 732 return CObject::NewOSError(); | 698 return CObject::NewOSError(); |
| 733 } | 699 } |
| 734 } else { | 700 } else { |
| 735 return CObject::FileClosedError(); | 701 return CObject::FileClosedError(); |
| 736 } | 702 } |
| 737 } | 703 } |
| 738 return CObject::IllegalArgumentError(); | 704 return CObject::IllegalArgumentError(); |
| 739 } | 705 } |
| 740 | 706 |
| 741 | 707 |
| 742 static CObject* FileWriteByteRequest(const CObjectArray& request) { | 708 static CObject* FileWriteByteRequest(const CObjectArray& request) { |
| 743 if (request.Length() == 3 && | 709 if (request.Length() == 3 && |
| 744 request[1]->IsIntptr() && | 710 request[1]->IsIntptr() && |
| 745 request[2]->IsInt32OrInt64()) { | 711 request[2]->IsInt32OrInt64()) { |
| 746 File* file = CObjectToFilePointer(request[1]); | 712 File* file = CObjectToFilePointer(request[1]); |
| 747 if (file != NULL && !file->IsClosed()) { | 713 ASSERT(file != NULL); |
| 714 if (!file->IsClosed()) { |
| 748 int64_t byte = CObjectInt32OrInt64ToInt64(request[2]); | 715 int64_t byte = CObjectInt32OrInt64ToInt64(request[2]); |
| 749 uint8_t buffer = static_cast<uint8_t>(byte & 0xff); | 716 uint8_t buffer = static_cast<uint8_t>(byte & 0xff); |
| 750 int bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); | 717 int bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); |
| 751 if (bytes_written > 0) { | 718 if (bytes_written > 0) { |
| 752 return new CObjectIntptr(CObject::NewIntptr(bytes_written)); | 719 return new CObjectIntptr(CObject::NewIntptr(bytes_written)); |
| 753 } else { | 720 } else { |
| 754 return CObject::NewOSError(); | 721 return CObject::NewOSError(); |
| 755 } | 722 } |
| 756 } else { | 723 } else { |
| 757 return CObject::FileClosedError(); | 724 return CObject::FileClosedError(); |
| 758 } | 725 } |
| 759 } | 726 } |
| 760 return CObject::IllegalArgumentError(); | 727 return CObject::IllegalArgumentError(); |
| 761 } | 728 } |
| 762 | 729 |
| 763 | 730 |
| 764 static CObject* FileReadListRequest(const CObjectArray& request) { | 731 static CObject* FileReadListRequest(const CObjectArray& request) { |
| 765 if (request.Length() == 3 && | 732 if (request.Length() == 3 && |
| 766 request[1]->IsIntptr() && | 733 request[1]->IsIntptr() && |
| 767 request[2]->IsInt32OrInt64()) { | 734 request[2]->IsInt32OrInt64()) { |
| 768 File* file = CObjectToFilePointer(request[1]); | 735 File* file = CObjectToFilePointer(request[1]); |
| 769 if (file != NULL && !file->IsClosed()) { | 736 ASSERT(file != NULL); |
| 737 if (!file->IsClosed()) { |
| 770 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); | 738 int64_t length = CObjectInt32OrInt64ToInt64(request[2]); |
| 771 CObjectUint8Array* byte_array = | 739 CObjectUint8Array* byte_array = |
| 772 new CObjectUint8Array(CObject::NewUint8Array(length)); | 740 new CObjectUint8Array(CObject::NewUint8Array(length)); |
| 773 void* buffer = reinterpret_cast<void*>(byte_array->Buffer()); | 741 void* buffer = reinterpret_cast<void*>(byte_array->Buffer()); |
| 774 int bytes_read = file->Read(buffer, byte_array->Length()); | 742 int bytes_read = file->Read(buffer, byte_array->Length()); |
| 775 if (bytes_read >= 0) { | 743 if (bytes_read >= 0) { |
| 776 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 744 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 777 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); | 745 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); |
| 778 result->SetAt(1, new CObjectIntptr(CObject::NewIntptr(bytes_read))); | 746 result->SetAt(1, new CObjectIntptr(CObject::NewIntptr(bytes_read))); |
| 779 result->SetAt(2, byte_array); | 747 result->SetAt(2, byte_array); |
| 780 return result; | 748 return result; |
| 781 } else { | 749 } else { |
| 782 return CObject::NewOSError(); | 750 return CObject::NewOSError(); |
| 783 } | 751 } |
| 784 } else { | 752 } else { |
| 785 return CObject::FileClosedError(); | 753 return CObject::FileClosedError(); |
| 786 } | 754 } |
| 787 } | 755 } |
| 788 return CObject::IllegalArgumentError(); | 756 return CObject::IllegalArgumentError(); |
| 789 } | 757 } |
| 790 | 758 |
| 791 | 759 |
| 792 static CObject* FileWriteListRequest(const CObjectArray& request) { | 760 static CObject* FileWriteListRequest(const CObjectArray& request) { |
| 793 if (request.Length() == 5 && | 761 if (request.Length() == 5 && |
| 794 request[1]->IsIntptr() && | 762 request[1]->IsIntptr() && |
| 795 (request[2]->IsUint8Array() || request[2]->IsArray()) && | 763 (request[2]->IsUint8Array() || request[2]->IsArray()) && |
| 796 request[3]->IsInt32OrInt64() && | 764 request[3]->IsInt32OrInt64() && |
| 797 request[4]->IsInt32OrInt64()) { | 765 request[4]->IsInt32OrInt64()) { |
| 798 File* file = CObjectToFilePointer(request[1]); | 766 File* file = CObjectToFilePointer(request[1]); |
| 799 if (file != NULL && !file->IsClosed()) { | 767 ASSERT(file != NULL); |
| 768 if (!file->IsClosed()) { |
| 800 int64_t offset = CObjectInt32OrInt64ToInt64(request[3]); | 769 int64_t offset = CObjectInt32OrInt64ToInt64(request[3]); |
| 801 int64_t length = CObjectInt32OrInt64ToInt64(request[4]); | 770 int64_t length = CObjectInt32OrInt64ToInt64(request[4]); |
| 802 uint8_t* buffer_start; | 771 uint8_t* buffer_start; |
| 803 if (request[2]->IsUint8Array()) { | 772 if (request[2]->IsUint8Array()) { |
| 804 CObjectUint8Array byte_array(request[2]); | 773 CObjectUint8Array byte_array(request[2]); |
| 805 buffer_start = byte_array.Buffer() + offset; | 774 buffer_start = byte_array.Buffer() + offset; |
| 806 } else { | 775 } else { |
| 807 CObjectArray array(request[2]); | 776 CObjectArray array(request[2]); |
| 808 buffer_start = new uint8_t[length]; | 777 buffer_start = new uint8_t[length]; |
| 809 for (int i = 0; i < length; i++) { | 778 for (int i = 0; i < length; i++) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 834 } | 803 } |
| 835 return CObject::IllegalArgumentError(); | 804 return CObject::IllegalArgumentError(); |
| 836 } | 805 } |
| 837 | 806 |
| 838 | 807 |
| 839 static CObject* FileWriteStringRequest(const CObjectArray& request) { | 808 static CObject* FileWriteStringRequest(const CObjectArray& request) { |
| 840 if (request.Length() == 3 && | 809 if (request.Length() == 3 && |
| 841 request[1]->IsIntptr() && | 810 request[1]->IsIntptr() && |
| 842 request[2]->IsString()) { | 811 request[2]->IsString()) { |
| 843 File* file = CObjectToFilePointer(request[1]); | 812 File* file = CObjectToFilePointer(request[1]); |
| 844 if (file != NULL && !file->IsClosed()) { | 813 ASSERT(file != NULL); |
| 814 if (!file->IsClosed()) { |
| 845 CObjectString str(request[2]); | 815 CObjectString str(request[2]); |
| 846 const void* buffer = reinterpret_cast<const void*>(str.CString()); | 816 const void* buffer = reinterpret_cast<const void*>(str.CString()); |
| 847 int64_t bytes_written = file->Write(buffer, str.Length()); | 817 int64_t bytes_written = file->Write(buffer, str.Length()); |
| 848 return new CObjectInt64(CObject::NewInt64(bytes_written)); | 818 return new CObjectInt64(CObject::NewInt64(bytes_written)); |
| 849 } else { | 819 } else { |
| 850 return CObject::FileClosedError(); | 820 return CObject::FileClosedError(); |
| 851 } | 821 } |
| 852 } | 822 } |
| 853 return CObject::IllegalArgumentError(); | 823 return CObject::IllegalArgumentError(); |
| 854 } | 824 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 Dart_EnterScope(); | 926 Dart_EnterScope(); |
| 957 Dart_SetReturnValue(args, Dart_Null()); | 927 Dart_SetReturnValue(args, Dart_Null()); |
| 958 Dart_Port service_port = File::GetServicePort(); | 928 Dart_Port service_port = File::GetServicePort(); |
| 959 if (service_port != kIllegalPort) { | 929 if (service_port != kIllegalPort) { |
| 960 // Return a send port for the service port. | 930 // Return a send port for the service port. |
| 961 Dart_Handle send_port = Dart_NewSendPort(service_port); | 931 Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 962 Dart_SetReturnValue(args, send_port); | 932 Dart_SetReturnValue(args, send_port); |
| 963 } | 933 } |
| 964 Dart_ExitScope(); | 934 Dart_ExitScope(); |
| 965 } | 935 } |
| OLD | NEW |