diff --git a/src/flatfile.h b/src/flatfile.h --- a/src/flatfile.h +++ b/src/flatfile.h @@ -23,12 +23,10 @@ READWRITE(VARINT(nPos)); } - FlatFilePos() { SetNull(); } + FlatFilePos() : nFile(-1), nPos(0) {} - FlatFilePos(int nFileIn, unsigned int nPosIn) { - nFile = nFileIn; - nPos = nPosIn; - } + FlatFilePos(int nFileIn, unsigned int nPosIn) + : nFile(nFileIn), nPos(nPosIn) {} friend bool operator==(const FlatFilePos &a, const FlatFilePos &b) { return (a.nFile == b.nFile && a.nPos == b.nPos); @@ -72,7 +70,7 @@ fs::path FileName(const FlatFilePos &pos) const; /** Open a handle to the file at the given position. */ - FILE *Open(const FlatFilePos &pos, bool fReadOnly = false); + FILE *Open(const FlatFilePos &pos, bool read_only = false); /** * Allocate additional space in a file after the given starting position. diff --git a/src/flatfile.cpp b/src/flatfile.cpp --- a/src/flatfile.cpp +++ b/src/flatfile.cpp @@ -25,25 +25,25 @@ return m_dir / strprintf("%s%05u.dat", m_prefix, pos.nFile); } -FILE *FlatFileSeq::Open(const FlatFilePos &pos, bool fReadOnly) { - if (pos.IsNull()) return nullptr; +FILE *FlatFileSeq::Open(const FlatFilePos &pos, bool read_only) { + if (pos.IsNull()) { + return nullptr; + } fs::path path = FileName(pos); fs::create_directories(path.parent_path()); - FILE *file = fsbridge::fopen(path, fReadOnly ? "rb" : "rb+"); - if (!file && !fReadOnly) { + FILE *file = fsbridge::fopen(path, read_only ? "rb" : "rb+"); + if (!file && !read_only) { file = fsbridge::fopen(path, "wb+"); } if (!file) { LogPrintf("Unable to open file %s\n", path.string()); return nullptr; } - if (pos.nPos) { - if (fseek(file, pos.nPos, SEEK_SET)) { - LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, - path.string()); - fclose(file); - return nullptr; - } + if (pos.nPos && fseek(file, pos.nPos, SEEK_SET)) { + LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, + path.string()); + fclose(file); + return nullptr; } return file; } diff --git a/src/util.h b/src/util.h --- a/src/util.h +++ b/src/util.h @@ -75,7 +75,7 @@ bool LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only = false); bool DirIsWritable(const fs::path &directory); -bool CheckDiskSpace(const fs::path &dir, uint64_t nAdditionalBytes = 0); +bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes = 0); /** * Release all directory locks. This is used for unit testing only, at runtime diff --git a/src/util.cpp b/src/util.cpp --- a/src/util.cpp +++ b/src/util.cpp @@ -203,12 +203,12 @@ return true; } -bool CheckDiskSpace(const fs::path &dir, uint64_t nAdditionalBytes) { +bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes) { // 50 MiB - constexpr uint64_t nMinDiskSpace = 52428800; + constexpr uint64_t min_disk_space = 52428800; - uint64_t nFreeBytesAvailable = fs::space(dir).available; - return nFreeBytesAvailable >= nMinDiskSpace + nAdditionalBytes; + uint64_t free_bytes_available = fs::space(dir).available; + return free_bytes_available >= min_disk_space + additional_bytes; } /**