| 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 <mach-o/dyld.h> | 8 #include <mach-o/dyld.h> |
| 9 | 9 |
| 10 #include "bin/file.h" | 10 #include "bin/file.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 return "dylib"; | 50 return "dylib"; |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) { | 54 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) { |
| 55 return gethostname(buffer, buffer_length) == 0; | 55 return gethostname(buffer, buffer_length) == 0; |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| 59 char** Platform::Environment(intptr_t* count) { | 59 char** Platform::Environment(intptr_t* count) { |
| 60 #if defined(TARGET_OS_IOS) |
| 61 // TODO(iposva): On Mac (desktop), _NSGetEnviron() is used to access the |
| 62 // environ from shared libraries or bundles. This is present in crt_externs.h |
| 63 // which is unavailable on iOS. On iOS, everything is statically linked for |
| 64 // now. So arguably, accessing the environ directly with a "extern char |
| 65 // **environ" will work. But this approach is brittle as the target with this |
| 66 // CU could be a dynamic framework (introduced in iOS 8). A more elegant |
| 67 // approach needs to be devised. |
| 68 return NULL; |
| 69 #else |
| 60 // Using environ directly is only safe as long as we do not | 70 // Using environ directly is only safe as long as we do not |
| 61 // provide access to modifying environment variables. | 71 // provide access to modifying environment variables. |
| 62 // On MacOS you have to do a bit of magic to get to the | 72 // On MacOS you have to do a bit of magic to get to the |
| 63 // environment strings. | 73 // environment strings. |
| 64 char** environ = *(_NSGetEnviron()); | 74 char** environ = *(_NSGetEnviron()); |
| 65 intptr_t i = 0; | 75 intptr_t i = 0; |
| 66 char** tmp = environ; | 76 char** tmp = environ; |
| 67 while (*(tmp++) != NULL) i++; | 77 while (*(tmp++) != NULL) i++; |
| 68 *count = i; | 78 *count = i; |
| 69 char** result = new char*[i]; | 79 char** result = new char*[i]; |
| 70 for (intptr_t current = 0; current < i; current++) { | 80 for (intptr_t current = 0; current < i; current++) { |
| 71 result[current] = environ[current]; | 81 result[current] = environ[current]; |
| 72 } | 82 } |
| 73 return result; | 83 return result; |
| 84 #endif |
| 74 } | 85 } |
| 75 | 86 |
| 76 | 87 |
| 77 void Platform::FreeEnvironment(char** env, intptr_t count) { | 88 void Platform::FreeEnvironment(char** env, intptr_t count) { |
| 78 delete[] env; | 89 delete[] env; |
| 79 } | 90 } |
| 80 | 91 |
| 81 | 92 |
| 82 char* Platform::ResolveExecutablePath() { | 93 char* Platform::ResolveExecutablePath() { |
| 83 // Get the required length of the buffer. | 94 // Get the required length of the buffer. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 95 // Return the canonical path as the returned path might contain symlinks. | 106 // Return the canonical path as the returned path might contain symlinks. |
| 96 char* canon_path = File::GetCanonicalPath(path); | 107 char* canon_path = File::GetCanonicalPath(path); |
| 97 free(path); | 108 free(path); |
| 98 return canon_path; | 109 return canon_path; |
| 99 } | 110 } |
| 100 | 111 |
| 101 } // namespace bin | 112 } // namespace bin |
| 102 } // namespace dart | 113 } // namespace dart |
| 103 | 114 |
| 104 #endif // defined(TARGET_OS_MACOS) | 115 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |