/src/c-blosc2/internal-complibs/zlib-ng-2.0.7/zutil_p.h
Line | Count | Source |
1 | | /* zutil_p.h -- Private inline functions used internally in zlib-ng |
2 | | * |
3 | | */ |
4 | | |
5 | | #ifndef ZUTIL_P_H |
6 | | #define ZUTIL_P_H |
7 | | |
8 | | #if defined(HAVE_POSIX_MEMALIGN) && !defined(_POSIX_C_SOURCE) |
9 | | # define _POSIX_C_SOURCE 200112L /* For posix_memalign(). */ |
10 | | #endif |
11 | | |
12 | | #if defined(__APPLE__) || defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_ALIGNED_ALLOC) |
13 | | # include <stdlib.h> |
14 | | #elif defined(__FreeBSD__) |
15 | | # include <stdlib.h> |
16 | | # include <malloc_np.h> |
17 | | #else |
18 | | # include <malloc.h> |
19 | | #endif |
20 | | |
21 | | /* Function to allocate 16 or 64-byte aligned memory */ |
22 | 164k | static inline void *zng_alloc(size_t size) { |
23 | | #ifdef HAVE_POSIX_MEMALIGN |
24 | | void *ptr; |
25 | | return posix_memalign(&ptr, 64, size) ? NULL : ptr; |
26 | | #elif defined(_WIN32) |
27 | | return (void *)_aligned_malloc(size, 64); |
28 | | #elif defined(__APPLE__) |
29 | | return (void *)malloc(size); /* MacOS always aligns to 16 bytes */ |
30 | | #elif defined(HAVE_ALIGNED_ALLOC) |
31 | | return (void *)aligned_alloc(64, size); |
32 | | #else |
33 | 164k | return (void *)memalign(64, size); |
34 | 164k | #endif |
35 | 164k | } |
36 | | |
37 | | /* Function that can free aligned memory */ |
38 | 164k | static inline void zng_free(void *ptr) { |
39 | | #if defined(_WIN32) |
40 | | _aligned_free(ptr); |
41 | | #else |
42 | 164k | free(ptr); |
43 | 164k | #endif |
44 | 164k | } |
45 | | |
46 | | #endif |