| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

node_create

#include "sflnode.h"
void *
node_create (
    void *after,
    size_t size)

Synopsis

Creates a new node with the specified size, and attaches it to the linked list after the specified node. Initialises all fields in the node (except the main list pointers) to binary zeroes. If the 'after' argument is null, initialises but does not attach the node. Returns a pointer to the newly-created node, or NULL if there was not enough memory.

Examples

    typedef struct {
        void *prev, *next;
        long data;
    } BLOCK;

    NODE head;
    BLOCK *pointer;

    //  Initialise head of list
    node_reset (&head);

    //  Attach new block to start of list
    pointer = (BLOCK *) node_create (&head, sizeof (BLOCK));
    pointer-> data = 1;

    //  Attach new block to end of list
    pointer = (BLOCK *) node_create (head.prev, sizeof (BLOCK));
    pointer-> data = 1000;

Source Code - (sflnode.c)

{
    NODE
        *node;                          /*  Allocated node                   */

    ASSERT (size > 0);

    if ((node = mem_alloc (size)) != NULL)
      {
        memset (node, 0, size);
        node_reset (node);              /*  Initialise node pointers         */
        if (after)                      /*  Link into list if required       */
            node relink after (node, after);
      }
    return (node);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation