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

Unified Diff: runtime/bin/platform_macos.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_macos.cc
diff --git a/runtime/bin/platform_macos.cc b/runtime/bin/platform_macos.cc
index 84cce9293ea7a5951b3d8f83bd54f40409721a9e..81455ba3d3988ae7348433d517836d4b83fb96ed 100644
--- a/runtime/bin/platform_macos.cc
+++ b/runtime/bin/platform_macos.cc
@@ -1,9 +1,10 @@
-// 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.
#include "bin/platform.h"
+#include <crt_externs.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
@@ -39,6 +40,24 @@ bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) {
}
+char** Platform::Environment(intptr_t* count) {
+ // Using environ directly is only safe as long as we do not
+ // provide access to modifying environment variables.
+ // On MacOS you have to do a bit of magic to get to the
+ // environment strings.
+ char** environ = *(_NSGetEnviron());
+ intptr_t i = 0;
+ char** tmp = environ;
+ while (*(tmp++) != NULL) i++;
+ *count = i;
+ char** result = new char*[i];
+ for (intptr_t current = 0; current < i; current++) {
+ result[current] = environ[current];
+ }
+ return result;
+}
+
+
char* Platform::StrError(int error_code) {
static const int kBufferSize = 1024;
char* error = static_cast<char*>(malloc(kBufferSize));

Powered by Google App Engine
This is Rietveld 408576698