| 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/files/file_path.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/numerics/safe_conversions.h" | 19 #include "base/numerics/safe_conversions.h" |
| 20 #include "base/strings/utf_string_conversions.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 bool IsSocketHandle(HANDLE file) { | 24 bool IsSocketHandle(HANDLE file) { |
| 24 if (GetFileType(file) == FILE_TYPE_PIPE) { | 25 if (GetFileType(file) == FILE_TYPE_PIPE) { |
| 25 // FILE_TYPE_PIPE means that it's a socket, a named pipe, or an anonymous | 26 // FILE_TYPE_PIPE means that it's a socket, a named pipe, or an anonymous |
| 26 // pipe. If we are unable to retrieve the pipe information, we know it's a | 27 // pipe. If we are unable to retrieve the pipe information, we know it's a |
| 27 // socket. | 28 // socket. |
| 28 return !GetNamedPipeInfo(file, NULL, NULL, NULL, NULL); | 29 return !GetNamedPipeInfo(file, NULL, NULL, NULL, NULL); |
| 29 } | 30 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 52 disposition = CREATE_NEW; | 53 disposition = CREATE_NEW; |
| 53 break; | 54 break; |
| 54 } | 55 } |
| 55 HANDLE file = CreateFile(path.value().c_str(), | 56 HANDLE file = CreateFile(path.value().c_str(), |
| 56 access, | 57 access, |
| 57 FILE_SHARE_READ | FILE_SHARE_WRITE, | 58 FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 58 nullptr, | 59 nullptr, |
| 59 disposition, | 60 disposition, |
| 60 FILE_ATTRIBUTE_NORMAL, | 61 FILE_ATTRIBUTE_NORMAL, |
| 61 nullptr); | 62 nullptr); |
| 62 PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile " | 63 PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) |
| 63 << path.value().c_str(); | 64 << "CreateFile " << base::UTF16ToUTF8(path.value()); |
| 64 return file; | 65 return file; |
| 65 } | 66 } |
| 66 | 67 |
| 67 } // namespace | 68 } // namespace |
| 68 | 69 |
| 69 // TODO(scottmg): Handle > DWORD sized writes if necessary. | 70 // TODO(scottmg): Handle > DWORD sized writes if necessary. |
| 70 | 71 |
| 71 ssize_t ReadFile(FileHandle file, void* buffer, size_t size) { | 72 ssize_t ReadFile(FileHandle file, void* buffer, size_t size) { |
| 72 DCHECK(!IsSocketHandle(file)); | 73 DCHECK(!IsSocketHandle(file)); |
| 73 DWORD size_dword = base::checked_cast<DWORD>(size); | 74 DWORD size_dword = base::checked_cast<DWORD>(size); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 113 } |
| 113 | 114 |
| 114 FileHandle LoggingOpenFileForRead(const base::FilePath& path) { | 115 FileHandle LoggingOpenFileForRead(const base::FilePath& path) { |
| 115 HANDLE file = CreateFile(path.value().c_str(), | 116 HANDLE file = CreateFile(path.value().c_str(), |
| 116 GENERIC_READ, | 117 GENERIC_READ, |
| 117 FILE_SHARE_READ | FILE_SHARE_WRITE, | 118 FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 118 nullptr, | 119 nullptr, |
| 119 OPEN_EXISTING, | 120 OPEN_EXISTING, |
| 120 0, | 121 0, |
| 121 nullptr); | 122 nullptr); |
| 122 PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile " | 123 PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) |
| 123 << path.value().c_str(); | 124 << "CreateFile " << base::UTF16ToUTF8(path.value()); |
| 124 return file; | 125 return file; |
| 125 } | 126 } |
| 126 | 127 |
| 127 FileHandle LoggingOpenFileForWrite(const base::FilePath& path, | 128 FileHandle LoggingOpenFileForWrite(const base::FilePath& path, |
| 128 FileWriteMode mode, | 129 FileWriteMode mode, |
| 129 FilePermissions permissions) { | 130 FilePermissions permissions) { |
| 130 return LoggingOpenFileForOutput(GENERIC_WRITE, path, mode, permissions); | 131 return LoggingOpenFileForOutput(GENERIC_WRITE, path, mode, permissions); |
| 131 } | 132 } |
| 132 | 133 |
| 133 FileHandle LoggingOpenFileForReadAndWrite(const base::FilePath& path, | 134 FileHandle LoggingOpenFileForReadAndWrite(const base::FilePath& path, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return true; | 203 return true; |
| 203 } | 204 } |
| 204 | 205 |
| 205 bool LoggingCloseFile(FileHandle file) { | 206 bool LoggingCloseFile(FileHandle file) { |
| 206 BOOL rv = CloseHandle(file); | 207 BOOL rv = CloseHandle(file); |
| 207 PLOG_IF(ERROR, !rv) << "CloseHandle"; | 208 PLOG_IF(ERROR, !rv) << "CloseHandle"; |
| 208 return rv; | 209 return rv; |
| 209 } | 210 } |
| 210 | 211 |
| 211 } // namespace crashpad | 212 } // namespace crashpad |
| OLD | NEW |