| 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, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 0, 0, 0); | 34 0, 0, 0); |
| 35 if (buffer_size < 0) { | 35 if (buffer_size < 0) { |
| 36 if (errno == ENOATTR) | 36 if (errno == ENOATTR) |
| 37 return XattrStatus::kNoAttribute; | 37 return XattrStatus::kNoAttribute; |
| 38 PLOG(ERROR) << "getxattr size " << name << " on file " << file.value(); | 38 PLOG(ERROR) << "getxattr size " << name << " on file " << file.value(); |
| 39 return XattrStatus::kOtherError; | 39 return XattrStatus::kOtherError; |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Resize the buffer and read into it. | 42 // Resize the buffer and read into it. |
| 43 value->resize(buffer_size); | 43 value->resize(buffer_size); |
| 44 ssize_t bytes_read = getxattr(file.value().c_str(), name.data(), | 44 if (!value->empty()) { |
| 45 &(*value)[0], value->size(), | 45 ssize_t bytes_read = getxattr(file.value().c_str(), name.data(), |
| 46 0, 0); | 46 &(*value)[0], value->size(), |
| 47 if (bytes_read < 0) { | 47 0, 0); |
| 48 PLOG(ERROR) << "getxattr " << name << " on file " << file.value(); | 48 if (bytes_read < 0) { |
| 49 return XattrStatus::kOtherError; | 49 PLOG(ERROR) << "getxattr " << name << " on file " << file.value(); |
| 50 return XattrStatus::kOtherError; |
| 51 } |
| 52 DCHECK_EQ(bytes_read, buffer_size); |
| 50 } | 53 } |
| 51 DCHECK_EQ(bytes_read, buffer_size); | |
| 52 | 54 |
| 53 return XattrStatus::kOK; | 55 return XattrStatus::kOK; |
| 54 } | 56 } |
| 55 | 57 |
| 56 bool WriteXattr(const base::FilePath& file, | 58 bool WriteXattr(const base::FilePath& file, |
| 57 const base::StringPiece& name, | 59 const base::StringPiece& name, |
| 58 const std::string& value) { | 60 const std::string& value) { |
| 59 int rv = setxattr(file.value().c_str(), name.data(), value.c_str(), | 61 int rv = setxattr(file.value().c_str(), name.data(), value.c_str(), |
| 60 value.length(), 0, 0); | 62 value.length(), 0, 0); |
| 61 PLOG_IF(ERROR, rv != 0) << "setxattr " << name << " on file " | 63 PLOG_IF(ERROR, rv != 0) << "setxattr " << name << " on file " |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 141 } |
| 140 | 142 |
| 141 bool WriteXattrTimeT(const base::FilePath& file, | 143 bool WriteXattrTimeT(const base::FilePath& file, |
| 142 const base::StringPiece& name, | 144 const base::StringPiece& name, |
| 143 time_t value) { | 145 time_t value) { |
| 144 std::string tmp = base::StringPrintf("%ld", value); | 146 std::string tmp = base::StringPrintf("%ld", value); |
| 145 return WriteXattr(file, name, tmp); | 147 return WriteXattr(file, name, tmp); |
| 146 } | 148 } |
| 147 | 149 |
| 148 } // namespace crashpad | 150 } // namespace crashpad |
| OLD | NEW |