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/file/file_writer.h" | 15 #include "util/file/file_writer.h" |
16 | 16 |
17 #include <algorithm> | 17 #include <algorithm> |
18 | 18 |
19 #include <limits.h> | 19 #include <limits.h> |
20 | 20 |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/posix/eintr_wrapper.h" | 22 #include "base/posix/eintr_wrapper.h" |
23 #include "util/file/fd_io.h" | 23 #include "util/file/file_io.h" |
24 | 24 |
25 namespace crashpad { | 25 namespace crashpad { |
26 | 26 |
27 // Ensure type compatibility between WritableIoVec and iovec. | 27 // Ensure type compatibility between WritableIoVec and iovec. |
28 static_assert(sizeof(WritableIoVec) == sizeof(iovec), "WritableIoVec size"); | 28 static_assert(sizeof(WritableIoVec) == sizeof(iovec), "WritableIoVec size"); |
29 static_assert(offsetof(WritableIoVec, iov_base) == offsetof(iovec, iov_base), | 29 static_assert(offsetof(WritableIoVec, iov_base) == offsetof(iovec, iov_base), |
30 "WritableIoVec base offset"); | 30 "WritableIoVec base offset"); |
31 static_assert(offsetof(WritableIoVec, iov_len) == offsetof(iovec, iov_len), | 31 static_assert(offsetof(WritableIoVec, iov_len) == offsetof(iovec, iov_len), |
32 "WritableIoVec len offset"); | 32 "WritableIoVec len offset"); |
33 | 33 |
(...skipping 20 matching lines...) Expand all Loading... |
54 void FileWriter::Close() { | 54 void FileWriter::Close() { |
55 CHECK(fd_.is_valid()); | 55 CHECK(fd_.is_valid()); |
56 | 56 |
57 fd_.reset(); | 57 fd_.reset(); |
58 } | 58 } |
59 | 59 |
60 bool FileWriter::Write(const void* data, size_t size) { | 60 bool FileWriter::Write(const void* data, size_t size) { |
61 DCHECK(fd_.is_valid()); | 61 DCHECK(fd_.is_valid()); |
62 | 62 |
63 // TODO(mark): Write no more than SSIZE_MAX bytes in a single call. | 63 // TODO(mark): Write no more than SSIZE_MAX bytes in a single call. |
64 ssize_t written = WriteFD(fd_.get(), data, size); | 64 ssize_t written = WriteFile(fd_.get(), data, size); |
65 if (written < 0) { | 65 if (written < 0) { |
66 PLOG(ERROR) << "write"; | 66 PLOG(ERROR) << "write"; |
67 return false; | 67 return false; |
68 } else if (written == 0) { | 68 } else if (written == 0) { |
69 LOG(ERROR) << "write: returned 0"; | 69 LOG(ERROR) << "write: returned 0"; |
70 return false; | 70 return false; |
71 } | 71 } |
72 | 72 |
73 return true; | 73 return true; |
74 } | 74 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 off_t rv = lseek(fd_.get(), offset, whence); | 143 off_t rv = lseek(fd_.get(), offset, whence); |
144 if (rv < 0) { | 144 if (rv < 0) { |
145 PLOG(ERROR) << "lseek"; | 145 PLOG(ERROR) << "lseek"; |
146 } | 146 } |
147 | 147 |
148 return rv; | 148 return rv; |
149 } | 149 } |
150 | 150 |
151 } // namespace crashpad | 151 } // namespace crashpad |
OLD | NEW |