home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE2.TAR / ptalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-21  |  1.5 KB  |  84 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.  * <copyright.h>.
  6.  */
  7.  
  8. #include <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. void
  55. ptfree(vt)
  56.     PTEXT    vt;
  57.     {
  58.     vt->next = free;
  59.     vt->previous = NULL;
  60.     free = vt;
  61.     ptext_count--;
  62.     }
  63.  
  64. /*
  65.  * ptlfree - free a VTEXT structure
  66.  *
  67.  *    VTLFREE takes a pointer to a VTEXT structure frees it and any linked
  68.  *    VTEXT structures.  It is used to free an entrie list of VTEXT
  69.  *    structures.
  70.  */
  71. void
  72. ptlfree(vt)
  73.     PTEXT    vt;
  74.     {
  75.     PTEXT    nxt;
  76.  
  77.     while(vt != NULL) {
  78.         nxt = vt->next;
  79.         ptfree(vt);
  80.         vt = nxt;
  81.     }
  82.     }
  83.  
  84.