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