nginx/src/core/ngx_hunk.c

100 lines
2.6 KiB
C
Raw Normal View History

2002-12-27 15:27:47 +08:00
#include <ngx_config.h>
2003-06-03 23:42:58 +08:00
#include <ngx_core.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-09-27 00:50:29 +08:00
ngx_hunk_t *h;
ngx_test_null(h, ngx_palloc(pool, sizeof(ngx_hunk_t)), NULL);
2002-09-27 00:50:29 +08:00
ngx_test_null(h->pre_start, ngx_palloc(pool, size + before + after), NULL);
2003-03-12 04:38:13 +08:00
h->start = h->pos = h->last = h->pre_start + before;
h->file_pos = h->file_last = 0;
h->end = h->last + size;
h->post_end = h->end + after;
2003-03-12 04:38:13 +08:00
h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
2002-09-02 22:48:24 +08:00
h->file = NULL;
2003-04-15 23:06:52 +08:00
h->shadow = NULL;
h->tag = 0;
return h;
}
2003-05-21 21:28:21 +08:00
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)
2003-05-21 21:28:21 +08:00
{
2002-09-27 00:50:29 +08:00
ngx_hunk_t *h;
ngx_test_null(h, ngx_palloc(pool, sizeof(ngx_hunk_t)), NULL);
2003-03-12 04:38:13 +08:00
if (hunk->type & NGX_HUNK_TEMP && hunk->pos - hunk->pre_start >= size) {
/* keep hunk->start unchanged - used in restore */
h->pre_start = hunk->pre_start;
2003-03-12 04:38:13 +08:00
h->end = h->post_end = hunk->pre_start = hunk->pos;
h->start = h->pos = h->last = h->end - size;
h->file_pos = h->file_last = 0;
2003-03-12 04:38:13 +08:00
h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
2002-09-02 22:48:24 +08:00
h->file = NULL;
2003-04-15 23:06:52 +08:00
h->shadow = NULL;
h->tag = 0;
} else {
2002-09-27 00:50:29 +08:00
ngx_test_null(h->pre_start, ngx_palloc(pool, size), NULL);
2003-05-21 21:28:21 +08:00
h->start = h->pos = h->last = h->pre_start;
h->end = h->post_end = h->start + size;
2003-03-12 04:38:13 +08:00
h->file_pos = h->file_last = 0;
2003-03-12 04:38:13 +08:00
h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
2002-09-02 22:48:24 +08:00
h->file = NULL;
2003-04-15 23:06:52 +08:00
h->shadow = NULL;
h->tag = 0;
}
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-09-27 00:50:29 +08:00
ngx_hunk_t *h;
ngx_test_null(h, ngx_palloc(pool, sizeof(ngx_hunk_t)), NULL);
if (hunk->type & NGX_HUNK_TEMP
2003-03-12 04:38:13 +08:00
&& hunk->last == hunk->end
&& hunk->post_end - hunk->end >= size)
{
h->post_end = hunk->post_end;
2003-03-12 04:38:13 +08:00
h->pre_start = h->start = h->pos = h->last = hunk->post_end =
hunk->last;
h->file_pos = h->file_last = 0;
h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
2002-09-02 22:48:24 +08:00
h->file = NULL;
2003-04-15 23:06:52 +08:00
h->shadow = NULL;
h->tag = 0;
} else {
2002-09-27 00:50:29 +08:00
ngx_test_null(h->pre_start, ngx_palloc(pool, size), NULL);
2003-05-21 21:28:21 +08:00
h->start = h->pos = h->last = h->pre_start;
h->end = h->post_end = h->start + size;
2003-03-12 04:38:13 +08:00
h->file_pos = h->file_last = 0;
2003-03-12 04:38:13 +08:00
h->type = NGX_HUNK_TEMP|NGX_HUNK_IN_MEMORY;
2002-09-02 22:48:24 +08:00
h->file = NULL;
2003-04-15 23:06:52 +08:00
h->shadow = NULL;
h->tag = 0;
}
return h;
}