| 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/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 #include "bin/directory.h" | 6 #include "bin/directory.h" |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 static intptr_t GetHandlerPort(Dart_Handle handle) { | 10 static intptr_t GetHandlerPort(Dart_Handle handle) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 73 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 74 } | 74 } |
| 75 Dart_ExitScope(); | 75 Dart_ExitScope(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 | 78 |
| 79 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { | 79 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { |
| 80 Dart_EnterScope(); | 80 Dart_EnterScope(); |
| 81 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 81 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
| 82 Dart_Handle number = Dart_GetNativeArgument(args, 1); | 82 Dart_Handle number = Dart_GetNativeArgument(args, 1); |
| 83 if (Dart_IsString(path) && Dart_IsInteger(number)) { | 83 Dart_Handle status_handle = Dart_GetNativeArgument(args, 2); |
| 84 char* result = Directory::CreateTemp(DartUtils::GetStringValue(path), | 84 static const int kMaxChildOsErrorMessageLength = 256; |
| 85 DartUtils::GetIntegerValue(number)); | 85 char os_error_message[kMaxChildOsErrorMessageLength]; |
| 86 if (!Dart_IsString(path) || !Dart_IsInteger(number)) { |
| 87 DartUtils::SetIntegerInstanceField(status_handle, "_errorCode", 0); |
| 88 DartUtils::SetStringInstanceField( |
| 89 status_handle, "_errorMessage", "Invalid arguments"); |
| 90 Dart_SetReturnValue(args, Dart_Null()); |
| 91 Dart_ExitScope(); |
| 92 return; |
| 93 } |
| 94 |
| 95 char* result = NULL; |
| 96 int error_code = Directory::CreateTemp(DartUtils::GetStringValue(path), |
| 97 DartUtils::GetIntegerValue(number), |
| 98 &result, |
| 99 os_error_message, |
| 100 kMaxChildOsErrorMessageLength); |
| 101 if (error_code == 0) { |
| 86 Dart_SetReturnValue(args, Dart_NewString(result)); | 102 Dart_SetReturnValue(args, Dart_NewString(result)); |
| 87 free(result); | 103 free(result); |
| 88 } else { | 104 } else { |
| 89 Dart_SetReturnValue(args, Dart_NewString("")); | 105 ASSERT(result == NULL); |
| 106 if (error_code == -1) { |
| 107 DartUtils::SetIntegerInstanceField(status_handle, "_errorCode", 0); |
| 108 DartUtils::SetStringInstanceField( |
| 109 status_handle, "_errorMessage", "Invalid arguments"); |
| 110 } else { |
| 111 DartUtils::SetIntegerInstanceField( |
| 112 status_handle, "_errorCode", error_code); |
| 113 DartUtils::SetStringInstanceField( |
| 114 status_handle, "_errorMessage", os_error_message); |
| 115 } |
| 116 Dart_SetReturnValue(args, Dart_Null()); |
| 90 } | 117 } |
| 91 Dart_ExitScope(); | 118 Dart_ExitScope(); |
| 92 } | 119 } |
| 93 | 120 |
| 94 | 121 |
| 95 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { | 122 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { |
| 96 Dart_EnterScope(); | 123 Dart_EnterScope(); |
| 97 Dart_Handle path = Dart_GetNativeArgument(args, 1); | 124 Dart_Handle path = Dart_GetNativeArgument(args, 1); |
| 98 if (Dart_IsString(path)) { | 125 if (Dart_IsString(path)) { |
| 99 bool deleted = Directory::Delete(DartUtils::GetStringValue(path)); | 126 bool deleted = Directory::Delete(DartUtils::GetStringValue(path)); |
| 100 Dart_SetReturnValue(args, Dart_NewBoolean(deleted)); | 127 Dart_SetReturnValue(args, Dart_NewBoolean(deleted)); |
| 101 } else { | 128 } else { |
| 102 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 129 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 103 } | 130 } |
| 104 Dart_ExitScope(); | 131 Dart_ExitScope(); |
| 105 } | 132 } |
| OLD | NEW |