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 10 matching lines...) Expand all Loading... |
21 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
22 #include "base/logging.h" | 22 #include "base/logging.h" |
23 #include "base/numerics/safe_conversions.h" | 23 #include "base/numerics/safe_conversions.h" |
24 #include "base/posix/eintr_wrapper.h" | 24 #include "base/posix/eintr_wrapper.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 struct ReadTraits { | 28 struct ReadTraits { |
29 using VoidBufferType = void*; | 29 using VoidBufferType = void*; |
30 using CharBufferType = char*; | 30 using CharBufferType = char*; |
31 static FileOperationResult Operate(int fd, | 31 static crashpad::FileOperationResult Operate(int fd, |
32 CharBufferType buffer, | 32 CharBufferType buffer, |
33 size_t size) { | 33 size_t size) { |
34 return read(fd, buffer, size); | 34 return read(fd, buffer, size); |
35 } | 35 } |
36 }; | 36 }; |
37 | 37 |
38 struct WriteTraits { | 38 struct WriteTraits { |
39 using VoidBufferType = const void*; | 39 using VoidBufferType = const void*; |
40 using CharBufferType = const char*; | 40 using CharBufferType = const char*; |
41 static FileOperationResult Operate(int fd, | 41 static crashpad::FileOperationResult Operate(int fd, |
42 CharBufferType buffer, | 42 CharBufferType buffer, |
43 size_t size) { | 43 size_t size) { |
44 return write(fd, buffer, size); | 44 return write(fd, buffer, size); |
45 } | 45 } |
46 }; | 46 }; |
47 | 47 |
48 template <typename Traits> | 48 template <typename Traits> |
49 FileOperationResult ReadOrWrite(int fd, | 49 crashpad::FileOperationResult |
50 typename Traits::VoidBufferType buffer, | 50 ReadOrWrite(int fd, typename Traits::VoidBufferType buffer, size_t size) { |
51 size_t size) { | |
52 typename Traits::CharBufferType buffer_c = | 51 typename Traits::CharBufferType buffer_c = |
53 reinterpret_cast<typename Traits::CharBufferType>(buffer); | 52 reinterpret_cast<typename Traits::CharBufferType>(buffer); |
54 | 53 |
55 FileOperationResult total_bytes = 0; | 54 crashpad::FileOperationResult total_bytes = 0; |
56 while (size > 0) { | 55 while (size > 0) { |
57 FileOperationResult bytes = | 56 crashpad::FileOperationResult bytes = |
58 HANDLE_EINTR(Traits::Operate(fd, buffer_c, size)); | 57 HANDLE_EINTR(Traits::Operate(fd, buffer_c, size)); |
59 if (bytes < 0) { | 58 if (bytes < 0) { |
60 return bytes; | 59 return bytes; |
61 } else if (bytes == 0) { | 60 } else if (bytes == 0) { |
62 break; | 61 break; |
63 } | 62 } |
64 | 63 |
65 buffer_c += bytes; | 64 buffer_c += bytes; |
66 size -= bytes; | 65 size -= bytes; |
67 total_bytes += bytes; | 66 total_bytes += bytes; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 return true; | 181 return true; |
183 } | 182 } |
184 | 183 |
185 bool LoggingCloseFile(FileHandle file) { | 184 bool LoggingCloseFile(FileHandle file) { |
186 int rv = IGNORE_EINTR(close(file)); | 185 int rv = IGNORE_EINTR(close(file)); |
187 PLOG_IF(ERROR, rv != 0) << "close"; | 186 PLOG_IF(ERROR, rv != 0) << "close"; |
188 return rv == 0; | 187 return rv == 0; |
189 } | 188 } |
190 | 189 |
191 } // namespace crashpad | 190 } // namespace crashpad |
OLD | NEW |