Initializer / Cleanup

Initialization

typedef void (*ntl_init_cb)(void*)

Null-terminated list initialization callback.

Callback function that will be called for each element of the NTL during initialization

ntl_t ntl_calloc_init(size_t nelems, size_t elem_size, ntl_init_cb init_cb)

Initialize a null-terminated list and each of its elements.

Initialize a NTL and fill n nelems of size elem_size with zeroes, and call init for each element.

Note

if init is NULL, it is the same as ntl_calloc

Parameters
  • nelems – the amount of elements for the NTL

  • elem_size – the size of each NTL element

  • init – the callback function to be called for each element initialized

Returns

the null-terminated list

ntl_t ntl_calloc(size_t nelems, size_t elem_size)

Initialize a null-terminated list.

Initialize a NTL and fill n nelems of size elem_size with zeroes

Parameters
  • nelems – the amount of elements for the NTL

  • elem_size – the size of each NTL element

Returns

the null-terminated list

ntl_t ntl_malloc(size_t nelems, size_t elem_size)

Initialize a null-terminated list.

Warning

use ntl_calloc() unless there’s a good reason to use this

Parameters
  • nelems – the amount of elements of the NTL

  • elem_size – the size of each NTL element

Returns

the null-terminated list

ntl_t ntl_malloc_init(size_t nelems, size_t elem_size, ntl_init_cb init_cb)

Initialize a null-terminated list and each of its elements.

Note

if init is NULL, it is the same as ntl_calloc

Warning

use ntl_calloc_init() unless there’s a good reason to use this

Parameters
  • nelems – the amount of elements of the NTL

  • elem_size – the size of each NTL element

  • init – the callback function to be called for each element initialized

Returns

the null-terminated list

ntl_t ntl_realloc_init(ntl_t p, size_t nelems, size_t elem_size, ntl_init_cb init)

Changes the size of the null-terminated list.

Changes the size of the NTL memory block pointed by p to nelems * elem_size bytes, call init for each element.

Parameters
  • p – the NTL to be resized

  • nelems – the amount of elements of the NTL

  • elem_size – the size of each NTL element

  • init – the callback function to be called for each element initialized

Returns

the null-terminated list

ntl_t ntl_dup(ntl_t p, size_t elem_size)

Duplicate a null-terminated list.

Parameters
  • p – pointer to the source NTL

  • elem_size – the size of each NTL element

Returns

the NTL duplicate

Cleanup

typedef void (*ntl_free_cb)(void*)

Null-terminated list cleanup callback.

Callback function that will be called for each element of the NTL during cleanup

void ntl_free(ntl_t p, ntl_free_cb cleanup)

Cleanup a null-terminated list.

Call cleanup callback for each element of the NTL, and then free() the NTL p pointer.

Parameters
  • p – the NTL to be free’d

  • cleanup – the cleanup callback to be called for each element