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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, 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/platform.h" 5 #include "bin/platform.h"
6 6
7 #include <crt_externs.h>
7 #include <signal.h> 8 #include <signal.h>
8 #include <string.h> 9 #include <string.h>
9 #include <unistd.h> 10 #include <unistd.h>
10 11
11 12
12 bool Platform::Initialize() { 13 bool Platform::Initialize() {
13 // Turn off the signal handler for SIGPIPE as it causes the process 14 // Turn off the signal handler for SIGPIPE as it causes the process
14 // to terminate on writing to a closed pipe. Without the signal 15 // to terminate on writing to a closed pipe. Without the signal
15 // handler error EPIPE is set instead. 16 // handler error EPIPE is set instead.
16 struct sigaction act; 17 struct sigaction act;
(...skipping 15 matching lines...) Expand all
32 const char* Platform::OperatingSystem() { 33 const char* Platform::OperatingSystem() {
33 return "macos"; 34 return "macos";
34 } 35 }
35 36
36 37
37 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) { 38 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) {
38 return gethostname(buffer, buffer_length) == 0; 39 return gethostname(buffer, buffer_length) == 0;
39 } 40 }
40 41
41 42
43 char** Platform::Environment(intptr_t* count) {
44 // Using environ directly is only safe as long as we do not
45 // provide access to modifying environment variables.
46 // On MacOS you have to do a bit of magic to get to the
47 // environment strings.
48 char** environ = *(_NSGetEnviron());
49 intptr_t i = 0;
50 char** tmp = environ;
51 while (*(tmp++) != NULL) i++;
52 *count = i;
53 char** result = new char*[i];
54 for (intptr_t current = 0; current < i; current++) {
55 result[current] = environ[current];
56 }
57 return result;
58 }
59
60
42 char* Platform::StrError(int error_code) { 61 char* Platform::StrError(int error_code) {
43 static const int kBufferSize = 1024; 62 static const int kBufferSize = 1024;
44 char* error = static_cast<char*>(malloc(kBufferSize)); 63 char* error = static_cast<char*>(malloc(kBufferSize));
45 error[0] = '\0'; 64 error[0] = '\0';
46 strerror_r(error_code, error, kBufferSize); 65 strerror_r(error_code, error, kBufferSize);
47 return error; 66 return error;
48 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698