summaryrefslogtreecommitdiffhomepage
path: root/pkg/binary
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-02-11 19:11:43 +0000
committergVisor bot <gvisor-bot@google.com>2020-02-11 19:11:43 +0000
commit3f585de5d7125ad7b6cf4b22e3ddf508818bb7db (patch)
tree57e9d0da31c01ed4060fe59f956e26c9e6e1818b /pkg/binary
parentc9c7eababe54e1b7d9fe43f12f479564ca24ddcc (diff)
parent762e4761cc4edd92108f6836ad1933c7158b8be8 (diff)
Merge release-20200127.0-128-g762e476 (automated)
Diffstat (limited to 'pkg/binary')
-rw-r--r--pkg/binary/binary.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/pkg/binary/binary.go b/pkg/binary/binary.go
index 631785f7b..25065aef9 100644
--- a/pkg/binary/binary.go
+++ b/pkg/binary/binary.go
@@ -254,3 +254,13 @@ func WriteUint64(w io.Writer, order binary.ByteOrder, num uint64) error {
_, err := w.Write(buf)
return err
}
+
+// AlignUp rounds a length up to an alignment. align must be a power of 2.
+func AlignUp(length int, align uint) int {
+ return (length + int(align) - 1) & ^(int(align) - 1)
+}
+
+// AlignDown rounds a length down to an alignment. align must be a power of 2.
+func AlignDown(length int, align uint) int {
+ return length & ^(int(align) - 1)
+}