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_MINIDUMP_MINIDUMP_WRITER_UTIL_H_ |
| 16 #define CRASHPAD_MINIDUMP_MINIDUMP_WRITER_UTIL_H_ |
| 17 |
| 18 #include <stdint.h> |
| 19 #include <sys/types.h> |
| 20 #include <time.h> |
| 21 |
| 22 #include <string> |
| 23 |
| 24 #include "base/basictypes.h" |
| 25 #include "base/strings/string16.h" |
| 26 |
| 27 namespace crashpad { |
| 28 namespace internal { |
| 29 |
| 30 //! \brief A collection of utility functions used by the MinidumpWritable family |
| 31 //! of classes. |
| 32 class MinidumpWriterUtil final { |
| 33 public: |
| 34 //! \brief Assigns a `time_t` value, logging a warning if the result overflows |
| 35 //! the destination buffer and will be truncated. |
| 36 //! |
| 37 //! \param[out] destination A pointer to the variable to be assigned to. |
| 38 //! \param[in] source The value to assign. |
| 39 //! |
| 40 //! The minidump format uses `uint32_t` for many timestamp values, but |
| 41 //! `time_t` may be wider than this. These year 2038 bugs are a limitation of |
| 42 //! the minidump format. An out-of-range error will be noted with a warning, |
| 43 //! but is not considered fatal. \a source will be truncated and assigned to |
| 44 //! \a destination in this case. |
| 45 //! |
| 46 //! For `time_t` values with nonfatal overflow semantics, this function is |
| 47 //! used in preference to AssignIfInRange(), which fails without performing an |
| 48 //! assignment when an out-of-range condition is detected. |
| 49 static void AssignTimeT(uint32_t* destination, time_t source); |
| 50 |
| 51 //! \brief Converts a UTF-8 string to UTF-16 and returns it. If the string |
| 52 //! cannot be converted losslessly, indicating that the input is not |
| 53 //! well-formed UTF-8, a warning is logged. |
| 54 //! |
| 55 //! \param[in] utf8 The UTF-8-encoded string to convert. |
| 56 //! |
| 57 //! \return The \a utf8 string, converted to UTF-16 encoding. If the |
| 58 //! conversion is lossy, U+FFFD “replacement characters” will be |
| 59 //! introduced. |
| 60 static string16 ConvertUTF8ToUTF16(const std::string& utf8); |
| 61 |
| 62 //! \brief Converts a UTF-8 string to UTF-16 and places it into a buffer of |
| 63 //! fixed size, taking care to `NUL`-terminate the buffer and not to |
| 64 //! overflow it. If the string will be truncated or if it cannot be |
| 65 //! converted losslessly, a warning is logged. |
| 66 //! |
| 67 //! Any unused portion of the \a destination buffer that is not written to by |
| 68 //! the converted string will be overwritten with `NUL` UTF-16 code units, |
| 69 //! thus, this function always writes \a destination_size `char16` units. |
| 70 //! |
| 71 //! If the conversion is lossy, U+FFFD “replacement characters” will be |
| 72 //! introduced. |
| 73 //! |
| 74 //! \param[out] destination A pointer to the destination buffer, where the |
| 75 //! UTF-16-encoded string will be written. |
| 76 //! \param[in] destination_size The size of \a destination in `char16` units, |
| 77 //! including space used by a `NUL` terminator. |
| 78 //! \param[in] source The UTF-8-encoded input string. |
| 79 static void AssignUTF8ToUTF16(char16* destination, |
| 80 size_t destination_size, |
| 81 const std::string& source); |
| 82 |
| 83 private: |
| 84 DISALLOW_IMPLICIT_CONSTRUCTORS(MinidumpWriterUtil); |
| 85 }; |
| 86 |
| 87 } // namespace internal |
| 88 } // namespace crashpad |
| 89 |
| 90 #endif // CRASHPAD_MINIDUMP_MINIDUMP_WRITER_UTIL_H_ |
OLD | NEW |