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 #ifndef CRASHPAD_UTIL_MAC_XATTR_H_ | 15 #ifndef CRASHPAD_UTIL_MAC_XATTR_H_ |
| 16 #define CRASHPAD_UTIL_MAC_XATTR_H_ | 16 #define CRASHPAD_UTIL_MAC_XATTR_H_ |
| 17 | 17 |
| 18 #include <time.h> | 18 #include <time.h> |
| 19 | 19 |
| 20 #include <string> | 20 #include <string> |
| 21 | 21 |
| 22 #include "base/files/file_path.h" | 22 #include "base/files/file_path.h" |
| 23 #include "base/strings/string_piece.h" | 23 #include "base/strings/string_piece.h" |
| 24 | 24 |
| 25 namespace crashpad { | 25 namespace crashpad { |
| 26 | 26 |
| 27 //! \brief The result code for an ReadXattr or WriteXattr operation. | |
|
Mark Mentovai
2015/01/09 17:52:35
I don’t think you need to use these for WriteXattr
Robert Sesek
2015/01/09 17:59:40
Done.
| |
| 28 enum class XattrStatus { | |
|
Mark Mentovai
2015/01/09 17:52:35
Our second one of these. Nice!
Robert Sesek
2015/01/09 17:59:40
Third, actually :)
| |
| 29 //! \brief No error occured. No message is logged. | |
| 30 kOK = 0, | |
| 31 //! \brief The attribute does not exist. No message is logged. | |
|
Mark Mentovai
2015/01/09 17:52:35
Space these out with blanks.
Robert Sesek
2015/01/09 17:59:40
Done.
| |
| 32 kNoAttribute, | |
| 33 //! \brief An error occurred and an error message was logged. | |
| 34 kOtherError, | |
| 35 }; | |
| 36 | |
| 27 //! \brief Reads an extended attribute on a file. | 37 //! \brief Reads an extended attribute on a file. |
| 28 //! | 38 //! |
| 29 //! \param[in] file The path to the file. | 39 //! \param[in] file The path to the file. |
| 30 //! \param[in] name The name of the extended attribute to read. | 40 //! \param[in] name The name of the extended attribute to read. |
| 31 //! \param[out] value The value of the attribute. | 41 //! \param[out] value The value of the attribute. |
| 32 //! | 42 //! |
| 33 //! \return `true` if the read was successful, with \a value filled in. `false` | 43 //! \return XattrStatus |
| 34 //! on error, with a message logged. | 44 XattrStatus ReadXattr(const base::FilePath& file, |
| 35 bool ReadXattr(const base::FilePath& file, | 45 const base::StringPiece& name, |
| 36 const base::StringPiece& name, | 46 std::string* value); |
| 37 std::string* value); | |
| 38 | 47 |
| 39 //! \brief Writes an extended attribute on a file. | 48 //! \brief Writes an extended attribute on a file. |
| 40 //! | 49 //! |
| 41 //! \param[in] file The path to the file. | 50 //! \param[in] file The path to the file. |
| 42 //! \param[in] name The name of the extended attribute to write. | 51 //! \param[in] name The name of the extended attribute to write. |
| 43 //! \param[in] value The value of the attribute. | 52 //! \param[in] value The value of the attribute. |
| 44 //! | 53 //! |
| 45 //! \return `true` if the write was successful. `false` on error, with a message | 54 //! \return XattrStatus |
| 46 //! logged. | 55 XattrStatus WriteXattr(const base::FilePath& file, |
| 47 bool WriteXattr(const base::FilePath& file, | 56 const base::StringPiece& name, |
| 48 const base::StringPiece& name, | 57 const std::string& value); |
| 49 const std::string& value); | |
| 50 | 58 |
| 51 //! \copydoc ReadXattr | 59 //! \copydoc ReadXattr |
| 52 //! | 60 //! |
| 53 //! Only the values `"0"` and `"1"`, for `false` and `true` respectively, are | 61 //! Only the values `"0"` and `"1"`, for `false` and `true` respectively, are |
| 54 //! valid conversions. | 62 //! valid conversions. |
| 55 bool ReadXattrBool(const base::FilePath& file, | 63 XattrStatus ReadXattrBool(const base::FilePath& file, |
| 56 const base::StringPiece& name, | 64 const base::StringPiece& name, |
| 57 bool* value); | 65 bool* value); |
| 58 | 66 |
| 59 //! \copydoc WriteXattr | 67 //! \copydoc WriteXattr |
| 60 bool WriteXattrBool(const base::FilePath& file, | 68 XattrStatus WriteXattrBool(const base::FilePath& file, |
| 61 const base::StringPiece& name, | 69 const base::StringPiece& name, |
| 62 bool value); | 70 bool value); |
| 63 | 71 |
| 64 //! \copydoc ReadXattr | 72 //! \copydoc ReadXattr |
| 65 bool ReadXattrInt(const base::FilePath& file, | 73 XattrStatus ReadXattrInt(const base::FilePath& file, |
| 66 const base::StringPiece& name, | 74 const base::StringPiece& name, |
| 67 int* value); | 75 int* value); |
| 68 | 76 |
| 69 //! \copydoc WriteXattr | 77 //! \copydoc WriteXattr |
| 70 bool WriteXattrInt(const base::FilePath& file, | 78 XattrStatus WriteXattrInt(const base::FilePath& file, |
| 71 const base::StringPiece& name, | 79 const base::StringPiece& name, |
| 72 int value); | 80 int value); |
| 73 | 81 |
| 74 //! \copydoc ReadXattr | 82 //! \copydoc ReadXattr |
| 75 bool ReadXattrTimeT(const base::FilePath& file, | 83 XattrStatus ReadXattrTimeT(const base::FilePath& file, |
| 76 const base::StringPiece& name, | 84 const base::StringPiece& name, |
| 77 time_t* value); | 85 time_t* value); |
| 78 | 86 |
| 79 //! \copydoc WriteXattr | 87 //! \copydoc WriteXattr |
| 80 bool WriteXattrTimeT(const base::FilePath& file, | 88 XattrStatus WriteXattrTimeT(const base::FilePath& file, |
| 81 const base::StringPiece& name, | 89 const base::StringPiece& name, |
| 82 time_t value); | 90 time_t value); |
| 83 | 91 |
| 84 } // namespace crashpad | 92 } // namespace crashpad |
| 85 | 93 |
| 86 #endif // CRASHPAD_UTIL_MAC_XATTR_H_ | 94 #endif // CRASHPAD_UTIL_MAC_XATTR_H_ |
| OLD | NEW |