2002-08-07 00:39:45 +08:00
|
|
|
|
|
|
|
#include <ngx_hunk.h>
|
|
|
|
|
|
|
|
|
2002-09-02 22:48:24 +08:00
|
|
|
ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size,
|
|
|
|
int before, int after)
|
2002-08-07 00:39:45 +08:00
|
|
|
{
|
|
|
|
ngx_hunk_t *h = ngx_palloc(pool, sizeof(ngx_hunk_t));
|
|
|
|
|
2002-09-02 22:48:24 +08:00
|
|
|
#if !(HAVE_OFFSET_EQUAL_PTR)
|
2002-08-16 01:20:26 +08:00
|
|
|
h->pos.file = h->last.file = 0;
|
2002-08-07 00:39:45 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
h->pre_start = ngx_palloc(pool, size + before + after);
|
2002-08-16 01:20:26 +08:00
|
|
|
h->start = h->pos.mem = h->last.mem = h->pre_start + before;
|
|
|
|
h->end = h->last.mem + size;
|
2002-08-07 00:39:45 +08:00
|
|
|
h->post_end = h->end + after;
|
|
|
|
|
|
|
|
h->type = NGX_HUNK_TEMP;
|
|
|
|
h->tag = 0;
|
2002-09-02 22:48:24 +08:00
|
|
|
h->file = NULL;
|
2002-08-07 00:39:45 +08:00
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2002-09-02 22:48:24 +08:00
|
|
|
ngx_hunk_t *ngx_create_hunk_before(ngx_pool_t *pool, ngx_hunk_t *hunk, int size)
|
2002-08-07 00:39:45 +08:00
|
|
|
{
|
|
|
|
ngx_hunk_t *h = ngx_palloc(pool, sizeof(ngx_hunk_t));
|
|
|
|
|
2002-09-02 22:48:24 +08:00
|
|
|
#if !(HAVE_OFFSET_EQUAL_PTR)
|
2002-08-16 01:20:26 +08:00
|
|
|
h->pos.file = h->last.file = 0;
|
2002-08-07 00:39:45 +08:00
|
|
|
#endif
|
|
|
|
|
2002-08-16 01:20:26 +08:00
|
|
|
if (hunk->type & NGX_HUNK_TEMP && hunk->pos.mem - hunk->pre_start >= size) {
|
2002-08-07 00:39:45 +08:00
|
|
|
/* keep hunk->start unchanged - used in restore */
|
|
|
|
h->pre_start = hunk->pre_start;
|
2002-08-16 01:20:26 +08:00
|
|
|
h->end = h->post_end = hunk->pre_start = hunk->pos.mem;
|
|
|
|
h->start = h->pos.mem = h->last.mem = h->end - size;
|
2002-08-07 00:39:45 +08:00
|
|
|
|
|
|
|
h->type = NGX_HUNK_TEMP;
|
|
|
|
h->tag = 0;
|
2002-09-02 22:48:24 +08:00
|
|
|
h->file = NULL;
|
2002-08-07 00:39:45 +08:00
|
|
|
|
|
|
|
} else {
|
2002-08-16 01:20:26 +08:00
|
|
|
h->pre_start = h->start = h->pos.mem = h->last.mem
|
|
|
|
= ngx_palloc(pool, size);
|
2002-08-07 00:39:45 +08:00
|
|
|
h->end = h->post_end = h->start + size;
|
|
|
|
|
|
|
|
h->type = NGX_HUNK_TEMP;
|
|
|
|
h->tag = 0;
|
2002-09-02 22:48:24 +08:00
|
|
|
h->file = NULL;
|
2002-08-07 00:39:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2002-09-02 22:48:24 +08:00
|
|
|
ngx_hunk_t *ngx_create_hunk_after(ngx_pool_t *pool, ngx_hunk_t *hunk, int size)
|
2002-08-07 00:39:45 +08:00
|
|
|
{
|
|
|
|
ngx_hunk_t *h = ngx_palloc(pool, sizeof(ngx_hunk_t));
|
|
|
|
|
2002-09-02 22:48:24 +08:00
|
|
|
#if !(HAVE_OFFSET_EQUAL_PTR)
|
2002-08-16 01:20:26 +08:00
|
|
|
h->pos.file = h->last.file = 0;
|
2002-08-07 00:39:45 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (hunk->type & NGX_HUNK_TEMP
|
2002-08-16 01:20:26 +08:00
|
|
|
&& hunk->last.mem == hunk->end
|
2002-08-07 00:39:45 +08:00
|
|
|
&& hunk->post_end - hunk->end >= size)
|
|
|
|
{
|
|
|
|
h->post_end = hunk->post_end;
|
2002-08-16 01:20:26 +08:00
|
|
|
h->pre_start = h->start = h->pos.mem = h->last.mem = hunk->post_end =
|
|
|
|
hunk->last.mem;
|
2002-08-07 00:39:45 +08:00
|
|
|
h->type = NGX_HUNK_TEMP;
|
|
|
|
h->tag = 0;
|
2002-09-02 22:48:24 +08:00
|
|
|
h->file = NULL;
|
2002-08-07 00:39:45 +08:00
|
|
|
|
|
|
|
} else {
|
2002-08-16 01:20:26 +08:00
|
|
|
h->pre_start = h->start = h->pos.mem = h->last.mem =
|
|
|
|
ngx_palloc(pool, size);
|
2002-08-07 00:39:45 +08:00
|
|
|
h->end = h->post_end = h->start + size;
|
|
|
|
|
|
|
|
h->type = NGX_HUNK_TEMP;
|
|
|
|
h->tag = 0;
|
2002-09-02 22:48:24 +08:00
|
|
|
h->file = NULL;
|
2002-08-07 00:39:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|