| 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/fd_io.h" | 15 #include "util/file/fd_io.h" |
| 16 | 16 |
| 17 #include <unistd.h> | 17 #include <unistd.h> |
| 18 | 18 |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/numerics/safe_conversions.h" | 20 #include "base/numerics/safe_conversions.h" |
| 21 #include "base/posix/eintr_wrapper.h" | 21 #include "base/posix/eintr_wrapper.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 struct ReadTraits { | 25 struct ReadTraits { |
| 26 typedef void* VoidBufferType; | 26 using VoidBufferType = void*; |
| 27 typedef char* CharBufferType; | 27 using CharBufferType = char*; |
| 28 static ssize_t Operate(int fd, CharBufferType buffer, size_t size) { | 28 static ssize_t Operate(int fd, CharBufferType buffer, size_t size) { |
| 29 return read(fd, buffer, size); | 29 return read(fd, buffer, size); |
| 30 } | 30 } |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 struct WriteTraits { | 33 struct WriteTraits { |
| 34 typedef const void* VoidBufferType; | 34 using VoidBufferType = const void*; |
| 35 typedef const char* CharBufferType; | 35 using CharBufferType = const char*; |
| 36 static ssize_t Operate(int fd, CharBufferType buffer, size_t size) { | 36 static ssize_t Operate(int fd, CharBufferType buffer, size_t size) { |
| 37 return write(fd, buffer, size); | 37 return write(fd, buffer, size); |
| 38 } | 38 } |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 template <typename Traits> | 41 template <typename Traits> |
| 42 ssize_t ReadOrWrite(int fd, | 42 ssize_t ReadOrWrite(int fd, |
| 43 typename Traits::VoidBufferType buffer, | 43 typename Traits::VoidBufferType buffer, |
| 44 size_t size) { | 44 size_t size) { |
| 45 typename Traits::CharBufferType buffer_c = | 45 typename Traits::CharBufferType buffer_c = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool LoggingCloseFD(int fd) { | 107 bool LoggingCloseFD(int fd) { |
| 108 int rv = IGNORE_EINTR(close(fd)); | 108 int rv = IGNORE_EINTR(close(fd)); |
| 109 PLOG_IF(ERROR, rv != 0) << "close"; | 109 PLOG_IF(ERROR, rv != 0) << "close"; |
| 110 return rv == 0; | 110 return rv == 0; |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace crashpad | 113 } // namespace crashpad |
| OLD | NEW |