OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #if !defined(__STDC_FORMAT_MACROS) | 15 #if !defined(__STDC_FORMAT_MACROS) |
16 #define __STDC_FORMAT_MACROS | 16 #define __STDC_FORMAT_MACROS |
17 #endif | 17 #endif |
18 | 18 |
19 #include "util/misc/uuid.h" | 19 #include "util/misc/uuid.h" |
20 | 20 |
21 #include <inttypes.h> | 21 #include <inttypes.h> |
22 #include <stdio.h> | 22 #include <stdio.h> |
23 #include <string.h> | 23 #include <string.h> |
24 | 24 |
25 #include "base/basictypes.h" | 25 #include "base/basictypes.h" |
| 26 #include "base/logging.h" |
26 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
27 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
28 #include "base/sys_byteorder.h" | 29 #include "base/sys_byteorder.h" |
29 #include "util/stdlib/cxx.h" | 30 #include "util/stdlib/cxx.h" |
30 | 31 |
| 32 #if defined(OS_MACOSX) |
| 33 #include <uuid/uuid.h> |
| 34 #endif // OS_MACOSX |
| 35 |
31 #if CXX_LIBRARY_VERSION >= 2011 | 36 #if CXX_LIBRARY_VERSION >= 2011 |
32 #include <type_traits> | 37 #include <type_traits> |
33 #endif | 38 #endif |
34 | 39 |
35 namespace crashpad { | 40 namespace crashpad { |
36 | 41 |
37 static_assert(sizeof(UUID) == 16, "UUID must be 16 bytes"); | 42 static_assert(sizeof(UUID) == 16, "UUID must be 16 bytes"); |
38 | 43 |
39 #if CXX_LIBRARY_VERSION >= 2011 | 44 #if CXX_LIBRARY_VERSION >= 2011 |
40 static_assert(std::is_standard_layout<UUID>::value, | 45 static_assert(std::is_standard_layout<UUID>::value, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 &temp.data_5[3], | 86 &temp.data_5[3], |
82 &temp.data_5[4], | 87 &temp.data_5[4], |
83 &temp.data_5[5]); | 88 &temp.data_5[5]); |
84 if (rv != 11) | 89 if (rv != 11) |
85 return false; | 90 return false; |
86 | 91 |
87 *this = temp; | 92 *this = temp; |
88 return true; | 93 return true; |
89 } | 94 } |
90 | 95 |
| 96 bool UUID::InitializeWithNew() { |
| 97 #if defined(OS_MACOSX) |
| 98 uuid_t uuid; |
| 99 uuid_generate(uuid); |
| 100 InitializeFromBytes(uuid); |
| 101 return true; |
| 102 #elif defined(OS_WIN) |
| 103 ::UUID system_uuid; |
| 104 if (UuidCreate(&system_uuid) != RPC_S_OK) { |
| 105 LOG(ERROR) << "UuidCreate"; |
| 106 return false; |
| 107 } |
| 108 InitializeFromSystemUUID(&system_uuid); |
| 109 return true; |
| 110 #else |
| 111 #error Port. |
| 112 #endif // OS_MACOSX |
| 113 } |
| 114 |
91 #if defined(OS_WIN) | 115 #if defined(OS_WIN) |
92 void UUID::InitializeFromSystemUUID(const ::UUID* system_uuid) { | 116 void UUID::InitializeFromSystemUUID(const ::UUID* system_uuid) { |
93 static_assert(sizeof(::UUID) == sizeof(UUID), | 117 static_assert(sizeof(::UUID) == sizeof(UUID), |
94 "unexpected system uuid size"); | 118 "unexpected system uuid size"); |
95 static_assert(offsetof(::UUID, Data1) == offsetof(UUID, data_1), | 119 static_assert(offsetof(::UUID, Data1) == offsetof(UUID, data_1), |
96 "unexpected system uuid layout"); | 120 "unexpected system uuid layout"); |
97 memcpy(this, system_uuid, sizeof(::UUID)); | 121 memcpy(this, system_uuid, sizeof(::UUID)); |
98 } | 122 } |
99 #endif // OS_WIN | 123 #endif // OS_WIN |
100 | 124 |
(...skipping 12 matching lines...) Expand all Loading... |
113 data_5[5]); | 137 data_5[5]); |
114 } | 138 } |
115 | 139 |
116 #if defined(OS_WIN) | 140 #if defined(OS_WIN) |
117 base::string16 UUID::ToString16() const { | 141 base::string16 UUID::ToString16() const { |
118 return base::UTF8ToUTF16(ToString()); | 142 return base::UTF8ToUTF16(ToString()); |
119 } | 143 } |
120 #endif // OS_WIN | 144 #endif // OS_WIN |
121 | 145 |
122 } // namespace crashpad | 146 } // namespace crashpad |
OLD | NEW |