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