home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / network / grn1src.lha / memalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-28  |  2.3 KB  |  115 lines

  1.  
  2. #include "defs.h"
  3.  
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. #if 0
  8. /* DEBUG support */
  9.  
  10. void *grn_malloc (const char *str, const long size)
  11. {
  12.         static FILE *debug = 0;
  13.  
  14.         debug = fopen ("t:grn_debug", "a");
  15.         fprintf (debug, "m:%s = %ld\n", str, size);
  16.         fclose (debug);
  17.         return malloc (size);
  18. }
  19. #endif
  20.  
  21. /* Normal routines */
  22.  
  23. ART *AllocART (const char *from, const char *subject)
  24. {
  25.         int
  26.                 len_tot,
  27.                 len_from = strlen (from) + 1,
  28.                 len_subj = strlen (subject) + 1;
  29.         ART
  30.                 *ap;
  31.  
  32.         len_tot = sizeof (ART) + len_from + len_subj;
  33.         ap = (ART *) malloc (len_tot);
  34.         panic0 (ap, "Can't malloc %d bytes for ART", len_tot);
  35.  
  36.         ap->node.ln_Name = ap->header;
  37.  
  38.         ap->from = ((char *) ap) + sizeof (ART);
  39.         memcpy (ap->from, from, len_from);
  40.  
  41.         ap->subject = ap->from + len_from;
  42.         memcpy (ap->subject, subject, len_subj);
  43.  
  44.         return ap;
  45. }
  46.  
  47. #ifdef SLOW
  48. void FreeART (ART *ap)
  49. {
  50.         if (ap) {
  51.                 free ((void *) ap);
  52.         }
  53.         return;
  54. }
  55. #endif
  56.  
  57. NODE *AllocNODE (const char *name, const int len)
  58. {
  59.         register int
  60.                 len_name = len + 1,
  61.                 len_tot;
  62.         register NODE
  63.                 *node;
  64.  
  65.         len_tot = sizeof (NODE) + len_name;
  66.         node = (NODE *) malloc (len_tot);
  67.         panic0 (node, "Can't alloc %d bytes for NODE", len_tot);
  68.  
  69.         node->ln_Name = ((char *) node) + sizeof (NODE);
  70.         memcpy (node->ln_Name, name, len_name);
  71.  
  72.         return node;
  73. }
  74.  
  75. #ifdef SLOW
  76. void FreeNODE (NODE *node)
  77. {
  78.         if (node) {
  79.                 free ((void *) node);
  80.         }
  81.         return;
  82. }
  83. #endif
  84.  
  85. GLIST *AllocGLIST (const char *in_group, const char *in_header)
  86. {
  87.         GLIST *gp;
  88.  
  89.         gp = (GLIST *) malloc (sizeof (GLIST));
  90.         panic0 (gp, "Can't malloc GLIST %d bytes\n", sizeof (GLIST));
  91.  
  92.         gp->node.ln_Name = gp->header;
  93.  
  94.         if (in_group)
  95.                 strcpy (gp->groupName, in_group);
  96.         else
  97.                 strcpy (gp->groupName, "");
  98.         if (in_header)
  99.                 strcpy (gp->header, in_header);
  100.         else
  101.                 strcpy (gp->header, "");
  102.  
  103.         return gp;
  104. }
  105.  
  106. void FreeListNode (LIST *list)
  107. {
  108.         register NODE *np;
  109.  
  110.         while (np = RemHead (list))
  111.                 free (np);
  112.  
  113.         return;
  114. }
  115.