Something like this for example:
char* aligned_buf;
char* buf;
size_t max_align_offset = (1<<align) - 1;
buf = malloc(length_needed + max_align_offset);
aligned_buf = (buf + max_align_offset) & ~max_align_offset;
In the example, if align==8, you have 256 byte alignment. If it's 12, 4kB alignment.