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