src/list.c
/*
 * Allocate a chain of linked nodes. Set data to NULL.
 * Returns the head of the list, and puts the tail in out_tail.
 */
Allocate a chain of linked nodes. Set data to NULL.
Returns the head of the list, and puts the tail in out_tail.
Allocate a chain of linked nodes . Set data to NULL . Returns the head of the list and puts the tail in out_tail .
static golle_list_node_t *alloc_linked_nodes (size_t size, 
					      size_t num,
					      golle_list_node_t **out_tail) 
{
  golle_list_node_t
    *head, *tail;
  head = NULL;
  tail = NULL;
  for (size_t i = 0; i < num; i++) {
    golle_list_node_t *node = malloc(size);
    if (!node) {
      free_linked_nodes (head);
      return NULL;
    }
    memset(node, 0, size);
    if (!head) {
      head = node;
    }
    if (tail) {
      tail->next = node;
    }
    tail = node;
  }
  if (out_tail) {
    *out_tail = tail;
  }
  return head;
}
static golle_list_node_t * alloc_linked_nodes ( size_t size , size_t num , golle_list_node_t * * out_tail ) { golle_list_node_t * head , * tail ; head = NULL ; tail = NULL ; for ( size_t i = 0 ; i < num ; i ++ ) { golle_list_node_t * node = malloc ( size ) ; if ( ! node ) { free_linked_nodes ( head ) ; return NULL ; } memset ( node , 0 , size ) ; if ( ! head ) { head = node ; } if ( tail ) { tail -> next = node ; } tail = node ; } if ( out_tail ) { * out_tail = tail ; } return head ; }
Allocate a chain of linked nodes.
Allocate a chain of linked nodes .
/* Allocate each node. If one fails, they all fail. */