OLD | NEW |
1 // Copyright (c) 2012, 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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "bin/platform.h" | 8 #include "bin/platform.h" |
9 | 9 |
10 #if !TARGET_OS_IOS | 10 #if !TARGET_OS_IOS |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) { | 72 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) { |
73 return gethostname(buffer, buffer_length) == 0; | 73 return gethostname(buffer, buffer_length) == 0; |
74 } | 74 } |
75 | 75 |
76 | 76 |
77 char** Platform::Environment(intptr_t* count) { | 77 char** Platform::Environment(intptr_t* count) { |
78 #if TARGET_OS_IOS | 78 #if TARGET_OS_IOS |
79 // TODO(iposva): On Mac (desktop), _NSGetEnviron() is used to access the | 79 // TODO(zra,chinmaygarde): On iOS, environment variables are seldom used. Wire |
80 // environ from shared libraries or bundles. This is present in crt_externs.h | 80 // this up if someone needs it. In the meantime, we return an empty array. |
81 // which is unavailable on iOS. On iOS, everything is statically linked for | 81 char** result; |
82 // now. So arguably, accessing the environ directly with a "extern char | 82 result = reinterpret_cast<char**>(Dart_ScopeAllocate(1 * sizeof(*result))); |
83 // **environ" will work. But this approach is brittle as the target with this | 83 if (result == NULL) { |
84 // CU could be a dynamic framework (introduced in iOS 8). A more elegant | 84 return NULL; |
85 // approach needs to be devised. | 85 } |
86 return NULL; | 86 result[0] = NULL; |
| 87 *count = 0; |
| 88 return result; |
87 #else | 89 #else |
88 // Using environ directly is only safe as long as we do not | 90 // Using environ directly is only safe as long as we do not |
89 // provide access to modifying environment variables. | 91 // provide access to modifying environment variables. |
90 // On MacOS you have to do a bit of magic to get to the | 92 // On MacOS you have to do a bit of magic to get to the |
91 // environment strings. | 93 // environment strings. |
92 char** environ = *(_NSGetEnviron()); | 94 char** environ = *(_NSGetEnviron()); |
93 intptr_t i = 0; | 95 intptr_t i = 0; |
94 char** tmp = environ; | 96 char** tmp = environ; |
95 while (*(tmp++) != NULL) { | 97 while (*(tmp++) != NULL) { |
96 i++; | 98 i++; |
(...skipping 27 matching lines...) Expand all Loading... |
124 | 126 |
125 | 127 |
126 void Platform::Exit(int exit_code) { | 128 void Platform::Exit(int exit_code) { |
127 exit(exit_code); | 129 exit(exit_code); |
128 } | 130 } |
129 | 131 |
130 } // namespace bin | 132 } // namespace bin |
131 } // namespace dart | 133 } // namespace dart |
132 | 134 |
133 #endif // defined(TARGET_OS_MACOS) | 135 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |