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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 namespace crashpad { | 67 namespace crashpad { |
68 | 68 |
69 ssize_t ReadFD(int fd, void* buffer, size_t size) { | 69 ssize_t ReadFD(int fd, void* buffer, size_t size) { |
70 return ReadOrWrite<ReadTraits>(fd, buffer, size); | 70 return ReadOrWrite<ReadTraits>(fd, buffer, size); |
71 } | 71 } |
72 | 72 |
73 ssize_t WriteFD(int fd, const void* buffer, size_t size) { | 73 ssize_t WriteFD(int fd, const void* buffer, size_t size) { |
74 return ReadOrWrite<WriteTraits>(fd, buffer, size); | 74 return ReadOrWrite<WriteTraits>(fd, buffer, size); |
75 } | 75 } |
76 | 76 |
77 void CheckedReadFD(int fd, void* buffer, size_t size) { | 77 bool LoggingReadFD(int fd, void* buffer, size_t size) { |
78 ssize_t expect = base::checked_cast<ssize_t>(size); | 78 ssize_t expect = base::checked_cast<ssize_t>(size); |
79 ssize_t rv = ReadFD(fd, buffer, size); | 79 ssize_t rv = ReadFD(fd, buffer, size); |
80 if (rv < 0) { | 80 if (rv < 0) { |
81 PCHECK(rv == expect) << "read"; | 81 PLOG(ERROR) << "read"; |
82 } else { | 82 return false; |
83 CHECK_EQ(rv, expect) << "read"; | |
84 } | 83 } |
| 84 if (rv != expect) { |
| 85 LOG(ERROR) << "read: expected " << expect << ", observed " << rv; |
| 86 return false; |
| 87 } |
| 88 |
| 89 return true; |
| 90 } |
| 91 |
| 92 bool LoggingWriteFD(int fd, const void* buffer, size_t size) { |
| 93 ssize_t expect = base::checked_cast<ssize_t>(size); |
| 94 ssize_t rv = WriteFD(fd, buffer, size); |
| 95 if (rv < 0) { |
| 96 PLOG(ERROR) << "write"; |
| 97 return false; |
| 98 } |
| 99 if (rv != expect) { |
| 100 LOG(ERROR) << "write: expected " << expect << ", observed " << rv; |
| 101 return false; |
| 102 } |
| 103 |
| 104 return true; |
| 105 } |
| 106 |
| 107 void CheckedReadFD(int fd, void* buffer, size_t size) { |
| 108 CHECK(LoggingReadFD(fd, buffer, size)); |
85 } | 109 } |
86 | 110 |
87 void CheckedWriteFD(int fd, const void* buffer, size_t size) { | 111 void CheckedWriteFD(int fd, const void* buffer, size_t size) { |
88 ssize_t expect = base::checked_cast<ssize_t>(size); | 112 CHECK(LoggingWriteFD(fd, buffer, size)); |
89 ssize_t rv = WriteFD(fd, buffer, size); | |
90 if (rv < 0) { | |
91 PCHECK(rv == expect) << "write"; | |
92 } else { | |
93 CHECK_EQ(rv, expect) << "write"; | |
94 } | |
95 } | 113 } |
96 | 114 |
97 void CheckedReadFDAtEOF(int fd) { | 115 void CheckedReadFDAtEOF(int fd) { |
98 char c; | 116 char c; |
99 ssize_t rv = ReadFD(fd, &c, 1); | 117 ssize_t rv = ReadFD(fd, &c, 1); |
100 if (rv < 0) { | 118 if (rv < 0) { |
101 PCHECK(rv == 0) << "read"; | 119 PCHECK(rv == 0) << "read"; |
102 } else { | 120 } else { |
103 CHECK_EQ(rv, 0) << "read"; | 121 CHECK_EQ(rv, 0) << "read"; |
104 } | 122 } |
105 } | 123 } |
106 | 124 |
107 bool LoggingCloseFD(int fd) { | 125 bool LoggingCloseFD(int fd) { |
108 int rv = IGNORE_EINTR(close(fd)); | 126 int rv = IGNORE_EINTR(close(fd)); |
109 PLOG_IF(ERROR, rv != 0) << "close"; | 127 PLOG_IF(ERROR, rv != 0) << "close"; |
110 return rv == 0; | 128 return rv == 0; |
111 } | 129 } |
112 | 130 |
| 131 void CheckedCloseFD(int fd) { |
| 132 CHECK(LoggingCloseFD(fd)); |
| 133 } |
| 134 |
113 } // namespace crashpad | 135 } // namespace crashpad |
OLD | NEW |