OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (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 |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #ifndef CRASHPAD_UTIL_STDLIB_STRLCPY_H_ |
| 16 #define CRASHPAD_UTIL_STDLIB_STRLCPY_H_ |
| 17 |
| 18 #include <stdint.h> |
| 19 |
| 20 #include "base/strings/string16.h" |
| 21 |
| 22 namespace crashpad { |
| 23 |
| 24 //! \brief Copy a `NUL`-terminated char16-based string to a fixed-size buffer. |
| 25 //! |
| 26 //! This function behaves identically to `strlcpy()`, but it operates on char16 |
| 27 //! data instead of `char` data. It copies the `NUL`-terminated string in the |
| 28 //! buffer beginning at \a source to the buffer of size \a length at \a |
| 29 //! destination, ensuring that the destination buffer is `NUL`-terminated. No |
| 30 //! data will be written outside of the \a destination buffer, but if \a length |
| 31 //! is smaller than the length of the string at \a source, the string will be |
| 32 //! truncated. |
| 33 //! |
| 34 //! \param[out] destination A pointer to a buffer of at least size \a length |
| 35 //! char16 units (not bytes). The string will be copied to this buffer, |
| 36 //! possibly with truncation, and `NUL`-terminated. Nothing will be written |
| 37 //! following the `NUL` terminator. |
| 38 //! \param[in] source A pointer to a `NUL`-terminated string of char16 data. The |
| 39 //! `NUL` terminator must be a `NUL` value in a char16 unit, not just a |
| 40 //! single `NUL` byte. |
| 41 //! \param[in] length The length of the \a destination buffer in char16 units, |
| 42 //! not bytes. A maximum of \a `length - 1` char16 units from \a source will |
| 43 //! be copied to \a destination. |
| 44 //! |
| 45 //! \return The length of the \a source string in char16 units, not including |
| 46 //! its `NUL` terminator. When truncation occurs, the return value will be |
| 47 //! equal to or greater than than the \a length parameter. |
| 48 size_t c16lcpy(char16* destination, const char16* source, size_t length); |
| 49 |
| 50 } // namespace crashpad |
| 51 |
| 52 #endif // CRASHPAD_UTIL_STDLIB_STRLCPY_H_ |
OLD | NEW |