Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: runtime/vm/os_win.cc

Issue 1331623002: Uses SNPRINT macro where possible. Otherwise uses #define for format. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add missing include Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/os_macos.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include <process.h> // NOLINT 11 #include <process.h> // NOLINT
12 #include <time.h> // NOLINT 12 #include <time.h> // NOLINT
13 13
14 #include "platform/utils.h" 14 #include "platform/utils.h"
15 #include "platform/assert.h" 15 #include "platform/assert.h"
16 #include "vm/os_thread.h" 16 #include "vm/os_thread.h"
17 #include "vm/vtune.h" 17 #include "vm/vtune.h"
18 #include "vm/zone.h"
18 19
19 namespace dart { 20 namespace dart {
20 21
21 const char* OS::Name() { 22 const char* OS::Name() {
22 return "windows"; 23 return "windows";
23 } 24 }
24 25
25 26
26 intptr_t OS::ProcessId() { 27 intptr_t OS::ProcessId() {
27 return static_cast<intptr_t>(GetCurrentProcessId()); 28 return static_cast<intptr_t>(GetCurrentProcessId());
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // truncated or if there was an error. 265 // truncated or if there was an error.
265 // The static cast is safe here as we have already determined that 'written' 266 // The static cast is safe here as we have already determined that 'written'
266 // is >= 0. 267 // is >= 0.
267 if (static_cast<size_t>(written) >= size) { 268 if (static_cast<size_t>(written) >= size) {
268 str[size - 1] = '\0'; 269 str[size - 1] = '\0';
269 } 270 }
270 return written; 271 return written;
271 } 272 }
272 273
273 274
275 char* OS::SCreate(Zone* zone, const char* format, ...) {
276 va_list args;
277 va_start(args, format);
278 char* buffer = VSCreate(zone, format, args);
279 va_end(args);
280 return buffer;
281 }
282
283
284 char* OS::VSCreate(Zone* zone, const char* format, va_list args) {
285 // Measure.
286 va_list measure_args;
287 va_copy(measure_args, args);
288 intptr_t len = VSNPrint(NULL, 0, format, measure_args);
289 va_end(measure_args);
290
291 char* buffer;
292 if (zone) {
293 buffer = zone->Alloc<char>(len + 1);
294 } else {
295 buffer = reinterpret_cast<char*>(malloc(len + 1));
296 }
297 ASSERT(buffer != NULL);
298
299 // Print.
300 va_list print_args;
301 va_copy(print_args, args);
302 VSNPrint(buffer, len + 1, format, print_args);
303 va_end(print_args);
304 return buffer;
305 }
306
307
274 bool OS::StringToInt64(const char* str, int64_t* value) { 308 bool OS::StringToInt64(const char* str, int64_t* value) {
275 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); 309 ASSERT(str != NULL && strlen(str) > 0 && value != NULL);
276 int32_t base = 10; 310 int32_t base = 10;
277 char* endptr; 311 char* endptr;
278 int i = 0; 312 int i = 0;
279 if (str[0] == '-') { 313 if (str[0] == '-') {
280 i = 1; 314 i = 1;
281 } 315 }
282 if ((str[i] == '0') && 316 if ((str[i] == '0') &&
283 (str[i + 1] == 'x' || str[i + 1] == 'X') && 317 (str[i + 1] == 'x' || str[i + 1] == 'X') &&
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 362 }
329 363
330 364
331 void OS::Exit(int code) { 365 void OS::Exit(int code) {
332 exit(code); 366 exit(code);
333 } 367 }
334 368
335 } // namespace dart 369 } // namespace dart
336 370
337 #endif // defined(TARGET_OS_WINDOWS) 371 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/vm/os_macos.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698