]> jfr.im git - irc/quakenet/newserv.git/blobdiff - proxyscan/proxyscanalloc.c
Update documentation.
[irc/quakenet/newserv.git] / proxyscan / proxyscanalloc.c
index dee282a71cfb92ee652509c03a65a996797bd44d..fa13146c5a8040959905086338b7660d4bff2cbe 100644 (file)
 /* proxyscanalloc.c */
 
 #include "proxyscan.h"
-
-#include <stdlib.h>
-
-#define ALLOCUNIT 1024
-
-scan *freescans;
-cachehost *freecachehosts;
-pendingscan *freependingscans;
-foundproxy *freefoundproxies;
-
-void *mallocs=NULL;
-
-void *smalloc(size_t size) {
-  void **mem;
-
-  /* Get the memory we want, with an extra four bytes for our pointer */
-  mem=(void **)malloc(size+sizeof(void *));
-
-  /* Set the first word to point at the last chunk we got */
-  *mem=mallocs;
-
-  /* Now set the "last chunk" pointer to the address of this one */
-  mallocs=(void *)mem;
-
-  /* Return the rest of the memory to the caller */
-  return (void *)(mem+1);
-}
-
-void sfreeall() {
-  void *vp,**vp2;
-  
-  vp=mallocs;
-
-  while (vp!=NULL) {
-    vp2=(void **)vp;
-    vp=*vp2;
-    free((void *)vp2);
-  }
-}
+#include "../core/nsmalloc.h"
 
 scan *getscan() {
-  int i;
-  scan *sp;
-  
-  if (freescans==NULL) {
-    /* Eep.  Allocate more. */
-    freescans=(scan *)smalloc(ALLOCUNIT*sizeof(scan));
-    for (i=0;i<(ALLOCUNIT-1);i++) {
-      freescans[i].next=&(freescans[i+1]);
-    }
-    freescans[ALLOCUNIT-1].next=NULL;
-  }
-  
-  sp=freescans;
-  freescans=sp->next;
-  
-  return sp;
+  return nsmalloc(POOL_PROXYSCAN, sizeof(scan));
 }
 
 void freescan(scan *sp) {
-  sp->next=freescans;
-  freescans=sp;
+  nsfree(POOL_PROXYSCAN, sp);
 }
 
 cachehost *getcachehost() {
-  int i;
-  cachehost *chp;
-  
-  if (freecachehosts==NULL) {
-    freecachehosts=(cachehost *)smalloc(ALLOCUNIT*sizeof(cachehost));
-    for (i=0;i<(ALLOCUNIT-1);i++) {
-      freecachehosts[i].next=&(freecachehosts[i+1]);
-    }
-    freecachehosts[ALLOCUNIT-1].next=NULL;
-  }
-  
-  chp=freecachehosts;
-  freecachehosts=chp->next;
-  
-  return chp;
+  return nsmalloc(POOL_PROXYSCAN, sizeof(cachehost));
 }
 
 void freecachehost(cachehost *chp) {
-  chp->next=freecachehosts;
-  freecachehosts=chp;
+  nsfree(POOL_PROXYSCAN, chp);
 } 
 
 pendingscan *getpendingscan() {
-  int i;
-  pendingscan *psp;
-
-  if (!freependingscans) {
-    freependingscans=(pendingscan *)smalloc(ALLOCUNIT * sizeof(pendingscan));
-    for (i=0;i<(ALLOCUNIT-1);i++)
-      freependingscans[i].next = freependingscans+i+1;
-    freependingscans[ALLOCUNIT-1].next=NULL;
-  }
-
-  psp=freependingscans;
-  freependingscans=psp->next;
-
-  return psp;
+  return nsmalloc(POOL_PROXYSCAN, sizeof(pendingscan));
 }
 
 void freependingscan(pendingscan *psp) {
-  psp->next=freependingscans;
-  freependingscans=psp;
+  nsfree(POOL_PROXYSCAN, psp);
 }
 
 foundproxy *getfoundproxy() {
-  int i;
-  foundproxy *fpp;
-
-  if (!freefoundproxies) {
-    freefoundproxies=(foundproxy *)smalloc(ALLOCUNIT * sizeof(foundproxy));
-    for (i=0;i<(ALLOCUNIT-1);i++)
-      freefoundproxies[i].next = freefoundproxies+i+1;
-    freefoundproxies[ALLOCUNIT-1].next=NULL;
-  }
+  return nsmalloc(POOL_PROXYSCAN, sizeof(foundproxy));
+}
 
-  fpp=freefoundproxies;
-  freefoundproxies=fpp->next;
+void freefoundproxy(foundproxy *fpp) {
+  nsfree(POOL_PROXYSCAN, fpp);
+}
 
-  return fpp;
+extrascan *getextrascan() {
+  return nsmalloc(POOL_PROXYSCAN, sizeof(extrascan));
 }
 
-void freefoundproxy(foundproxy *fpp) {
-  fpp->next=freefoundproxies;
-  freefoundproxies=fpp;
+void freeextrascan(extrascan *esp) {
+  nsfree(POOL_PROXYSCAN, esp);
 }