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 "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "vm/os.h" | 8 #include "vm/os.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 void OS::DebugBreak() { | 129 void OS::DebugBreak() { |
130 #if defined(HOST_ARCH_X64) || defined(HOST_ARCH_IA32) | 130 #if defined(HOST_ARCH_X64) || defined(HOST_ARCH_IA32) |
131 asm("int $3"); | 131 asm("int $3"); |
132 #else | 132 #else |
133 #error Unsupported architecture. | 133 #error Unsupported architecture. |
134 #endif | 134 #endif |
135 } | 135 } |
136 | 136 |
137 | 137 |
| 138 char* OS::StrNDup(const char* s, intptr_t n) { |
| 139 // strndup has only been added to Mac OS X in 10.7. We are supplying |
| 140 // our own copy here if needed. |
| 141 #if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \ |
| 142 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 1060 |
| 143 intptr_t len = strlen(s); |
| 144 if ((n < 0) || (len < 0)) { |
| 145 return NULL; |
| 146 } |
| 147 if (n < len) { |
| 148 len = n; |
| 149 } |
| 150 char* result = reinterpret_cast<char*>(malloc(len + 1)); |
| 151 if (result == NULL) { |
| 152 return NULL; |
| 153 } |
| 154 result[len] = '\0'; |
| 155 return reinterpret_cast<char*>(memcpy(result, s, len)); |
| 156 #else // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... |
| 157 return strndup(s, n); |
| 158 #endif // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... |
| 159 } |
| 160 |
| 161 |
138 void OS::Print(const char* format, ...) { | 162 void OS::Print(const char* format, ...) { |
139 va_list args; | 163 va_list args; |
140 va_start(args, format); | 164 va_start(args, format); |
141 VFPrint(stdout, format, args); | 165 VFPrint(stdout, format, args); |
142 va_end(args); | 166 va_end(args); |
143 } | 167 } |
144 | 168 |
145 | 169 |
146 void OS::VFPrint(FILE* stream, const char* format, va_list args) { | 170 void OS::VFPrint(FILE* stream, const char* format, va_list args) { |
147 vfprintf(stream, format, args); | 171 vfprintf(stream, format, args); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 241 } |
218 | 242 |
219 | 243 |
220 void OS::Exit(int code) { | 244 void OS::Exit(int code) { |
221 exit(code); | 245 exit(code); |
222 } | 246 } |
223 | 247 |
224 } // namespace dart | 248 } // namespace dart |
225 | 249 |
226 #endif // defined(TARGET_OS_MACOS) | 250 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |