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/version.h" | 5 #include "vm/version.h" |
6 | 6 |
7 #include "vm/cpu.h" | 7 #include "vm/cpu.h" |
8 #include "vm/os.h" | 8 #include "vm/os.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
11 | 11 |
12 // TODO(iposva): Avoid racy initialization. | 12 // TODO(iposva): Avoid racy initialization. |
13 static const char* formatted_version = NULL; | 13 static const char* formatted_version = NULL; |
14 | 14 |
15 const char* Version::String() { | 15 const char* Version::String() { |
16 if (formatted_version == NULL) { | 16 if (formatted_version == NULL) { |
17 const char* format = "%s on \"%s_%s\""; | |
18 const char* os = OS::Name(); | 17 const char* os = OS::Name(); |
19 const char* arch = CPU::Id(); | 18 const char* arch = CPU::Id(); |
20 | 19 formatted_version = OS::SCreate(NULL, "%s on \"%s_%s\"", str_, os, arch); |
21 intptr_t len = OS::SNPrint(NULL, 0, format, str_, os, arch); | |
22 char* buffer = reinterpret_cast<char*>(malloc(len + 1)); | |
23 OS::SNPrint(buffer, (len + 1), format, str_, os, arch); | |
24 formatted_version = buffer; | |
25 } | 20 } |
26 return formatted_version; | 21 return formatted_version; |
27 } | 22 } |
28 | 23 |
29 | 24 |
30 const char* Version::SnapshotString() { | 25 const char* Version::SnapshotString() { |
31 return snapshot_hash_; | 26 return snapshot_hash_; |
32 } | 27 } |
33 | 28 |
34 const char* Version::snapshot_hash_ = "{{SNAPSHOT_HASH}}"; | 29 const char* Version::snapshot_hash_ = "{{SNAPSHOT_HASH}}"; |
35 const char* Version::str_ = "{{VERSION_STR}} ({{BUILD_TIME}})"; | 30 const char* Version::str_ = "{{VERSION_STR}} ({{BUILD_TIME}})"; |
36 | 31 |
37 } // namespace dart | 32 } // namespace dart |
OLD | NEW |