home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE0.TAR / vlalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-27  |  2.3 KB  |  107 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. vlfree(vl)
  61.     VLINK    vl;
  62.     {
  63.         extern int string_count;
  64.  
  65.     if(vl->dontfree) return;
  66.     /* many of these don't need to call stfree(); since a check
  67.        for pointer validity's already done before even calling
  68.        it, we can just call free() here then do one big decrement
  69.        of string_count at the end.  */
  70.     if(vl->name) free(vl->name);
  71.     stfree(vl->type);
  72.     if(vl->replicas) vllfree(vl->replicas);
  73.     stfree(vl->hosttype);
  74.     if(vl->host) free(vl->host);
  75.     stfree(vl->nametype);
  76.     if(vl->filename) free(vl->filename);
  77.     if(vl->args) free(vl->args);
  78.     if(vl->lattrib) atlfree(vl->lattrib);
  79.     /* No allocation routines for f_info yet */
  80.     vl->f_info = NULL;
  81.     vl->next = lfree;
  82.     vl->previous = NULL;
  83.     lfree = vl;
  84.     vlink_count--;
  85.     string_count -= 4; /* freed name, host, filename, and args */
  86.     }
  87.  
  88. /*
  89.  * vllfree - free a VLINK structure
  90.  *
  91.  *    VLLFREE takes a pointer to a VLINK structure frees it and any linked
  92.  *    VLINK structures.  It is used to free an entrie list of VLINK
  93.  *    structures.
  94.  */
  95. vllfree(vl)
  96.     VLINK    vl;
  97.     {
  98.     VLINK    nxt;
  99.  
  100.     while((vl != NULL) && !vl->dontfree) {
  101.         nxt = vl->next;
  102.         vlfree(vl);
  103.         vl = nxt;
  104.     }
  105.     }
  106.  
  107.