Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #include <ngx_config.h>
0009 #include <ngx_core.h>
0010 
0011 
0012 ngx_list_t *
0013 ngx_list_create(ngx_pool_t *pool, ngx_uint_t n, size_t size)
0014 {
0015     ngx_list_t  *list;
0016 
0017     list = ngx_palloc(pool, sizeof(ngx_list_t));
0018     if (list == NULL) {
0019         return NULL;
0020     }
0021 
0022     if (ngx_list_init(list, pool, n, size) != NGX_OK) {
0023         return NULL;
0024     }
0025 
0026     return list;
0027 }
0028 
0029 
0030 void *
0031 ngx_list_push(ngx_list_t *l)
0032 {
0033     void             *elt;
0034     ngx_list_part_t  *last;
0035 
0036     last = l->last;
0037 
0038     if (last->nelts == l->nalloc) {
0039 
0040         /* the last part is full, allocate a new list part */
0041 
0042         last = ngx_palloc(l->pool, sizeof(ngx_list_part_t));
0043         if (last == NULL) {
0044             return NULL;
0045         }
0046 
0047         last->elts = ngx_palloc(l->pool, l->nalloc * l->size);
0048         if (last->elts == NULL) {
0049             return NULL;
0050         }
0051 
0052         last->nelts = 0;
0053         last->next = NULL;
0054 
0055         l->last->next = last;
0056         l->last = last;
0057     }
0058 
0059     elt = (char *) last->elts + l->size * last->nelts;
0060     last->nelts++;
0061 
0062     return elt;
0063 }