| 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(HOST_OS_MACOS) | 6 #if defined(HOST_OS_MACOS) |
| 7 | 7 |
| 8 #include "bin/platform.h" | 8 #include "bin/platform.h" |
| 9 | 9 |
| 10 #include <CoreFoundation/CoreFoundation.h> | |
| 11 | |
| 12 #if !HOST_OS_IOS | 10 #if !HOST_OS_IOS |
| 13 #include <crt_externs.h> // NOLINT | 11 #include <crt_externs.h> // NOLINT |
| 14 #endif // !HOST_OS_IOS | 12 #endif // !HOST_OS_IOS |
| 15 #include <mach-o/dyld.h> | 13 #include <mach-o/dyld.h> |
| 16 #include <signal.h> // NOLINT | 14 #include <signal.h> // NOLINT |
| 17 #include <string.h> // NOLINT | 15 #include <string.h> // NOLINT |
| 18 #include <sys/sysctl.h> // NOLINT | 16 #include <sys/sysctl.h> // NOLINT |
| 19 #include <sys/types.h> // NOLINT | 17 #include <sys/types.h> // NOLINT |
| 20 #include <unistd.h> // NOLINT | 18 #include <unistd.h> // NOLINT |
| 21 | 19 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 const char* Platform::LibraryPrefix() { | 91 const char* Platform::LibraryPrefix() { |
| 94 return "lib"; | 92 return "lib"; |
| 95 } | 93 } |
| 96 | 94 |
| 97 | 95 |
| 98 const char* Platform::LibraryExtension() { | 96 const char* Platform::LibraryExtension() { |
| 99 return "dylib"; | 97 return "dylib"; |
| 100 } | 98 } |
| 101 | 99 |
| 102 | 100 |
| 103 static const char* GetLocaleName() { | |
| 104 CFLocaleRef locale = CFLocaleCopyCurrent(); | |
| 105 CFLocaleIdentifier locale_id = CFLocaleGetIdentifier(locale); | |
| 106 CFStringRef locale_string = reinterpret_cast<CFStringRef>(locale_id); | |
| 107 CFIndex len = CFStringGetLength(locale_string); | |
| 108 CFIndex max_len = | |
| 109 CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8) + 1; | |
| 110 char* result = reinterpret_cast<char*>(Dart_ScopeAllocate(max_len)); | |
| 111 ASSERT(result != NULL); | |
| 112 bool success = | |
| 113 CFStringGetCString(locale_string, result, max_len, kCFStringEncodingUTF8); | |
| 114 CFRelease(locale); | |
| 115 if (!success) { | |
| 116 return NULL; | |
| 117 } | |
| 118 return result; | |
| 119 } | |
| 120 | |
| 121 | |
| 122 static const char* GetPreferredLanguageName() { | |
| 123 CFArrayRef languages = CFLocaleCopyPreferredLanguages(); | |
| 124 CFIndex languages_length = CFArrayGetCount(languages); | |
| 125 if (languages_length < 1) { | |
| 126 CFRelease(languages); | |
| 127 return NULL; | |
| 128 } | |
| 129 CFTypeRef item = | |
| 130 reinterpret_cast<CFTypeRef>(CFArrayGetValueAtIndex(languages, 0)); | |
| 131 CFTypeID item_type = CFGetTypeID(item); | |
| 132 ASSERT(item_type == CFStringGetTypeID()); | |
| 133 CFStringRef language = reinterpret_cast<CFStringRef>(item); | |
| 134 CFIndex len = CFStringGetLength(language); | |
| 135 CFIndex max_len = | |
| 136 CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8) + 1; | |
| 137 char* result = reinterpret_cast<char*>(Dart_ScopeAllocate(max_len)); | |
| 138 ASSERT(result != NULL); | |
| 139 bool success = | |
| 140 CFStringGetCString(language, result, max_len, kCFStringEncodingUTF8); | |
| 141 CFRelease(languages); | |
| 142 if (!success) { | |
| 143 return NULL; | |
| 144 } | |
| 145 return result; | |
| 146 } | |
| 147 | |
| 148 | |
| 149 const char* Platform::LocaleName() { | |
| 150 // First see if there is a preferred language. If not, return the | |
| 151 // current locale name. | |
| 152 const char* preferred_langauge = GetPreferredLanguageName(); | |
| 153 return (preferred_langauge != NULL) ? preferred_langauge : GetLocaleName(); | |
| 154 } | |
| 155 | |
| 156 | |
| 157 bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) { | 101 bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) { |
| 158 return gethostname(buffer, buffer_length) == 0; | 102 return gethostname(buffer, buffer_length) == 0; |
| 159 } | 103 } |
| 160 | 104 |
| 161 | 105 |
| 162 char** Platform::Environment(intptr_t* count) { | 106 char** Platform::Environment(intptr_t* count) { |
| 163 #if HOST_OS_IOS | 107 #if HOST_OS_IOS |
| 164 // TODO(zra,chinmaygarde): On iOS, environment variables are seldom used. Wire | 108 // TODO(zra,chinmaygarde): On iOS, environment variables are seldom used. Wire |
| 165 // this up if someone needs it. In the meantime, we return an empty array. | 109 // this up if someone needs it. In the meantime, we return an empty array. |
| 166 char** result; | 110 char** result; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 155 |
| 212 | 156 |
| 213 void Platform::Exit(int exit_code) { | 157 void Platform::Exit(int exit_code) { |
| 214 exit(exit_code); | 158 exit(exit_code); |
| 215 } | 159 } |
| 216 | 160 |
| 217 } // namespace bin | 161 } // namespace bin |
| 218 } // namespace dart | 162 } // namespace dart |
| 219 | 163 |
| 220 #endif // defined(HOST_OS_MACOS) | 164 #endif // defined(HOST_OS_MACOS) |
| OLD | NEW |