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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 198 |
199 int OS::SNPrint(char* str, size_t size, const char* format, ...) { | 199 int OS::SNPrint(char* str, size_t size, const char* format, ...) { |
200 va_list args; | 200 va_list args; |
201 va_start(args, format); | 201 va_start(args, format); |
202 int retval = VSNPrint(str, size, format, args); | 202 int retval = VSNPrint(str, size, format, args); |
203 va_end(args); | 203 va_end(args); |
204 return retval; | 204 return retval; |
205 } | 205 } |
206 | 206 |
207 | 207 |
| 208 char* OS::SNCreate(Zone* zone, const char* format, ...) { |
| 209 va_list args; |
| 210 va_start(args, format); |
| 211 |
| 212 // Measure. |
| 213 va_list measure_args; |
| 214 va_copy(measure_args, args); |
| 215 intptr_t len = VSNPrint(NULL, 0, format, measure_args); |
| 216 va_end(measure_args); |
| 217 |
| 218 char* buffer; |
| 219 if (zone) { |
| 220 buffer = zone->Alloc<char>(len + 1); |
| 221 } else { |
| 222 buffer = reinterpret_cast<char*>(malloc(len + 1)); |
| 223 } |
| 224 ASSERT(buffer != NULL); |
| 225 |
| 226 // Print. |
| 227 va_list print_args; |
| 228 va_copy(print_args, args); |
| 229 VSNPrint(buffer, len + 1, format, print_args); |
| 230 va_end(print_args); |
| 231 va_end(args); |
| 232 return buffer; |
| 233 } |
| 234 |
| 235 |
208 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { | 236 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
209 int retval = vsnprintf(str, size, format, args); | 237 int retval = vsnprintf(str, size, format, args); |
210 if (retval < 0) { | 238 if (retval < 0) { |
211 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); | 239 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); |
212 } | 240 } |
213 return retval; | 241 return retval; |
214 } | 242 } |
215 | 243 |
216 | 244 |
217 bool OS::StringToInt64(const char* str, int64_t* value) { | 245 bool OS::StringToInt64(const char* str, int64_t* value) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 292 } |
265 | 293 |
266 | 294 |
267 void OS::Exit(int code) { | 295 void OS::Exit(int code) { |
268 exit(code); | 296 exit(code); |
269 } | 297 } |
270 | 298 |
271 } // namespace dart | 299 } // namespace dart |
272 | 300 |
273 #endif // defined(TARGET_OS_MACOS) | 301 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |