File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 10
10
#ifndef UMF_COMMON_H
11
11
#define UMF_COMMON_H 1
12
12
13
+ #include <stdint.h>
13
14
#include <stdio.h>
14
15
#include <stdlib.h>
15
16
#include <string.h>
@@ -77,6 +78,25 @@ static inline void *Zalloc(size_t s) {
77
78
} \
78
79
} while (0)
79
80
81
+ // align a pointer and a size
82
+ static inline void align_ptr_size (void * * ptr , size_t * size , size_t alignment ) {
83
+ uintptr_t p = (uintptr_t )* ptr ;
84
+ size_t s = * size ;
85
+
86
+ // align pointer to 'alignment' bytes and adjust the size
87
+ size_t rest = p & (alignment - 1 );
88
+ if (rest ) {
89
+ p += alignment - rest ;
90
+ s -= alignment - rest ;
91
+ }
92
+
93
+ ASSERT ((p & (alignment - 1 )) == 0 );
94
+ ASSERT ((s & (alignment - 1 )) == 0 );
95
+
96
+ * ptr = (void * )p ;
97
+ * size = s ;
98
+ }
99
+
80
100
static inline size_t align_size (size_t size , size_t alignment ) {
81
101
// align size to 'alignment' bytes
82
102
size_t rest = size & (alignment - 1 );
You can’t perform that action at this time.
0 commit comments