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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 namespace crashpad { | 70 namespace crashpad { |
71 | 71 |
72 namespace { | 72 namespace { |
73 | 73 |
74 FileHandle LoggingOpenFileForOutput(int rdwr_or_wronly, | 74 FileHandle LoggingOpenFileForOutput(int rdwr_or_wronly, |
75 const base::FilePath& path, | 75 const base::FilePath& path, |
76 FileWriteMode mode, | 76 FileWriteMode mode, |
77 FilePermissions permissions) { | 77 FilePermissions permissions) { |
78 int flags = rdwr_or_wronly | O_CREAT; | 78 int flags = rdwr_or_wronly & (O_RDWR | O_WRONLY); |
79 // kReuseOrCreate does not need any additional flags. | 79 DCHECK_NE(flags, 0); |
80 if (mode == FileWriteMode::kTruncateOrCreate) | 80 |
81 flags |= O_TRUNC; | 81 switch (mode) { |
82 else if (mode == FileWriteMode::kCreateOrFail) | 82 case FileWriteMode::kReuseOrFail: |
83 flags |= O_EXCL; | 83 break; |
| 84 case FileWriteMode::kReuseOrCreate: |
| 85 flags |= O_CREAT; |
| 86 break; |
| 87 case FileWriteMode::kTruncateOrCreate: |
| 88 flags |= O_CREAT | O_TRUNC; |
| 89 break; |
| 90 case FileWriteMode::kCreateOrFail: |
| 91 flags |= O_CREAT | O_EXCL; |
| 92 break; |
| 93 } |
84 | 94 |
85 int fd = HANDLE_EINTR( | 95 int fd = HANDLE_EINTR( |
86 open(path.value().c_str(), | 96 open(path.value().c_str(), |
87 flags, | 97 flags, |
88 permissions == FilePermissions::kWorldReadable ? 0644 : 0600)); | 98 permissions == FilePermissions::kWorldReadable ? 0644 : 0600)); |
89 PLOG_IF(ERROR, fd < 0) << "open " << path.value(); | 99 PLOG_IF(ERROR, fd < 0) << "open " << path.value(); |
90 return fd; | 100 return fd; |
91 } | 101 } |
92 | 102 |
93 } // namespace | 103 } // namespace |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 return true; | 155 return true; |
146 } | 156 } |
147 | 157 |
148 bool LoggingCloseFile(FileHandle file) { | 158 bool LoggingCloseFile(FileHandle file) { |
149 int rv = IGNORE_EINTR(close(file)); | 159 int rv = IGNORE_EINTR(close(file)); |
150 PLOG_IF(ERROR, rv != 0) << "close"; | 160 PLOG_IF(ERROR, rv != 0) << "close"; |
151 return rv == 0; | 161 return rv == 0; |
152 } | 162 } |
153 | 163 |
154 } // namespace crashpad | 164 } // namespace crashpad |
OLD | NEW |