output_buffer: only realloc once, and memset just what we need
[fio.git] / memalign.c
index 87667b42c35c7bea3f5d4c5d3e3a7a60c8a94539..cfd6e463ff924682d44346d130283094b7de3a07 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <assert.h>
+#include <inttypes.h>
 
 #include "memalign.h"
 
@@ -8,7 +9,7 @@ struct align_footer {
 };
 
 #define PTR_ALIGN(ptr, mask)   \
-       (char *) (((unsigned long) ((ptr) + (mask)) & ~(mask)))
+       (char *) (((uintptr_t) ((ptr) + (mask)) & ~(mask)))
 
 void *fio_memalign(size_t alignment, size_t size)
 {
@@ -19,9 +20,9 @@ void *fio_memalign(size_t alignment, size_t size)
 
        ptr = malloc(size + alignment + size + sizeof(*f) - 1);
        if (ptr) {
-               ret = PTR_ALIGN(ptr, alignment);
+               ret = PTR_ALIGN(ptr, alignment - 1);
                f = ret + size;
-               f->offset = (unsigned long) ret - (unsigned long) ptr;
+               f->offset = (uintptr_t) ret - (uintptr_t) ptr;
        }
 
        return ret;