| 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_io.h" | 15 #include "util/file/file_io.h" |
| 16 | 16 |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
| 19 | 19 |
| 20 namespace crashpad { | 20 namespace crashpad { |
| 21 | 21 |
| 22 bool LoggingReadFile(FileHandle file, void* buffer, size_t size) { | 22 bool LoggingReadFile(FileHandle file, void* buffer, size_t size) { |
| 23 ssize_t expect = base::checked_cast<ssize_t>(size); | 23 FileOperationResult expect = base::checked_cast<FileOperationResult>(size); |
| 24 ssize_t rv = ReadFile(file, buffer, size); | 24 FileOperationResult rv = ReadFile(file, buffer, size); |
| 25 if (rv < 0) { | 25 if (rv < 0) { |
| 26 PLOG(ERROR) << "read"; | 26 PLOG(ERROR) << "read"; |
| 27 return false; | 27 return false; |
| 28 } | 28 } |
| 29 if (rv != expect) { | 29 if (rv != expect) { |
| 30 LOG(ERROR) << "read: expected " << expect << ", observed " << rv; | 30 LOG(ERROR) << "read: expected " << expect << ", observed " << rv; |
| 31 return false; | 31 return false; |
| 32 } | 32 } |
| 33 | 33 |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool LoggingWriteFile(FileHandle file, const void* buffer, size_t size) { | 37 bool LoggingWriteFile(FileHandle file, const void* buffer, size_t size) { |
| 38 ssize_t expect = base::checked_cast<ssize_t>(size); | 38 FileOperationResult expect = base::checked_cast<FileOperationResult>(size); |
| 39 ssize_t rv = WriteFile(file, buffer, size); | 39 FileOperationResult rv = WriteFile(file, buffer, size); |
| 40 if (rv < 0) { | 40 if (rv < 0) { |
| 41 PLOG(ERROR) << "write"; | 41 PLOG(ERROR) << "write"; |
| 42 return false; | 42 return false; |
| 43 } | 43 } |
| 44 if (rv != expect) { | 44 if (rv != expect) { |
| 45 LOG(ERROR) << "write: expected " << expect << ", observed " << rv; | 45 LOG(ERROR) << "write: expected " << expect << ", observed " << rv; |
| 46 return false; | 46 return false; |
| 47 } | 47 } |
| 48 | 48 |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void CheckedReadFile(FileHandle file, void* buffer, size_t size) { | 52 void CheckedReadFile(FileHandle file, void* buffer, size_t size) { |
| 53 CHECK(LoggingReadFile(file, buffer, size)); | 53 CHECK(LoggingReadFile(file, buffer, size)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void CheckedWriteFile(FileHandle file, const void* buffer, size_t size) { | 56 void CheckedWriteFile(FileHandle file, const void* buffer, size_t size) { |
| 57 CHECK(LoggingWriteFile(file, buffer, size)); | 57 CHECK(LoggingWriteFile(file, buffer, size)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void CheckedReadFileAtEOF(FileHandle file) { | 60 void CheckedReadFileAtEOF(FileHandle file) { |
| 61 char c; | 61 char c; |
| 62 ssize_t rv = ReadFile(file, &c, 1); | 62 FileOperationResult rv = ReadFile(file, &c, 1); |
| 63 if (rv < 0) { | 63 if (rv < 0) { |
| 64 PCHECK(rv == 0) << "read"; | 64 PCHECK(rv == 0) << "read"; |
| 65 } else { | 65 } else { |
| 66 CHECK_EQ(rv, 0) << "read"; | 66 CHECK_EQ(rv, 0) << "read"; |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 void CheckedCloseFile(FileHandle file) { | 70 void CheckedCloseFile(FileHandle file) { |
| 71 CHECK(LoggingCloseFile(file)); | 71 CHECK(LoggingCloseFile(file)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace crashpad | 74 } // namespace crashpad |
| OLD | NEW |