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/mac/xattr.h" | 15 #include "util/mac/xattr.h" |
16 | 16 |
17 #include <errno.h> | |
17 #include <stdint.h> | 18 #include <stdint.h> |
18 #include <sys/xattr.h> | 19 #include <sys/xattr.h> |
19 | 20 |
20 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
21 #include "base/logging.h" | 22 #include "base/logging.h" |
22 #include "base/numerics/safe_conversions.h" | 23 #include "base/numerics/safe_conversions.h" |
23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
25 | 26 |
26 namespace crashpad { | 27 namespace crashpad { |
27 | 28 |
29 bool HasXattr(const base::FilePath& file, const base::StringPiece& name) { | |
30 if (getxattr(file.value().c_str(), name.data(), nullptr, 0, 0, 0) < 0) { | |
Mark Mentovai
2015/01/08 22:38:10
Especially since you just wind up calling getxattr
| |
31 PLOG_IF(ERROR, errno != ENOATTR) | |
32 << "getxattr exists " << name << " on file " << file.value(); | |
33 return false; | |
34 } | |
35 return true; | |
36 } | |
37 | |
28 bool ReadXattr(const base::FilePath& file, | 38 bool ReadXattr(const base::FilePath& file, |
29 const base::StringPiece& name, | 39 const base::StringPiece& name, |
30 std::string* value) { | 40 std::string* value) { |
31 // First get the size of the attribute value. | 41 // First get the size of the attribute value. |
32 ssize_t buffer_size = getxattr(file.value().c_str(), name.data(), nullptr, | 42 ssize_t buffer_size = getxattr(file.value().c_str(), name.data(), nullptr, |
33 0, 0, 0); | 43 0, 0, 0); |
34 if (buffer_size < 0) { | 44 if (buffer_size < 0) { |
35 PLOG(ERROR) << "getxattr size " << name << " on file " << file.value(); | 45 PLOG(ERROR) << "getxattr size " << name << " on file " << file.value(); |
36 return false; | 46 return false; |
37 } | 47 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 } | 143 } |
134 | 144 |
135 bool WriteXattrTimeT(const base::FilePath& file, | 145 bool WriteXattrTimeT(const base::FilePath& file, |
136 const base::StringPiece& name, | 146 const base::StringPiece& name, |
137 time_t value) { | 147 time_t value) { |
138 std::string tmp = base::StringPrintf("%ld", value); | 148 std::string tmp = base::StringPrintf("%ld", value); |
139 return WriteXattr(file, name, tmp); | 149 return WriteXattr(file, name, tmp); |
140 } | 150 } |
141 | 151 |
142 } // namespace crashpad | 152 } // namespace crashpad |
OLD | NEW |