comparison src/core/ngx_hunk.c @ 166:389d7ee9fa60

nginx-0.0.1-2003-10-30-11:51:06 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 30 Oct 2003 08:51:06 +0000
parents e7e094d34162
children 8aef3c72e5da
comparison
equal deleted inserted replaced
165:894a01c6aea3 166:389d7ee9fa60
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 4
5 5
6 ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size, 6 ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size)
7 int before, int after)
8 { 7 {
9 ngx_hunk_t *h; 8 ngx_hunk_t *h;
10 9
11 ngx_test_null(h, ngx_palloc(pool, sizeof(ngx_hunk_t)), NULL); 10 ngx_test_null(h, ngx_alloc_hunk(pool), NULL);
12 11
13 ngx_test_null(h->pre_start, ngx_palloc(pool, size + before + after), NULL); 12 ngx_test_null(h->start, ngx_palloc(pool, size), NULL);
14 13
15 h->start = h->pos = h->last = h->pre_start + before; 14 h->pos = h->start;
16 h->file_pos = h->file_last = 0; 15 h->last = h->start;
16
17 h->file_pos = 0;
18 h->file_last = 0;
19
17 h->end = h->last + size; 20 h->end = h->last + size;
18 h->post_end = h->end + after;
19 21
20 h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY; 22 h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
21 h->file = NULL; 23 h->file = NULL;
22 h->shadow = NULL; 24 h->shadow = NULL;
23 25
63 } 65 }
64 66
65 *ll = NULL; 67 *ll = NULL;
66 68
67 return chain; 69 return chain;
68 }
69
70
71 ngx_hunk_t *ngx_create_hunk_before(ngx_pool_t *pool, ngx_hunk_t *hunk, int size)
72 {
73 ngx_hunk_t *h;
74
75 ngx_test_null(h, ngx_palloc(pool, sizeof(ngx_hunk_t)), NULL);
76
77 if (hunk->type & NGX_HUNK_TEMP && hunk->pos - hunk->pre_start >= size) {
78 /* keep hunk->start unchanged - used in restore */
79 h->pre_start = hunk->pre_start;
80 h->end = h->post_end = hunk->pre_start = hunk->pos;
81 h->start = h->pos = h->last = h->end - size;
82 h->file_pos = h->file_last = 0;
83
84 h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
85 h->file = NULL;
86 h->shadow = NULL;
87
88 h->tag = 0;
89
90 } else {
91 ngx_test_null(h->pre_start, ngx_palloc(pool, size), NULL);
92 h->start = h->pos = h->last = h->pre_start;
93 h->end = h->post_end = h->start + size;
94 h->file_pos = h->file_last = 0;
95
96 h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
97 h->file = NULL;
98 h->shadow = NULL;
99
100 h->tag = 0;
101 }
102
103 return h;
104 }
105
106
107 ngx_hunk_t *ngx_create_hunk_after(ngx_pool_t *pool, ngx_hunk_t *hunk, int size)
108 {
109 ngx_hunk_t *h;
110
111 ngx_test_null(h, ngx_palloc(pool, sizeof(ngx_hunk_t)), NULL);
112
113 if (hunk->type & NGX_HUNK_TEMP
114 && hunk->last == hunk->end
115 && hunk->post_end - hunk->end >= size)
116 {
117 h->post_end = hunk->post_end;
118 h->pre_start = h->start = h->pos = h->last = hunk->post_end =
119 hunk->last;
120 h->file_pos = h->file_last = 0;
121
122 h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
123 h->file = NULL;
124 h->shadow = NULL;
125
126 h->tag = 0;
127
128 } else {
129 ngx_test_null(h->pre_start, ngx_palloc(pool, size), NULL);
130 h->start = h->pos = h->last = h->pre_start;
131 h->end = h->post_end = h->start + size;
132 h->file_pos = h->file_last = 0;
133
134 h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
135 h->file = NULL;
136 h->shadow = NULL;
137
138 h->tag = 0;
139 }
140
141 return h;
142 } 70 }
143 71
144 72
145 int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in) 73 int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in)
146 { 74 {