Make lib/memalign.c a stand-alone library
authorTomohiro Kusumi <tkusumi@tuxera.com>
Tue, 4 Apr 2017 20:22:15 +0000 (23:22 +0300)
committerJens Axboe <axboe@fb.com>
Sat, 8 Apr 2017 17:04:21 +0000 (11:04 -0600)
lib/memalign.c not having dependency on fio.h enables it to be
a stand-alone library, which is useful for debugging purpose.
In fact, most of the files under lib/ directory do things this way.

(For lib/memalign.c, it was actually myself who introduced this
dependency as a part of changes made by 248c9436, so this commit
is partially reverting that)

--
 # cat ./test3.c
 #include <stdio.h>
 #include "lib/memalign.h"
 int main(void) {
         char *p = fio_memalign(4096, 1000000);
         printf("%p\n", p);
         fio_memfree(p, 1000000);
         return 0;
 }
 # gcc -Wall -g ./test3.c ./lib/memalign.c
 # ./a.out
 0x7fbb7bbbc000

Signed-off-by: Tomohiro Kusumi <tkusumi@tuxera.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
lib/memalign.c

index 1d1ba9ba2013ea2c3fdba579931ff1743989cdd7..137cc8ec3ec4eef920b9524c9b6a374cba32660f 100644 (file)
@@ -3,7 +3,9 @@
 #include <inttypes.h>
 
 #include "memalign.h"
-#include "../fio.h"
+
+#define PTR_ALIGN(ptr, mask)   \
+       (char *)((uintptr_t)((ptr) + (mask)) & ~(mask))
 
 struct align_footer {
        unsigned int offset;