Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: util/file/file_io.h

Issue 999953002: Use LockFile/UnlockFile for Settings to port to Windows (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@lock-fileio-2
Patch Set: Tag inside, no info spam Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/settings_test.cc ('k') | util/file/file_io_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 //! reading. Logs an error if the operation fails. 181 //! reading. Logs an error if the operation fails.
182 //! 182 //!
183 //! \return The newly opened FileHandle, or an invalid FileHandle on failure. 183 //! \return The newly opened FileHandle, or an invalid FileHandle on failure.
184 //! 184 //!
185 //! \sa ScopedFileHandle 185 //! \sa ScopedFileHandle
186 FileHandle LoggingOpenFileForRead(const base::FilePath& path); 186 FileHandle LoggingOpenFileForRead(const base::FilePath& path);
187 187
188 //! \brief Wraps `open()` or `CreateFile()`, creating a file for output. Logs 188 //! \brief Wraps `open()` or `CreateFile()`, creating a file for output. Logs
189 //! an error if the operation fails. 189 //! an error if the operation fails.
190 //! 190 //!
191 //! \a write_mode determines the style (truncate, reuse, etc.) that is used to 191 //! \a mode determines the style (truncate, reuse, etc.) that is used to open
192 //! open the file. On POSIX, \a permissions determines the value that is passed 192 //! the file. On POSIX, \a permissions determines the value that is passed as
193 //! as `mode` to `open()`. On Windows, the file is always opened in binary mode 193 //! `mode` to `open()`. On Windows, the file is always opened in binary mode
194 //! (that is, no CRLF translation). On Windows, the file is opened for sharing, 194 //! (that is, no CRLF translation). On Windows, the file is opened for sharing,
195 //! see LoggingLockFile() and LoggingUnlockFile() to control concurrent access. 195 //! see LoggingLockFile() and LoggingUnlockFile() to control concurrent access.
196 //! 196 //!
197 //! \return The newly opened FileHandle, or an invalid FileHandle on failure. 197 //! \return The newly opened FileHandle, or an invalid FileHandle on failure.
198 //! 198 //!
199 //! \sa FileWriteMode 199 //! \sa FileWriteMode
200 //! \sa FilePermissions 200 //! \sa FilePermissions
201 //! \sa ScopedFileHandle 201 //! \sa ScopedFileHandle
202 FileHandle LoggingOpenFileForWrite(const base::FilePath& path, 202 FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
203 FileWriteMode write_mode, 203 FileWriteMode mode,
204 FilePermissions permissions); 204 FilePermissions permissions);
205 205
206 //! \brief Wraps `open()` or `CreateFile()`, creating a file for both input and
207 //! output. Logs an error if the operation fails.
208 //!
209 //! \a mode determines the style (truncate, reuse, etc.) that is used to open
210 //! the file. On POSIX, \a permissions determines the value that is passed as
211 //! `mode` to `open()`. On Windows, the file is always opened in binary mode
212 //! (that is, no CRLF translation). On Windows, the file is opened for sharing,
213 //! see LoggingLockFile() and LoggingUnlockFile() to control concurrent access.
214 //!
215 //! \return The newly opened FileHandle, or an invalid FileHandle on failure.
216 //!
217 //! \sa FileWriteMode
218 //! \sa FilePermissions
219 //! \sa ScopedFileHandle
220 FileHandle LoggingOpenFileForReadAndWrite(const base::FilePath& path,
221 FileWriteMode mode,
222 FilePermissions permissions);
223
206 //! \brief Locks the given \a file using `flock()` on POSIX or `LockFileEx()` on 224 //! \brief Locks the given \a file using `flock()` on POSIX or `LockFileEx()` on
207 //! Windows. 225 //! Windows.
208 //! 226 //!
209 //! It is an error to attempt to lock a file in a different mode when it is 227 //! It is an error to attempt to lock a file in a different mode when it is
210 //! already locked. This call will block until the lock is acquired. The 228 //! already locked. This call will block until the lock is acquired. The
211 //! entire file is locked. 229 //! entire file is locked.
212 //! 230 //!
213 //! If \a locking is FileLocking::kShared, \a file must have been opened for 231 //! If \a locking is FileLocking::kShared, \a file must have been opened for
214 //! reading, and if it's FileLocking::kExclusive, \a file must have been opened 232 //! reading, and if it's FileLocking::kExclusive, \a file must have been opened
215 //! for writing. 233 //! for writing.
(...skipping 20 matching lines...) Expand all
236 //! operation fails. 254 //! operation fails.
237 //! 255 //!
238 //! Repositions the offset of the open \a file to the specified \a offset, 256 //! Repositions the offset of the open \a file to the specified \a offset,
239 //! relative to \a whence. \a whence must be one of `SEEK_SET`, `SEEK_CUR`, or 257 //! relative to \a whence. \a whence must be one of `SEEK_SET`, `SEEK_CUR`, or
240 //! `SEEK_END`, and is interpreted in the usual way. 258 //! `SEEK_END`, and is interpreted in the usual way.
241 //! 259 //!
242 //! \return The resulting offset in bytes from the beginning of the file, or 260 //! \return The resulting offset in bytes from the beginning of the file, or
243 //! `-1` on failure. 261 //! `-1` on failure.
244 FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence); 262 FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence);
245 263
264 //! \brief Truncates the given \a file to zero bytes in length.
265 //!
266 //! \return `true` on success, or `false`, and a message will be logged.
267 bool LoggingTruncateFile(FileHandle file);
268
246 //! \brief Wraps `close()` or `CloseHandle()`, logging an error if the operation 269 //! \brief Wraps `close()` or `CloseHandle()`, logging an error if the operation
247 //! fails. 270 //! fails.
248 //! 271 //!
249 //! \return On success, `true` is returned. On failure, an error is logged and 272 //! \return On success, `true` is returned. On failure, an error is logged and
250 //! `false` is returned. 273 //! `false` is returned.
251 bool LoggingCloseFile(FileHandle file); 274 bool LoggingCloseFile(FileHandle file);
252 275
253 //! \brief Wraps `close()` or `CloseHandle()`, ensuring that it succeeds. 276 //! \brief Wraps `close()` or `CloseHandle()`, ensuring that it succeeds.
254 //! 277 //!
255 //! If the underlying function fails, this function causes execution to 278 //! If the underlying function fails, this function causes execution to
256 //! terminate without returning. 279 //! terminate without returning.
257 void CheckedCloseFile(FileHandle file); 280 void CheckedCloseFile(FileHandle file);
258 281
259 } // namespace crashpad 282 } // namespace crashpad
260 283
261 #endif // CRASHPAD_UTIL_FILE_FILE_IO_H_ 284 #endif // CRASHPAD_UTIL_FILE_FILE_IO_H_
OLDNEW
« no previous file with comments | « client/settings_test.cc ('k') | util/file/file_io_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698