summaryrefslogtreecommitdiff
path: root/src/basic/io-util.h
diff options
context:
space:
mode:
authorDaniel Mack <github@zonque.org>2016-01-27 13:35:18 +0100
committerDaniel Mack <github@zonque.org>2016-01-27 13:35:18 +0100
commitfdb4ee00f022863ceee923b196f9c6dd536db9e2 (patch)
tree647aae3aa21c2e22073fc895f39a2c171e052a99 /src/basic/io-util.h
parent1cdc94482302cca88e0a7282bbc161c1d77c381c (diff)
parenta464cf80110f0c7424f688ffaa4ec0a8a19f9720 (diff)
Merge pull request #2445 from poettering/various-fixes
A number of fixes
Diffstat (limited to 'src/basic/io-util.h')
-rw-r--r--src/basic/io-util.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/basic/io-util.h b/src/basic/io-util.h
index 5f77a556c0..7d0d2bd810 100644
--- a/src/basic/io-util.h
+++ b/src/basic/io-util.h
@@ -77,3 +77,21 @@ static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) {
return k;
}
+
+static inline bool FILE_SIZE_VALID(uint64_t l) {
+ /* ftruncate() and friends take an unsigned file size, but actually cannot deal with file sizes larger than
+ * 2^63 since the kernel internally handles it as signed value. This call allows checking for this early. */
+
+ return (l >> 63) == 0;
+}
+
+static inline bool FILE_SIZE_VALID_OR_INFINITY(uint64_t l) {
+
+ /* Same as above, but allows one extra value: -1 as indication for infinity. */
+
+ if (l == (uint64_t) -1)
+ return true;
+
+ return FILE_SIZE_VALID(l);
+
+}