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

Unified Diff: runtime/bin/platform.cc

Issue 10112002: Add read-only environment variable access. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add windows error handling. 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 side-by-side diff with in-line comments
Download patch
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();
+}
« no previous file with comments | « runtime/bin/platform.h ('k') | runtime/bin/platform.dart » ('j') | runtime/bin/platform_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698