home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / ARCHIE-1.2 / PTALLOC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-04  |  1.7 KB  |  87 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. #ifdef MSDOS
  14. # define free _pfree   /* otherwise we get conflicts with free() */
  15. #endif
  16.  
  17. static PTEXT    free = NULL;
  18. int         ptext_count = 0;
  19. int        ptext_max = 0;
  20.  
  21. /*
  22.  * ptalloc - allocate and initialize ptext structure
  23.  *
  24.  *    PTALLOC returns a pointer to an initialized structure of type
  25.  *    PTEXT.  If it is unable to allocate such a structure, it
  26.  *    returns NULL.
  27.  */
  28. PTEXT
  29. ptalloc()
  30.     {
  31.     PTEXT    vt;
  32.     if(free) {
  33.         vt = free;
  34.         free = free->next;
  35.     }
  36.     else {
  37.         vt = (PTEXT) malloc(sizeof(PTEXT_ST));
  38.         if (!vt) return(NULL);
  39.         ptext_max++;
  40.     }
  41.     ptext_count++;
  42.  
  43.     /* nearly all parts are 0 [or NULL] */
  44.     ZERO(vt);
  45.     /* The offset is to leave room for additional headers */
  46.     vt->start = vt->dat + MAX_PTXT_HDR;
  47.  
  48.     return(vt);
  49.     }
  50.  
  51. /*
  52.  * ptfree - free a VTEXT structure
  53.  *
  54.  *    VTFREE takes a pointer to a VTEXT structure and adds it to
  55.  *    the free list for later reuse.
  56.  */
  57. void
  58. ptfree(vt)
  59.     PTEXT    vt;
  60.     {
  61.     vt->next = free;
  62.     vt->previous = NULL;
  63.     free = vt;
  64.     ptext_count--;
  65.     }
  66.  
  67. /*
  68.  * ptlfree - free a VTEXT structure
  69.  *
  70.  *    VTLFREE takes a pointer to a VTEXT structure frees it and any linked
  71.  *    VTEXT structures.  It is used to free an entrie list of VTEXT
  72.  *    structures.
  73.  */
  74. void
  75. ptlfree(vt)
  76.     PTEXT    vt;
  77.     {
  78.     PTEXT    nxt;
  79.  
  80.     while(vt != NULL) {
  81.         nxt = vt->next;
  82.         ptfree(vt);
  83.         vt = nxt;
  84.     }
  85.     }
  86.  
  87.