Skip to content

Commit d48e11a

Browse files
committed
nginx-sys: define ngx_list_init
like many of the functions defined in nginx-sys, this is defined in nginx as an inline function in a C header, so it isnt captured by bindgen.
1 parent 6ff537e commit d48e11a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

nginx-sys/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,34 @@ pub fn ngx_timeofday() -> &'static ngx_time_t {
183183
unsafe { &*ngx_cached_time }
184184
}
185185

186+
/// Initialize a list, using a pool for the backing memory, with capacity to store the given number
187+
/// of elements and element size.
188+
///
189+
/// # Safety
190+
/// * `list` must be non-null
191+
/// * `pool` must be a valid pool
192+
#[inline]
193+
pub unsafe fn ngx_list_init(
194+
list: *mut ngx_list_t,
195+
pool: *mut ngx_pool_t,
196+
n: ngx_uint_t,
197+
size: usize,
198+
) -> ngx_int_t {
199+
unsafe {
200+
(*list).part.elts = ngx_palloc(pool, n * size);
201+
if (*list).part.elts.is_null() {
202+
return NGX_ERROR as ngx_int_t;
203+
}
204+
(*list).part.nelts = 0;
205+
(*list).part.next = core::ptr::null_mut();
206+
(*list).last = core::ptr::from_mut(&mut (*list).part);
207+
(*list).size = size;
208+
(*list).nalloc = n;
209+
(*list).pool = pool;
210+
NGX_OK as ngx_int_t
211+
}
212+
}
213+
186214
/// Add a key-value pair to an nginx table entry (`ngx_table_elt_t`) in the given nginx memory pool.
187215
///
188216
/// # Arguments

0 commit comments

Comments
 (0)