diff options
-rw-r--r-- | src/flatfile.cpp | 19 | ||||
-rw-r--r-- | src/flatfile.h | 14 | ||||
-rw-r--r-- | src/util/system.cpp | 8 | ||||
-rw-r--r-- | src/util/system.h | 2 |
4 files changed, 20 insertions, 23 deletions
diff --git a/src/flatfile.cpp b/src/flatfile.cpp index d2e11825d5..8a8f7b681c 100644 --- a/src/flatfile.cpp +++ b/src/flatfile.cpp @@ -30,25 +30,24 @@ fs::path FlatFileSeq::FileName(const FlatFilePos& pos) const return m_dir / strprintf("%s%05u.dat", m_prefix, pos.nFile); } -FILE* FlatFileSeq::Open(const FlatFilePos& pos, bool fReadOnly) +FILE* FlatFileSeq::Open(const FlatFilePos& pos, bool read_only) { - if (pos.IsNull()) + 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/flatfile.h b/src/flatfile.h index 6051970490..374ceff411 100644 --- a/src/flatfile.h +++ b/src/flatfile.h @@ -24,14 +24,12 @@ struct FlatFilePos 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 @@ public: 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. The amount allocated diff --git a/src/util/system.cpp b/src/util/system.cpp index 3e6c2ae5d4..1f0a097e3d 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -135,12 +135,12 @@ bool DirIsWritable(const fs::path& directory) return true; } -bool CheckDiskSpace(const fs::path& dir, uint64_t nAdditionalBytes) +bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes) { - constexpr uint64_t nMinDiskSpace = 52428800; // 50 MiB + constexpr uint64_t min_disk_space = 52428800; // 50 MiB - 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; } /** diff --git a/src/util/system.h b/src/util/system.h index 2a2ee9bc1d..bcfcaaaed0 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -72,7 +72,7 @@ bool RenameOver(fs::path src, fs::path dest); bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false); void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name); 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 * the global destructor will take care of the locks. |