Mercurial > hg > nginx
comparison src/os/unix/ngx_alloc.c @ 346:55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 06 Jun 2004 19:49:18 +0000 |
parents | |
children | f48d579daf78 |
comparison
equal
deleted
inserted
replaced
345:fade4edd61f8 | 346:55e496a8ece3 |
---|---|
1 | |
2 #include <ngx_config.h> | |
3 #include <ngx_core.h> | |
4 | |
5 | |
6 int ngx_pagesize; | |
7 | |
8 | |
9 void *ngx_alloc(size_t size, ngx_log_t *log) | |
10 { | |
11 void *p; | |
12 | |
13 if (!(p = malloc(size))) { | |
14 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | |
15 "malloc() " SIZE_T_FMT " bytes failed", size); | |
16 } | |
17 | |
18 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, | |
19 "malloc: " PTR_FMT ":" SIZE_T_FMT, p, size); | |
20 | |
21 return p; | |
22 } | |
23 | |
24 | |
25 void *ngx_calloc(size_t size, ngx_log_t *log) | |
26 { | |
27 void *p; | |
28 | |
29 p = ngx_alloc(size, log); | |
30 | |
31 if (p) { | |
32 ngx_memzero(p, size); | |
33 } | |
34 | |
35 return p; | |
36 } | |
37 | |
38 | |
39 #if (HAVE_POSIX_MEMALIGN) | |
40 | |
41 void *ngx_memalign(size_t aligment, size_t size, ngx_log_t *log) | |
42 { | |
43 void *p; | |
44 | |
45 if (posix_memalign(&p, aligment, size) == -1) { | |
46 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | |
47 "posix_memalign() " SIZE_T_FMT " bytes aligned to " | |
48 SIZE_T_FMT " failed", size, alignment); | |
49 } | |
50 | |
51 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, | |
52 "posix_memalign: " PTR_FMT ":" SIZE_T_FMT, p, size); | |
53 | |
54 return p; | |
55 } | |
56 | |
57 #esif (HAVE_MEMALIGN) | |
58 | |
59 void *ngx_memalign(size_t aligment, size_t size, ngx_log_t *log) | |
60 { | |
61 void *p; | |
62 | |
63 if (!(p = memalign(aligment, size))) { | |
64 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | |
65 "memalign() " SIZE_T_FMT " bytes aligned to " | |
66 SIZE_T_FMT " failed", size, alignment); | |
67 } | |
68 | |
69 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, | |
70 "memalign: " PTR_FMT ":" SIZE_T_FMT, p, size); | |
71 | |
72 return p; | |
73 } | |
74 | |
75 #endif |