Chromium Code Reviews| 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) && \ | |
| 18 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 && \ | |
| 19 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | |
| 20 // Forward declare a method only available on OSX 10.7+ so that | |
|
Mark Mentovai
2015/04/29 00:33:52
There’s nothing really “forward” about this, it’s
erikchen
2015/04/30 00:34:42
Right. Updated the comment.
| |
| 21 // -Wpartial-availability does not emit a warning. | |
| 22 size_t strnlen(const char*, size_t); | |
|
Mark Mentovai
2015/04/29 00:33:52
The parameters should be named, and this ought to
erikchen
2015/04/30 00:34:42
I've done as you suggested. The extern "C" seems t
| |
| 23 #endif | |
| 24 | |
| 17 namespace crashpad { | 25 namespace crashpad { |
| 18 | 26 |
| 19 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 | 27 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 |
|
Mark Mentovai
2015/04/29 00:33:52
We should be sharing this #ifdef. You can move it
erikchen
2015/04/30 00:34:42
Done.
| |
| 20 size_t strnlen(const char* string, size_t max_length) { | 28 size_t strnlen(const char* string, size_t max_length) { |
| 21 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | 29 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 |
| 22 if (::strnlen) { | 30 if (::strnlen) { |
|
Mark Mentovai
2015/04/29 00:33:52
This is a check to see whether the symbol exists a
erikchen
2015/04/30 00:34:42
It does not.
$ /Applications/Xcode.app/Contents/D
| |
| 23 return ::strnlen(string, max_length); | 31 return ::strnlen(string, max_length); |
| 24 } | 32 } |
| 25 #endif | 33 #endif |
| 26 | 34 |
| 27 for (size_t index = 0; index < max_length; ++index) { | 35 for (size_t index = 0; index < max_length; ++index) { |
| 28 if (string[index] == '\0') { | 36 if (string[index] == '\0') { |
| 29 return index; | 37 return index; |
| 30 } | 38 } |
| 31 } | 39 } |
| 32 | 40 |
| 33 return max_length; | 41 return max_length; |
| 34 } | 42 } |
| 35 #endif | 43 #endif |
| 36 | 44 |
| 37 } // namespace crashpad | 45 } // namespace crashpad |
| OLD | NEW |