home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume22 / archie / part01 / ptalloc.c < prev    next >
C/C++ Source or Header  |  1991-08-21  |  2KB  |  82 lines

  1. /*
  2.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <uw-copyright.h>.
  6.  */
  7.  
  8. #include <uw-copyright.h>
  9. #include <stdio.h>
  10.  
  11. #include <pfs.h>
  12. #include <pmachine.h> /* for correct definition of ZERO */
  13.  
  14. static PTEXT    free = NULL;
  15. int         ptext_count = 0;
  16. int        ptext_max = 0;
  17.  
  18. /*
  19.  * ptalloc - allocate and initialize ptext structure
  20.  *
  21.  *    PTALLOC returns a pointer to an initialized structure of type
  22.  *    PTEXT.  If it is unable to allocate such a structure, it
  23.  *    returns NULL.
  24.  */
  25. PTEXT
  26. ptalloc()
  27.     {
  28.     PTEXT    vt;
  29.     if(free) {
  30.         vt = free;
  31.         free = free->next;
  32.     }
  33.     else {
  34.         vt = (PTEXT) malloc(sizeof(PTEXT_ST));
  35.         if (!vt) return(NULL);
  36.         ptext_max++;
  37.     }
  38.     ptext_count++;
  39.  
  40.     /* nearly all parts are 0 [or NULL] */
  41.     ZERO(vt);
  42.     /* The offset is to leave room for additional headers */
  43.     vt->start = vt->dat + MAX_PTXT_HDR;
  44.  
  45.     return(vt);
  46.     }
  47.  
  48. /*
  49.  * ptfree - free a VTEXT structure
  50.  *
  51.  *    VTFREE takes a pointer to a VTEXT structure and adds it to
  52.  *    the free list for later reuse.
  53.  */
  54. ptfree(vt)
  55.     PTEXT    vt;
  56.     {
  57.     vt->next = free;
  58.     vt->previous = NULL;
  59.     free = vt;
  60.     ptext_count--;
  61.     }
  62.  
  63. /*
  64.  * ptlfree - free a VTEXT structure
  65.  *
  66.  *    VTLFREE takes a pointer to a VTEXT structure frees it and any linked
  67.  *    VTEXT structures.  It is used to free an entrie list of VTEXT
  68.  *    structures.
  69.  */
  70. ptlfree(vt)
  71.     PTEXT    vt;
  72.     {
  73.     PTEXT    nxt;
  74.  
  75.     while(vt != NULL) {
  76.         nxt = vt->next;
  77.         ptfree(vt);
  78.         vt = nxt;
  79.     }
  80.     }
  81.  
  82.