| 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/files/file_path.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/numerics/safe_conversions.h" | 19 #include "base/numerics/safe_conversions.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 bool IsSocketHandle(HANDLE file) { | 23 bool IsSocketHandle(HANDLE file) { |
| 23 if (GetFileType(file) == FILE_TYPE_PIPE) { | 24 if (GetFileType(file) == FILE_TYPE_PIPE) { |
| 24 // FILE_TYPE_PIPE means that it's a socket, a named pipe, or an anonymous | 25 // FILE_TYPE_PIPE means that it's a socket, a named pipe, or an anonymous |
| 25 // pipe. If we are unable to retrieve the pipe information, we know it's a | 26 // pipe. If we are unable to retrieve the pipe information, we know it's a |
| 26 // socket. | 27 // socket. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // network in the future. | 66 // network in the future. |
| 66 DWORD size_dword = base::checked_cast<DWORD>(size); | 67 DWORD size_dword = base::checked_cast<DWORD>(size); |
| 67 DWORD bytes_written; | 68 DWORD bytes_written; |
| 68 BOOL rv = ::WriteFile(file, buffer, size_dword, &bytes_written, nullptr); | 69 BOOL rv = ::WriteFile(file, buffer, size_dword, &bytes_written, nullptr); |
| 69 if (!rv) | 70 if (!rv) |
| 70 return -1; | 71 return -1; |
| 71 CHECK_EQ(bytes_written, size_dword); | 72 CHECK_EQ(bytes_written, size_dword); |
| 72 return bytes_written; | 73 return bytes_written; |
| 73 } | 74 } |
| 74 | 75 |
| 76 FileHandle LoggingOpenFileForWrite(const base::FilePath& path, uint32_t mode) { |
| 77 HANDLE file = CreateFile(path.value().c_str(), GENERIC_WRITE, 0, nullptr, |
| 78 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 79 PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile " |
| 80 << path.value().c_str(); |
| 81 return file; |
| 82 } |
| 83 |
| 84 FileHandle LoggingOpenFileForRead(const base::FilePath& path) { |
| 85 HANDLE file = CreateFile(path.value().c_str(), GENERIC_READ, FILE_SHARE_READ, |
| 86 nullptr, OPEN_EXISTING, 0, nullptr); |
| 87 PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile " |
| 88 << path.value().c_str(); |
| 89 return file; |
| 90 } |
| 91 |
| 75 bool LoggingCloseFile(FileHandle file) { | 92 bool LoggingCloseFile(FileHandle file) { |
| 76 BOOL rv = CloseHandle(file); | 93 BOOL rv = CloseHandle(file); |
| 77 PLOG_IF(ERROR, !rv) << "CloseHandle"; | 94 PLOG_IF(ERROR, !rv) << "CloseHandle"; |
| 78 return rv; | 95 return rv; |
| 79 } | 96 } |
| 80 | 97 |
| 81 } // namespace crashpad | 98 } // namespace crashpad |
| OLD | NEW |