comparison src/os/unix/ngx_alloc.c @ 0:f0b350454894 NGINX_0_1_0

nginx 0.1.0 *) The first public version.
author Igor Sysoev <http://sysoev.ru>
date Mon, 04 Oct 2004 00:00:00 +0400
parents
children 46833bd150cb
comparison
equal deleted inserted replaced
-1:000000000000 0:f0b350454894
1
2 /*
3 * Copyright (C) Igor Sysoev
4 */
5
6
7 #include <ngx_config.h>
8 #include <ngx_core.h>
9
10
11 int ngx_pagesize;
12
13
14 void *ngx_alloc(size_t size, ngx_log_t *log)
15 {
16 void *p;
17
18 if (!(p = malloc(size))) {
19 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
20 "malloc() " SIZE_T_FMT " bytes failed", size);
21 }
22
23 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
24 "malloc: " PTR_FMT ":" SIZE_T_FMT, p, size);
25
26 return p;
27 }
28
29
30 void *ngx_calloc(size_t size, ngx_log_t *log)
31 {
32 void *p;
33
34 p = ngx_alloc(size, log);
35
36 if (p) {
37 ngx_memzero(p, size);
38 }
39
40 return p;
41 }
42
43
44 #if (HAVE_POSIX_MEMALIGN)
45
46 void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
47 {
48 void *p;
49
50 if (posix_memalign(&p, alignment, size) == -1) {
51 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
52 "posix_memalign() " SIZE_T_FMT " bytes aligned to "
53 SIZE_T_FMT " failed", size, alignment);
54 }
55
56 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
57 "posix_memalign: " PTR_FMT ":" SIZE_T_FMT, p, size);
58
59 return p;
60 }
61
62 #elif (HAVE_MEMALIGN)
63
64 void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
65 {
66 void *p;
67
68 if (!(p = memalign(alignment, size))) {
69 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
70 "memalign() " SIZE_T_FMT " bytes aligned to "
71 SIZE_T_FMT " failed", size, alignment);
72 }
73
74 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
75 "memalign: " PTR_FMT ":" SIZE_T_FMT, p, size);
76
77 return p;
78 }
79
80 #endif