home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_04 / 8n04106a < prev    next >
Text File  |  1990-03-20  |  2KB  |  53 lines

  1.  
  2. Listing 3
  3. =========
  4.  
  5. /* Return all memory allocated to this ID */
  6.  
  7. /* NULL is returned on error */
  8.  
  9. unsigned int deiniz_borrow(id)
  10. register MemBlock *id;
  11. {
  12.    register MemBlock *nextone=id,   /* Pointer to next block */
  13.                      *thisone;      /* Pointer to pres block */
  14.                                     
  15.    while(thisone=nextone) {         /* While blocks to return */
  16.       nextone=thisone->mb_next;     /* Point to next block */
  17.       if(deallocate(thisone)==0)    /* Return this one */
  18.          return(NULL);
  19.    }
  20.  
  21.    return(id);                             /* Return non-zero */
  22. }
  23.  
  24.  
  25. /* ---------------------------------------------------------- */
  26.  
  27. /* Return all memory but the first block */
  28.  
  29. /* NULL is returned on error */
  30.  
  31. unsigned int return_borrow(id)
  32. register MemBlock *id;
  33. {
  34.    register MemBlock *nextone,       /* Pointer to next block */
  35.                      *thisone;       /* Pointer to pres block */
  36.  
  37.    /* Return all but first */
  38.    if(nextone=id->mb_next)           /* If anything to return */
  39.       while(thisone=nextone) {       /* While blocks to return */
  40.          nextone=thisone->mb_next;   /* Point to next block */
  41.          if(deallocate(thisone)==0)  /* Return this one */
  42.             return(NULL);
  43.       }
  44.  
  45.    /* Reset infomation in the first block */
  46.    id->mb_next=NULL;                 /* No next block */
  47.    id->mb_pres=id;                   /* This is the present one */
  48.    id->mb_offs=sizeof(MemBlock);     /* Reset offset */
  49.  
  50.    return(id);                       /* Return non-zero */
  51. }
  52.  
  53.