Unverified Commit fb28d7a9 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

introduce lpad/rpad functions

parent 4a868f35
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -39,6 +39,28 @@ inline off64_t ralign(const off64_t offset, const size_t block_size) {
}


/**
 * Return the padding (bytes) that separates the @offset from the closest
 * left side block boundary
 *
 * If @offset is a boundary the resulting padding will be 0
 */
inline size_t lpad(const off64_t offset, const size_t block_size) {
    return offset % block_size;
}


/**
 * Return the padding (bytes) that separates the @offset from the closest
 * right side block boundary
 *
 * If @offset is a boundary the resulting padding will be 0
 */
inline size_t rpad(const off64_t offset, const size_t block_size) {
    return (-offset) % block_size;
}


/**
 * Given an @offset calculates the block number to which the @offset belongs
 *