summaryrefslogtreecommitdiffstats
path: root/third_party/rust/object/src/write/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/object/src/write/util.rs')
-rw-r--r--third_party/rust/object/src/write/util.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/third_party/rust/object/src/write/util.rs b/third_party/rust/object/src/write/util.rs
new file mode 100644
index 0000000000..0ac65424af
--- /dev/null
+++ b/third_party/rust/object/src/write/util.rs
@@ -0,0 +1,14 @@
+use crate::alloc::vec::Vec;
+
+pub(crate) fn align(offset: usize, size: usize) -> usize {
+ (offset + (size - 1)) & !(size - 1)
+}
+
+pub(crate) fn align_u64(offset: u64, size: u64) -> u64 {
+ (offset + (size - 1)) & !(size - 1)
+}
+
+pub(crate) fn write_align(buffer: &mut Vec<u8>, size: usize) {
+ let offset = align(buffer.len(), size);
+ buffer.resize(offset, 0);
+}