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 / vlalloc.c < prev   
Encoding:
C/C++ Source or Header  |  1994-10-10  |  2.3 KB  |  114 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 <string.h>
  12.  
  13. #include <stdlib.h>
  14. #include <time.h>
  15.  
  16. #include <pfs.h>
  17. #include <pmachine.h>
  18.  
  19. static VLINK    lfree = NULL;
  20. int        vlink_count = 0;
  21. int        vlink_max = 0;
  22.  
  23. /*
  24.  * vlalloc - allocate and initialize vlink structure
  25.  *
  26.  *    VLALLOC returns a pointer to an initialized structure of type
  27.  *    VLINK.  If it is unable to allocate such a structure, it
  28.  *    returns NULL.
  29.  */
  30. VLINK
  31. vlalloc()
  32.     {
  33.     VLINK    vl;
  34.     if(lfree) {
  35.         vl = lfree;
  36.         lfree = lfree->next;
  37.     }
  38.     else {
  39.         vl = (VLINK) malloc(sizeof(VLINK_ST));
  40.         if (!vl) return(NULL);
  41.         vlink_max++;
  42.     }
  43.  
  44.     vlink_count++;
  45.  
  46.     /* Initialize and fill in default values */
  47.     /* Since all but four are set to a zero-value,
  48.        why not just wipe it clean?  */
  49.     ZERO(vl);
  50.  
  51.     vl->linktype = 'L';
  52.     vl->type = stcopy("FILE");
  53.     vl->hosttype = stcopy("INTERNET-D");
  54.     vl->nametype = stcopy("ASCII");
  55.  
  56.     return(vl);
  57.     }
  58.  
  59. /*
  60.  * vlfree - free a VLINK structure
  61.  *
  62.  *    VLFREE takes a pointer to a VLINK structure and adds it to
  63.  *    the free list for later reuse.
  64.  */
  65. void
  66. vlfree(vl)
  67.     VLINK    vl;
  68.     {
  69.         extern int string_count;
  70.  
  71.     if(vl->dontfree) return;
  72.     /* many of these don't need to call stfree(); since a check
  73.        for pointer validity's already done before even calling
  74.        it, we can just call free() here then do one big decrement
  75.        of string_count at the end.  */
  76.     if(vl->name) free(vl->name);
  77.     stfree(vl->type);
  78.     if(vl->replicas) vllfree(vl->replicas);
  79.     stfree(vl->hosttype);
  80.     if(vl->host) free(vl->host);
  81.     stfree(vl->nametype);
  82.     if(vl->filename) free(vl->filename);
  83.     if(vl->args) free(vl->args);
  84.     if(vl->lattrib) atlfree(vl->lattrib);
  85.     /* No allocation routines for f_info yet */
  86.     vl->f_info = NULL;
  87.     vl->next = lfree;
  88.     vl->previous = NULL;
  89.     lfree = vl;
  90.     vlink_count--;
  91.     string_count -= 4; /* freed name, host, filename, and args */
  92.     }
  93.  
  94. /*
  95.  * vllfree - free a VLINK structure
  96.  *
  97.  *    VLLFREE takes a pointer to a VLINK structure frees it and any linked
  98.  *    VLINK structures.  It is used to free an entrie list of VLINK
  99.  *    structures.
  100.  */
  101. void
  102. vllfree(vl)
  103.     VLINK    vl;
  104.     {
  105.     VLINK    nxt;
  106.  
  107.     while((vl != NULL) && !vl->dontfree) {
  108.         nxt = vl->next;
  109.         vlfree(vl);
  110.         vl = nxt;
  111.     }
  112.     }
  113.  
  114.