diff --git a/configure.ac b/configure.ac index 73f7a2c2f..d860a74fe 100644 --- a/configure.ac +++ b/configure.ac @@ -326,7 +326,7 @@ HTS_HIDE_DYNAMIC_SYMBOLS dnl FIXME This pulls in dozens of standard header checks AC_FUNC_MMAP -AC_CHECK_FUNCS([gmtime_r fsync drand48 srand48_deterministic getauxval elf_aux_info]) +AC_CHECK_FUNCS([gmtime_r fsync drand48 srand48_deterministic getauxval elf_aux_info posix_memalign]) # Darwin has a dubious fdatasync() symbol, but no declaration in AC_CHECK_DECL([fdatasync(int)], [AC_CHECK_FUNCS(fdatasync)]) diff --git a/hfile.c b/hfile.c index 20245db43..f810f0d25 100644 --- a/hfile.c +++ b/hfile.c @@ -113,8 +113,13 @@ hFILE *hfile_init(size_t struct_size, const char *mode, size_t capacity) // FIXME For now, clamp input buffer sizes so mpileup doesn't eat memory if (strchr(mode, 'r') && capacity > maxcap) capacity = maxcap; +#ifdef HAVE_POSIX_MEMALIGN + if (posix_memalign((void **)&fp->buffer, 256, capacity) < 0) + goto error; +#else fp->buffer = (char *) malloc(capacity); if (fp->buffer == NULL) goto error; +#endif fp->begin = fp->end = fp->buffer; fp->limit = &fp->buffer[capacity];