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/strnlen.h" | 15 #include "util/stdlib/strnlen.h" |
16 | 16 |
| 17 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 |
| 18 |
| 19 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 |
| 20 // Redeclare a method only available on OSX 10.7+ to suppress a |
| 21 // -Wpartial-availability warning. |
| 22 extern "C" { |
| 23 size_t strnlen(const char* string, size_t max_length); |
| 24 } // extern "C" |
| 25 #endif |
| 26 |
17 namespace crashpad { | 27 namespace crashpad { |
18 | 28 |
19 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 | |
20 size_t strnlen(const char* string, size_t max_length) { | 29 size_t strnlen(const char* string, size_t max_length) { |
21 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | 30 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 |
22 if (::strnlen) { | 31 if (::strnlen) { |
23 return ::strnlen(string, max_length); | 32 return ::strnlen(string, max_length); |
24 } | 33 } |
25 #endif | 34 #endif |
26 | 35 |
27 for (size_t index = 0; index < max_length; ++index) { | 36 for (size_t index = 0; index < max_length; ++index) { |
28 if (string[index] == '\0') { | 37 if (string[index] == '\0') { |
29 return index; | 38 return index; |
30 } | 39 } |
31 } | 40 } |
32 | 41 |
33 return max_length; | 42 return max_length; |
34 } | 43 } |
35 #endif | |
36 | 44 |
37 } // namespace crashpad | 45 } // namespace crashpad |
| 46 |
| 47 #endif |
OLD | NEW |