1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*
* Copyright (C) Igor Sysoev
* Copyright (C) NGINX, Inc.
*/
#include <njs_main.h>
void *
njs_zalloc(size_t size)
{
void *p;
p = njs_malloc(size);
if (njs_fast_path(p != NULL)) {
njs_memzero(p, size);
}
return p;
}
#if (NJS_HAVE_POSIX_MEMALIGN)
/*
* posix_memalign() presents in Linux glibc 2.1.91, FreeBSD 7.0,
* Solaris 11, MacOSX 10.6 (Snow Leopard), NetBSD 5.0, OpenBSD 4.8.
*/
void *
njs_memalign(size_t alignment, size_t size)
{
int err;
void *p;
err = posix_memalign(&p, alignment, size);
if (njs_fast_path(err == 0)) {
return p;
}
return NULL;
}
#elif (NJS_HAVE_MEMALIGN)
/* memalign() presents in Solaris, HP-UX. */
void *
njs_memalign(size_t alignment, size_t size)
{
return memalign(alignment, size);
}
#else
#error no memalign() implementation.
#endif
|