next up previous contents
Next: Status and State Up: Functions Previous: Functions

Initialization

NAME
    
DLL_CreateList, DLL_InitializeList, DLL_DestroyList, -- Initialization Functions.

SYNOPSIS
#include <linklist.h>

List *DLL_CreateList(List **list);
DLL_Return DLL_InitializeList(List *list, size_t infosize);
void DLL_DestroyList(List **list);

DESCRIPTION
    
The initialization group of functions must be used in the allocation and freeing of memory used by the link list.

DLL_CreateList
    
This function is called first to create the environment of the link list package. It is passed list, a pointer to a pointer, of the Top Level Struct type List. This pointer is returned both as the return value of the function and in the argument list.

DLL_InitializeList
    
After defining the Info structure this function is called to initialize the environment. Its first argument, list, is the value returned from DLL_CreateList and the second argument, infosize, is the size in bytes of the Info structure. The value DLL_ZERO_INFO is returned if infosize is zero; DLL_NULL_LIST if the pointer list is NULL; and DLL_NORMAL if the initialization was successful.

DLL_DestroyList
    
Upon exiting the application this function when called will free all memory allocated during this instance of the list. It is passed list, the value returned from DLL_CreateList, and has no return value of its own; however, the argument list is set to NULL.

EXAMPLE
#include <stdio.h>
#include <stdlib.h>
#include <linklist.h>


typedef struct name_addr    /* Sample data structure */
   {
   char name[30];
   char street[40];
   char city[22];
   char state[3];
   char zip[11];
   } NameAddr;

void main(void)
   {
   List *NAList = NULL;
   DLL_Return DLL_Exit;

   if(DLL_CreateList(&NAList) == NULL)
      {
      fputs("Fatal Memory error", stderr);
      exit(EXIT_FAILURE);
      }

   if((DLL_Exit = DLL_InitializeList(NAList, sizeof(NameAddr)))
    != DLL_NORMAL)
      {
      (void)(DLL_Exit == DLL_ZERO_INFO
       && fputs("Size of address record is zero.\n\n", stderr));
      (void)(DLL_Exit == DLL_NULL_LIST
       && fputs("NAList points to a NULL address.\n\n", stderr));
      exit(EXIT_FAILURE);
      }

   DoYourThingHere(NAList);

   DLL_DestroyList(&NAList);
   exit(EXIT_SUCCESS);
   }


next up previous contents
Next: Status and State Up: Functions Previous: Functions
Carl John Nobile
1999-07-07