diff --git a/base/filesystem/file.cc b/base/filesystem/file.cc index 07567a3c..9b334099 100644 --- a/base/filesystem/file.cc +++ b/base/filesystem/file.cc @@ -20,7 +20,7 @@ File::Info::~Info() = default; File::File() = default; #if !defined(OS_NACL) -File::File(const Path& path, uint32_t flags) : error_details_(FILE_OK) { +File::File(const Path& path, u32 flags) : error_details_(FILE_OK) { Initialize(path, flags); } #endif @@ -68,28 +68,28 @@ File& File::operator=(File&& other) noexcept { } #if !defined(OS_NACL) -void File::Initialize(const Path& path, uint32_t flags) { +void File::Initialize(const Path& path, u32 flags) { path_ = path; DoInitialize(path, flags); } #endif -bool File::ReadAndCheck(int64_t offset, base::Span data) { +bool File::ReadAndCheck(i64 offset, base::Span data) { int size = static_cast(data.size()); return Read(offset, reinterpret_cast(data.begin()), size) == size; } -bool File::ReadAtCurrentPosAndCheck(base::Span data) { +bool File::ReadAtCurrentPosAndCheck(base::Span data) { int size = static_cast(data.size()); return ReadAtCurrentPos(reinterpret_cast(data.begin()), size) == size; } -bool File::WriteAndCheck(int64_t offset, base::Span data) { +bool File::WriteAndCheck(i64 offset, base::Span data) { int size = static_cast(data.size()); return Write(offset, reinterpret_cast(data.data()), size) == size; } -bool File::WriteAtCurrentPosAndCheck(base::Span data) { +bool File::WriteAtCurrentPosAndCheck(base::Span data) { int size = static_cast(data.size()); return WriteAtCurrentPos(reinterpret_cast(data.data()), size) == size; } diff --git a/base/filesystem/file.h b/base/filesystem/file.h index 821b571e..861e3ff7 100644 --- a/base/filesystem/file.h +++ b/base/filesystem/file.h @@ -2,6 +2,7 @@ // For licensing information see LICENSE at the root of this distribution. #pragma once +#include "base/arch.h" #include "base/containers/span.h" #include "base/export.h" #include "base/filesystem/path.h" @@ -117,7 +118,7 @@ class BASE_EXPORT File { #endif // The size of the file in bytes. Undefined when is_directory is true. - int64_t size = 0; + i64 size = 0; // True if the file corresponds to a directory. bool is_directory = false; @@ -131,7 +132,7 @@ class BASE_EXPORT File { // Creates or opens the given file. This will fail with 'access denied' if the // |path| contains path traversal ('..') components. - File(const Path& path, uint32_t flags); + File(const Path& path, u32 flags); // Takes ownership of |platform_file| and sets async to false. explicit File(ScopedPlatformFile platform_file); @@ -156,7 +157,7 @@ class BASE_EXPORT File { File& operator=(File&& other) noexcept; // Creates or opens the given file. - void Initialize(const Path& path, uint32_t flags); + void Initialize(const Path& path, u32 flags); // Returns |true| if the handle / fd wrapped by this object is valid. This // method doesn't interact with the file system and is thus safe to be called @@ -184,27 +185,27 @@ class BASE_EXPORT File { // Changes current position in the file to an |offset| relative to an origin // defined by |whence|. Returns the resultant current position in the file // (relative to the start) or -1 in case of error. - int64_t Seek(Whence whence, int64_t offset); + i64 Seek(Whence whence, i64 offset); // Simplified versions of Read() and friends (see below) that check the int // return value and just return a boolean. They return true if and only if // the function read in / wrote out exactly |size| bytes of data. - bool ReadAndCheck(int64_t offset, base::Span data); - bool ReadAtCurrentPosAndCheck(base::Span data); - bool WriteAndCheck(int64_t offset, base::Span data); - bool WriteAtCurrentPosAndCheck(base::Span data); + bool ReadAndCheck(i64 offset, base::Span data); + bool ReadAtCurrentPosAndCheck(base::Span data); + bool WriteAndCheck(i64 offset, base::Span data); + bool WriteAtCurrentPosAndCheck(base::Span data); // Reads up to |size| bytes (or until EOF) at |offset|. Returns the number // of bytes read, or -1 on error. Makes a best effort to read all data on // all platforms; not for stream-oriented files. - int Read(int64_t offset, char* data, int size); + int Read(i64 offset, char* data, int size); // Same as Read() without the seek. int ReadAtCurrentPos(char* data, int size); // Like Read() but makes no effort to read all data. Returns the number of // bytes read, or -1 on error. - int ReadNoBestEffort(int64_t offset, char* data, int size); + int ReadNoBestEffort(i64 offset, char* data, int size); // Same as ReadNoBestEffort() without the seek. int ReadAtCurrentPosNoBestEffort(char* data, int size); @@ -213,7 +214,7 @@ class BASE_EXPORT File { // number of bytes written, or -1 on error. Makes a best effort to write all // data on all platforms. |data| may be nullptr when |size| is 0. With // FLAG_APPEND the offset is ignored and writes go to the end of the file. - int Write(int64_t offset, const char* data, size_t size); + int Write(i64 offset, const char* data, mem_size size); // Same as Write() without the seek. int WriteAtCurrentPos(const char* data, int size); @@ -222,12 +223,12 @@ class BASE_EXPORT File { int WriteAtCurrentPosNoBestEffort(const char* data, int size); // Returns the current size of this file, or a negative number on failure. - int64_t GetLength(); + i64 GetLength(); // Truncates the file to the given length. If |length| is greater than the // current size of the file, the file is extended with zeros. If the file // doesn't exist, |false| is returned. - bool SetLength(int64_t length); + bool SetLength(i64 length); // Instructs the filesystem to flush the file to disk. (POSIX: fsync, Windows: // FlushFileBuffers). @@ -286,7 +287,7 @@ class BASE_EXPORT File { #endif #if defined(OS_WIN) - static Error OSErrorToFileError(uint32_t last_error); + static Error OSErrorToFileError(u32 last_error); #elif defined(OS_POSIX) || defined(OS_FUCHSIA) static Error OSErrorToFileError(int saved_errno); #endif @@ -313,7 +314,7 @@ class BASE_EXPORT File { private: // Creates or opens the given file. Only called if |path| has no // traversal ('..') components. - void DoInitialize(const Path& path, uint32_t flags); + void DoInitialize(const Path& path, u32 flags); void SetPlatformFile(PlatformFile file); diff --git a/base/filesystem/posix/file_posix.cc b/base/filesystem/posix/file_posix.cc index dc6fae6d..8e6cc9fe 100644 --- a/base/filesystem/posix/file_posix.cc +++ b/base/filesystem/posix/file_posix.cc @@ -116,7 +116,7 @@ void File::Close() { file_.reset(); } -int64_t File::Seek(Whence whence, int64_t offset) { +i64 File::Seek(Whence whence, i64 offset) { ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK); BASE_DCHECK(IsValid()); @@ -124,7 +124,7 @@ int64_t File::Seek(Whence whence, int64_t offset) { return lseek(file_.get(), static_cast(offset), static_cast(whence)); } -int File::Read(int64_t offset, char* data, int size) { +int File::Read(i64 offset, char* data, int size) { ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK); BASE_DCHECK(IsValid()); if (size < 0) @@ -163,7 +163,7 @@ int File::ReadAtCurrentPos(char* data, int size) { return bytes_read ? bytes_read : rv; } -int File::ReadNoBestEffort(int64_t offset, char* data, int size) { +int File::ReadNoBestEffort(i64 offset, char* data, int size) { ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK); BASE_DCHECK(IsValid()); @@ -179,7 +179,7 @@ int File::ReadAtCurrentPosNoBestEffort(char* data, int size) { return HANDLE_EINTR(read(file_.get(), data, size)); } -int File::Write(int64_t offset, const char* data, size_t size) { +int File::Write(i64 offset, const char* data, mem_size size) { ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK); // The running total and the return value are both int, so a request larger @@ -238,7 +238,7 @@ int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { return HANDLE_EINTR(write(file_.get(), data, size)); } -int64_t File::GetLength() { +i64 File::GetLength() { BASE_DCHECK(IsValid()); stat_wrapper_t file_info; @@ -248,7 +248,7 @@ int64_t File::GetLength() { return file_info.st_size; } -bool File::SetLength(int64_t length) { +bool File::SetLength(i64 length) { ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK); BASE_DCHECK(IsValid()); @@ -332,7 +332,7 @@ File::Error File::OSErrorToFileError(int saved_errno) { } // TODO: consider supporting FLAG_EXCLUSIVE_* here. -void File::DoInitialize(const Path& path, uint32_t flags) { +void File::DoInitialize(const Path& path, u32 flags) { ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK); BASE_DCHECK(!IsValid()); diff --git a/base/filesystem/win/file_win.cc b/base/filesystem/win/file_win.cc index 2565ed7f..3dc61374 100644 --- a/base/filesystem/win/file_win.cc +++ b/base/filesystem/win/file_win.cc @@ -37,7 +37,7 @@ void File::Close() { file_.Close(); } -int64_t File::Seek(Whence whence, int64_t offset) { +i64 File::Seek(Whence whence, i64 offset) { BASE_BUGCHECK(IsValid()); LARGE_INTEGER distance, res; @@ -48,7 +48,7 @@ int64_t File::Seek(Whence whence, int64_t offset) { return res.QuadPart; } -int File::Read(int64_t offset, char* data, int size) { +int File::Read(i64 offset, char* data, int size) { BASE_BUGCHECK(IsValid()); BASE_BUGCHECK(!async_); if (size < 0) @@ -85,7 +85,7 @@ int File::ReadAtCurrentPos(char* data, int size) { return -1; } -int File::ReadNoBestEffort(int64_t offset, char* data, int size) { +int File::ReadNoBestEffort(i64 offset, char* data, int size) { return Read(offset, data, size); } @@ -93,7 +93,7 @@ int File::ReadAtCurrentPosNoBestEffort(char* data, int size) { return ReadAtCurrentPos(data, size); } -int File::Write(int64_t offset, const char* data, size_t size) { +int File::Write(i64 offset, const char* data, mem_size size) { BASE_BUGCHECK(IsValid()); BASE_BUGCHECK(!async_); @@ -135,17 +135,17 @@ int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { return WriteAtCurrentPos(data, size); } -int64_t File::GetLength() { +i64 File::GetLength() { BASE_BUGCHECK(IsValid()); LARGE_INTEGER size; if (!::GetFileSizeEx(file_.Get(), &size)) return -1; - return static_cast(size.QuadPart); + return static_cast(size.QuadPart); } -bool File::SetLength(int64_t length) { +bool File::SetLength(i64 length) { BASE_BUGCHECK(IsValid()); // Get the current file pointer. @@ -253,7 +253,7 @@ bool File::DeleteOnClose(bool delete_on_close) { } // Static. -File::Error File::OSErrorToFileError(uint32_t last_error) { +File::Error File::OSErrorToFileError(u32 last_error) { switch (last_error) { case ERROR_SHARING_VIOLATION: case ERROR_UNABLE_TO_REMOVE_REPLACED: // ReplaceFile failure cases. @@ -296,7 +296,7 @@ File::Error File::OSErrorToFileError(uint32_t last_error) { } } -void File::DoInitialize(const Path& path, uint32_t flags) { +void File::DoInitialize(const Path& path, u32 flags) { BASE_BUGCHECK(!IsValid()); DWORD disposition = 0; diff --git a/base/hashing/crc.h b/base/hashing/crc.h index 22b50d93..708df00f 100644 --- a/base/hashing/crc.h +++ b/base/hashing/crc.h @@ -2,6 +2,7 @@ // For licensing information see LICENSE at the root of this distribution. #pragma once +#include #include #if defined(__SSE4_2__) && (defined(__GNUC__) || defined(__clang__)) @@ -63,7 +64,7 @@ inline u32 CRC32C_SW( inline u32 CRC32C(const byte* data, mem_size length, u32 previousCrc32 = 0xFFFFFFFF) { // virtually all 64 bit chips have it #ifdef ARCH_X86_64 - uint32_t crc = ~previousCrc32; + u32 crc = ~previousCrc32; // The Intel instruction uses the iSCSI (Castagnoli) polynomial, for the CRC // often referred to as CRC-32C.