home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / CUJJUN93.ZIP / 1106112B < prev    next >
Text File  |  1993-04-19  |  1KB  |  59 lines

  1.     typedef char * Buffer;
  2.  
  3.     void Buffer_initialize(char ** pointer);
  4.     int Buffer_allocate(char ** pointer, size_t size,
  5.         char * name);
  6.     void Buffer_terminate(char ** pointer);
  7.  
  8.     int some_function(void)
  9.         {
  10.         Buffer buffer1, buffer2;
  11.         int ret1, ret2;
  12.  
  13.         Buffer_initialize(&buffer1);
  14.         Buffer_initialize(&buffer2);
  15.  
  16.         if (Buffer_allocate(&buffer1, 1024, "buffer1") 
  17.             == SUCCESS
  18.             && Buffer_allocate(&buffer2, 1024, "buffer2") 
  19.             == SUCCESS)
  20.             {
  21.             /* Do whatever processing is required. */
  22.             }
  23.         Buffer_terminate(&buffer1);
  24.         Buffer_terminate(&buffer2);
  25.         }
  26.  
  27.     void Buffer_initialize(Buffer * buffer)
  28.         {
  29.         *buffer = NULL:
  30.         return;
  31.         }
  32.  
  33.     int Buffer_allocate(Buffer * pointer, size_t size,
  34.         char * name)
  35.         {
  36.         int return_code = SUCCESS;
  37.         *pointer = malloc(size);
  38.         if (*pointer == NULL)
  39.             {
  40.  
  41.             fprintf(stderr, "Allocation failure for %s size %d",
  42.                 name, size);
  43.             return_code = FAILUE;
  44.             }
  45.         return return_code;
  46.         }
  47.  
  48.     void Buffer_terminate(Buffer * pointer)
  49.         {
  50.         if (*pointer != NULL)
  51.             {
  52.             free(*pointer);
  53.             *pointer = NULL;
  54.             }
  55.         return;
  56.         }
  57.  
  58.  
  59.