Index: runtime/bin/platform.cc |
diff --git a/runtime/bin/platform.cc b/runtime/bin/platform.cc |
index f8398f415174719fb6ffcb594c9d64983281b8b0..34c29100272deb6062fea5d42304670527491eff 100644 |
--- a/runtime/bin/platform.cc |
+++ b/runtime/bin/platform.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
@@ -39,3 +39,34 @@ void FUNCTION_NAME(Platform_LocalHostname)(Dart_NativeArguments args) { |
} |
Dart_ExitScope(); |
} |
+ |
+ |
+void FUNCTION_NAME(Platform_Environment)(Dart_NativeArguments args) { |
+ Dart_EnterScope(); |
+ intptr_t count = 0; |
+ char** env = Platform::Environment(&count); |
+ if (env == NULL) { |
+ OSError error(-1, |
+ "Failed to retrieve environment variables.", |
+ OSError::kUnknown); |
+ Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); |
+ } else { |
+ Dart_Handle result = Dart_NewList(count); |
+ if (Dart_IsError(result)) { |
+ Dart_PropagateError(result); |
+ } |
+ for (intptr_t i = 0; i < count; i++) { |
+ Dart_Handle str = Dart_NewString(env[i]); |
+ if (Dart_IsError(str)) { |
+ Dart_PropagateError(str); |
+ } |
+ Dart_Handle error = Dart_ListSetAt(result, i, str); |
+ if (Dart_IsError(error)) { |
+ Dart_PropagateError(error); |
+ } |
+ } |
+ delete[] env; |
+ Dart_SetReturnValue(args, result); |
+ } |
+ Dart_ExitScope(); |
+} |