diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2023-02-28 21:46:11 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2023-03-04 10:10:20 +0100 |
commit | e7489b70d16d218470cb5ce45766bdfa38d6db91 (patch) | |
tree | 9209f9fd37bff232b2c5f3918fa0b7fb8136e65d /src/util/file.hpp | |
parent | 9b7830450268893bdb23872d5fcfa89b8d014f5e (diff) | |
download | ccache-e7489b70d16d218470cb5ce45766bdfa38d6db91.tar.gz |
enhance: Add util::likely_size_on_disk
Diffstat (limited to 'src/util/file.hpp')
-rw-r--r-- | src/util/file.hpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/util/file.hpp b/src/util/file.hpp index bb0c8b22..c74b58dc 100644 --- a/src/util/file.hpp +++ b/src/util/file.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2022 Joel Rosdahl and other contributors +// Copyright (C) 2021-2023 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -39,6 +39,9 @@ enum class InPlace { yes, no }; void create_cachedir_tag(const std::string& dir); +// Return how much a file of `size` bytes likely would take on disk. +uint64_t likely_size_on_disk(uint64_t size); + // Read data from `fd` until end of file and call `data_receiver` with the read // data. Returns an error if the underlying read(2) call returned -1. nonstd::expected<void, std::string> read_fd(int fd, DataReceiver data_receiver); @@ -87,4 +90,12 @@ nonstd::expected<void, std::string> write_file(const std::string& path, nonstd::span<const uint8_t> data, InPlace in_place = InPlace::no); +// --- Inline implementations --- + +inline uint64_t +likely_size_on_disk(uint64_t size) +{ + return (size + 4095) & ~4095; +} + } // namespace util |