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 #include "util/stdlib/strlcpy.h" | 15 #include "util/stdlib/strlcpy.h" |
16 | 16 |
| 17 #include "base/logging.h" |
| 18 #include "build/build_config.h" |
| 19 |
| 20 #if defined(OS_WIN) && defined(WCHAR_T_IS_UTF16) |
| 21 #include <strsafe.h> |
| 22 #endif |
| 23 |
17 namespace crashpad { | 24 namespace crashpad { |
18 | 25 |
| 26 #if defined(OS_WIN) && defined(WCHAR_T_IS_UTF16) |
| 27 |
19 size_t c16lcpy(base::char16* destination, | 28 size_t c16lcpy(base::char16* destination, |
20 const base::char16* source, | 29 const base::char16* source, |
21 size_t length) { | 30 size_t length) { |
| 31 HRESULT result = StringCchCopyW(destination, length, source); |
| 32 CHECK(result == S_OK || result == STRSAFE_E_INSUFFICIENT_BUFFER); |
| 33 return wcslen(source); |
| 34 } |
| 35 |
| 36 #elif defined(WCHAR_T_IS_UTF32) |
| 37 |
| 38 size_t c16lcpy(base::char16* destination, |
| 39 const base::char16* source, |
| 40 size_t length) { |
22 size_t source_length = base::c16len(source); | 41 size_t source_length = base::c16len(source); |
23 if (source_length < length) { | 42 if (source_length < length) { |
24 base::c16memcpy(destination, source, source_length + 1); | 43 base::c16memcpy(destination, source, source_length + 1); |
25 } else if (length != 0) { | 44 } else if (length != 0) { |
26 base::c16memcpy(destination, source, length - 1); | 45 base::c16memcpy(destination, source, length - 1); |
27 destination[length - 1] = '\0'; | 46 destination[length - 1] = '\0'; |
28 } | 47 } |
29 return source_length; | 48 return source_length; |
30 } | 49 } |
31 | 50 |
| 51 #endif // WCHAR_T_IS_UTF32 |
| 52 |
32 } // namespace crashpad | 53 } // namespace crashpad |
OLD | NEW |