1 /* zutil_p.h -- Private inline functions used internally in zlib-ng
2  * For conditions of distribution and use, see copyright notice in zlib.h
3  */
4 
5 #ifndef ZUTIL_P_H
6 #define ZUTIL_P_H
7 
8 #if defined(__APPLE__) || defined(HAVE_POSIX_MEMALIGN)
9 #  include <stdlib.h>
10 #elif defined(__FreeBSD__)
11 #  include <stdlib.h>
12 #  include <malloc_np.h>
13 #else
14 #  include <malloc.h>
15 #endif
16 
17 /* Function to allocate 16 or 64-byte aligned memory */
zng_alloc(size_t size)18 static inline void *zng_alloc(size_t size) {
19 #ifdef HAVE_POSIX_MEMALIGN
20     void *ptr;
21     return posix_memalign(&ptr, 64, size) ? NULL : ptr;
22 #elif defined(_WIN32)
23     return (void *)_aligned_malloc(size, 64);
24 #elif defined(__APPLE__)
25     return (void *)malloc(size);     /* MacOS always aligns to 16 bytes */
26 #else
27     return (void *)memalign(64, size);
28 #endif
29 }
30 
31 /* Function that can free aligned memory */
zng_free(void * ptr)32 static inline void zng_free(void *ptr) {
33 #if defined(_WIN32)
34     _aligned_free(ptr);
35 #else
36     free(ptr);
37 #endif
38 }
39 
40 #endif
41