mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
Add LoggingSeekFile
As the whence values are "helpfully" available in windows.h as well ( http://msdn.microsoft.com/en-us/library/windows/desktop/dd757336(v=vs.85).aspx ) don't bother inventing a new enum. Add implementations for POSIX and Win32. R=mark@chromium.org BUG=crashpad:1 Review URL: https://codereview.chromium.org/812593005
This commit is contained in:
parent
4034d30023
commit
384497475a
@ -30,10 +30,18 @@ class FilePath;
|
|||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
|
||||||
#if defined(OS_POSIX) || DOXYGEN
|
#if defined(OS_POSIX) || DOXYGEN
|
||||||
|
|
||||||
//! \brief Platform-specific alias for a low-level file handle.
|
//! \brief Platform-specific alias for a low-level file handle.
|
||||||
using FileHandle = int;
|
using FileHandle = int;
|
||||||
|
|
||||||
|
//! \brief Platform-specific alias for a position in an open file.
|
||||||
|
using FileOffset = off_t;
|
||||||
|
|
||||||
#elif defined(OS_WIN)
|
#elif defined(OS_WIN)
|
||||||
|
|
||||||
using FileHandle = HANDLE;
|
using FileHandle = HANDLE;
|
||||||
|
using FileOffset = LONGLONG;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//! \brief Determines the mode that LoggingOpenFileForWrite() uses.
|
//! \brief Determines the mode that LoggingOpenFileForWrite() uses.
|
||||||
@ -166,6 +174,17 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
|
|||||||
FileWriteMode write_mode,
|
FileWriteMode write_mode,
|
||||||
bool world_readable);
|
bool world_readable);
|
||||||
|
|
||||||
|
//! \brief Wraps `lseek()` or `SetFilePointerEx()`. Logs an error if the
|
||||||
|
//! operation fails.
|
||||||
|
//!
|
||||||
|
//! Repositions the offset of the open \a file to the specified \a offset,
|
||||||
|
//! relative to \a whence. \a whence must be one of `SEEK_SET`, `SEEK_CUR`, or
|
||||||
|
//! `SEEK_END`, and is interpreted in the usual way.
|
||||||
|
//!
|
||||||
|
//! \return The resulting offset in bytes from the beginning of the file, or
|
||||||
|
//! `-1` on failure.
|
||||||
|
FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence);
|
||||||
|
|
||||||
//! \brief Wraps `close()` or `CloseHandle()`, logging an error if the operation
|
//! \brief Wraps `close()` or `CloseHandle()`, logging an error if the operation
|
||||||
//! fails.
|
//! fails.
|
||||||
//!
|
//!
|
||||||
|
@ -98,6 +98,12 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence) {
|
||||||
|
off_t rv = lseek(file, offset, whence);
|
||||||
|
PLOG_IF(ERROR, rv < 0) << "lseek";
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
bool LoggingCloseFile(FileHandle file) {
|
bool LoggingCloseFile(FileHandle file) {
|
||||||
int rv = IGNORE_EINTR(close(file));
|
int rv = IGNORE_EINTR(close(file));
|
||||||
PLOG_IF(ERROR, rv != 0) << "close";
|
PLOG_IF(ERROR, rv != 0) << "close";
|
||||||
|
@ -103,6 +103,34 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence) {
|
||||||
|
DWORD method = 0;
|
||||||
|
switch (whence) {
|
||||||
|
case SEEK_SET:
|
||||||
|
method = FILE_BEGIN;
|
||||||
|
break;
|
||||||
|
case SEEK_CUR:
|
||||||
|
method = FILE_CURRENT;
|
||||||
|
break;
|
||||||
|
case SEEK_END:
|
||||||
|
method = FILE_END;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
NOTREACHED();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
LARGE_INTEGER distance_to_move;
|
||||||
|
distance_to_move.QuadPart = offset;
|
||||||
|
LARGE_INTEGER new_offset;
|
||||||
|
BOOL result = SetFilePointerEx(file, distance_to_move, &new_offset, method);
|
||||||
|
if (!result) {
|
||||||
|
PLOG(ERROR) << "SetFilePointerEx";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return new_offset.QuadPart;
|
||||||
|
}
|
||||||
|
|
||||||
bool LoggingCloseFile(FileHandle file) {
|
bool LoggingCloseFile(FileHandle file) {
|
||||||
BOOL rv = CloseHandle(file);
|
BOOL rv = CloseHandle(file);
|
||||||
PLOG_IF(ERROR, !rv) << "CloseHandle";
|
PLOG_IF(ERROR, !rv) << "CloseHandle";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user