Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions base/filesystem/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<uint8_t> data) {
bool File::ReadAndCheck(i64 offset, base::Span<u8> data) {
int size = static_cast<int>(data.size());
return Read(offset, reinterpret_cast<char*>(data.begin()), size) == size;
}

bool File::ReadAtCurrentPosAndCheck(base::Span<uint8_t> data) {
bool File::ReadAtCurrentPosAndCheck(base::Span<u8> data) {
int size = static_cast<int>(data.size());
return ReadAtCurrentPos(reinterpret_cast<char*>(data.begin()), size) == size;
}

bool File::WriteAndCheck(int64_t offset, base::Span<const uint8_t> data) {
bool File::WriteAndCheck(i64 offset, base::Span<const u8> data) {
int size = static_cast<int>(data.size());
return Write(offset, reinterpret_cast<const char*>(data.data()), size) == size;
}

bool File::WriteAtCurrentPosAndCheck(base::Span<const uint8_t> data) {
bool File::WriteAtCurrentPosAndCheck(base::Span<const u8> data) {
int size = static_cast<int>(data.size());
return WriteAtCurrentPos(reinterpret_cast<const char*>(data.data()), size) == size;
}
Expand Down
31 changes: 16 additions & 15 deletions base/filesystem/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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<uint8_t> data);
bool ReadAtCurrentPosAndCheck(base::Span<uint8_t> data);
bool WriteAndCheck(int64_t offset, base::Span<const uint8_t> data);
bool WriteAtCurrentPosAndCheck(base::Span<const uint8_t> data);
bool ReadAndCheck(i64 offset, base::Span<u8> data);
bool ReadAtCurrentPosAndCheck(base::Span<u8> data);
bool WriteAndCheck(i64 offset, base::Span<const u8> data);
bool WriteAtCurrentPosAndCheck(base::Span<const u8> 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);
Expand All @@ -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);
Expand All @@ -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).
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down
14 changes: 7 additions & 7 deletions base/filesystem/posix/file_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ 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());

static_assert(sizeof(int64_t) == sizeof(off_t), "off_t must be 64 bits");
return lseek(file_.get(), static_cast<off_t>(offset), static_cast<int>(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)
Expand Down Expand Up @@ -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());

Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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());

Expand Down Expand Up @@ -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());

Expand Down
18 changes: 9 additions & 9 deletions base/filesystem/win/file_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -85,15 +85,15 @@ 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);
}

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_);

Expand Down Expand Up @@ -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<int64_t>(size.QuadPart);
return static_cast<i64>(size.QuadPart);
}

bool File::SetLength(int64_t length) {
bool File::SetLength(i64 length) {
BASE_BUGCHECK(IsValid());

// Get the current file pointer.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion base/hashing/crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// For licensing information see LICENSE at the root of this distribution.
#pragma once

#include <base/arch.h>
#include <base/compiler.h>

#if defined(__SSE4_2__) && (defined(__GNUC__) || defined(__clang__))
Expand Down Expand Up @@ -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.
Expand Down