ptalloc.c
上传用户:sddyfurun
上传日期:2007-01-04
资源大小:525k
文件大小:3k
源码类别:

代理服务器

开发平台:

Unix_Linux

  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. #include "pmachine.h"
  7. #include "pfs.h"
  8. static PTEXT freep = NULL;
  9. int  ptext_count = 0;
  10. int ptext_max = 0;
  11. /*                                                                           */
  12. /*  * ptalloc - allocate and initialize ptext structure                      */
  13. /*  *                                                                        */
  14. /*  * PTALLOC returns a pointer to an initialized structure of type          */
  15. /*  * PTEXT.  If it is unable to allocate such a structure, it               */
  16. /*  * returns NULL.                                                          */
  17. PTEXT
  18. ptalloc()
  19.     {
  20. PTEXT vt;
  21. if(freep) {
  22.     vt = freep;
  23.     freep = freep->next;
  24. }
  25. else {
  26.     vt = (PTEXT) malloc(sizeof(PTEXT_ST));
  27.     if (!vt) return(NULL);
  28.     ptext_max++;
  29. }
  30. ptext_count++;
  31. /* nearly all parts are 0 [or NULL]                                  */
  32. ZERO(vt);
  33. /* The offset is to leave room for additional headers                */
  34. vt->start = vt->dat + MAX_PTXT_HDR;
  35. return(vt);
  36.     }
  37. /*                                                                           */
  38. /*  * ptfree - free a VTEXT structure                                        */
  39. /*  *                                                                        */
  40. /*  * VTFREE takes a pointer to a VTEXT structure and adds it to             */
  41. /*  * the free list for later reuse.                                         */
  42. void
  43. ptfree(vt)
  44.     PTEXT vt;
  45.     {
  46. vt->next = freep;
  47. vt->previous = NULL;
  48. freep = vt;
  49. ptext_count--;
  50.     }
  51. /*                                                                           */
  52. /*  * ptlfree - free a VTEXT structure                                       */
  53. /*  *                                                                        */
  54. /*  * VTLFREE takes a pointer to a VTEXT structure frees it and any linked   */
  55. /*  * VTEXT structures.  It is used to free an entrie list of VTEXT          */
  56. /*  * structures.                                                            */
  57. void
  58. ptlfree(vt)
  59.     PTEXT vt;
  60.     {
  61. PTEXT nxt;
  62. while(vt != NULL) {
  63.     nxt = vt->next;
  64.     ptfree(vt);
  65.     vt = nxt;
  66. }
  67.     }