| 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 |
| 10 #if !HOST_OS_IOS | 12 #if !HOST_OS_IOS |
| 11 #include <crt_externs.h> // NOLINT | 13 #include <crt_externs.h> // NOLINT |
| 12 #endif // !HOST_OS_IOS | 14 #endif // !HOST_OS_IOS |
| 13 #include <mach-o/dyld.h> | 15 #include <mach-o/dyld.h> |
| 14 #include <signal.h> // NOLINT | 16 #include <signal.h> // NOLINT |
| 15 #include <string.h> // NOLINT | 17 #include <string.h> // NOLINT |
| 16 #include <sys/sysctl.h> // NOLINT | 18 #include <sys/sysctl.h> // NOLINT |
| 17 #include <sys/types.h> // NOLINT | 19 #include <sys/types.h> // NOLINT |
| 18 #include <unistd.h> // NOLINT | 20 #include <unistd.h> // NOLINT |
| 19 | 21 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 const char* Platform::LibraryPrefix() { | 93 const char* Platform::LibraryPrefix() { |
| 92 return "lib"; | 94 return "lib"; |
| 93 } | 95 } |
| 94 | 96 |
| 95 | 97 |
| 96 const char* Platform::LibraryExtension() { | 98 const char* Platform::LibraryExtension() { |
| 97 return "dylib"; | 99 return "dylib"; |
| 98 } | 100 } |
| 99 | 101 |
| 100 | 102 |
| 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 |
| 101 bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) { | 157 bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) { |
| 102 return gethostname(buffer, buffer_length) == 0; | 158 return gethostname(buffer, buffer_length) == 0; |
| 103 } | 159 } |
| 104 | 160 |
| 105 | 161 |
| 106 char** Platform::Environment(intptr_t* count) { | 162 char** Platform::Environment(intptr_t* count) { |
| 107 #if HOST_OS_IOS | 163 #if HOST_OS_IOS |
| 108 // TODO(zra,chinmaygarde): On iOS, environment variables are seldom used. Wire | 164 // TODO(zra,chinmaygarde): On iOS, environment variables are seldom used. Wire |
| 109 // this up if someone needs it. In the meantime, we return an empty array. | 165 // this up if someone needs it. In the meantime, we return an empty array. |
| 110 char** result; | 166 char** result; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 211 |
| 156 | 212 |
| 157 void Platform::Exit(int exit_code) { | 213 void Platform::Exit(int exit_code) { |
| 158 exit(exit_code); | 214 exit(exit_code); |
| 159 } | 215 } |
| 160 | 216 |
| 161 } // namespace bin | 217 } // namespace bin |
| 162 } // namespace dart | 218 } // namespace dart |
| 163 | 219 |
| 164 #endif // defined(HOST_OS_MACOS) | 220 #endif // defined(HOST_OS_MACOS) |
| OLD | NEW |