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_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "vm/os.h" | 8 #include "vm/os.h" |
9 | 9 |
10 #include <malloc.h> // NOLINT | 10 #include <malloc.h> // NOLINT |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 229 |
230 int OS::SNPrint(char* str, size_t size, const char* format, ...) { | 230 int OS::SNPrint(char* str, size_t size, const char* format, ...) { |
231 va_list args; | 231 va_list args; |
232 va_start(args, format); | 232 va_start(args, format); |
233 int retval = VSNPrint(str, size, format, args); | 233 int retval = VSNPrint(str, size, format, args); |
234 va_end(args); | 234 va_end(args); |
235 return retval; | 235 return retval; |
236 } | 236 } |
237 | 237 |
238 | 238 |
| 239 char* OS::SNCreate(Zone* zone, const char* format, ...) { |
| 240 va_list args; |
| 241 va_start(args, format); |
| 242 |
| 243 // Measure. |
| 244 va_list measure_args; |
| 245 va_copy(measure_args, args); |
| 246 intptr_t len = VSNPrint(NULL, 0, format, measure_args); |
| 247 va_end(measure_args); |
| 248 |
| 249 char* buffer; |
| 250 if (zone) { |
| 251 buffer = zone->Alloc<char>(len + 1); |
| 252 } else { |
| 253 buffer = reinterpret_cast<char*>(malloc(len + 1)); |
| 254 } |
| 255 ASSERT(buffer != NULL); |
| 256 |
| 257 // Print. |
| 258 va_list print_args; |
| 259 va_copy(print_args, args); |
| 260 VSNPrint(buffer, len + 1, format, print_args); |
| 261 va_end(print_args); |
| 262 va_end(args); |
| 263 return buffer; |
| 264 } |
| 265 |
| 266 |
239 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { | 267 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
240 if (str == NULL || size == 0) { | 268 if (str == NULL || size == 0) { |
241 int retval = _vscprintf(format, args); | 269 int retval = _vscprintf(format, args); |
242 if (retval < 0) { | 270 if (retval < 0) { |
243 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); | 271 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); |
244 } | 272 } |
245 return retval; | 273 return retval; |
246 } | 274 } |
247 va_list args_copy; | 275 va_list args_copy; |
248 va_copy(args_copy, args); | 276 va_copy(args_copy, args); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 356 } |
329 | 357 |
330 | 358 |
331 void OS::Exit(int code) { | 359 void OS::Exit(int code) { |
332 exit(code); | 360 exit(code); |
333 } | 361 } |
334 | 362 |
335 } // namespace dart | 363 } // namespace dart |
336 | 364 |
337 #endif // defined(TARGET_OS_WINDOWS) | 365 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |