]> jfr.im git - irc/quakenet/newserv.git/blame - proxyscan/proxyscanalloc.c
merge
[irc/quakenet/newserv.git] / proxyscan / proxyscanalloc.c
CommitLineData
c86edd1d
Q
1/* proxyscanalloc.c */
2
3#include "proxyscan.h"
4
5#include <stdlib.h>
6
7#define ALLOCUNIT 1024
8
9scan *freescans;
10cachehost *freecachehosts;
11pendingscan *freependingscans;
12foundproxy *freefoundproxies;
13
14void *mallocs=NULL;
15
16void *smalloc(size_t size) {
17 void **mem;
18
19 /* Get the memory we want, with an extra four bytes for our pointer */
20 mem=(void **)malloc(size+sizeof(void *));
21
22 /* Set the first word to point at the last chunk we got */
23 *mem=mallocs;
24
25 /* Now set the "last chunk" pointer to the address of this one */
26 mallocs=(void *)mem;
27
28 /* Return the rest of the memory to the caller */
29 return (void *)(mem+1);
30}
31
32void sfreeall() {
33 void *vp,**vp2;
34
35 vp=mallocs;
36
37 while (vp!=NULL) {
38 vp2=(void **)vp;
39 vp=*vp2;
40 free((void *)vp2);
41 }
42}
43
44scan *getscan() {
45 int i;
46 scan *sp;
47
48 if (freescans==NULL) {
49 /* Eep. Allocate more. */
50 freescans=(scan *)smalloc(ALLOCUNIT*sizeof(scan));
51 for (i=0;i<(ALLOCUNIT-1);i++) {
52 freescans[i].next=&(freescans[i+1]);
53 }
54 freescans[ALLOCUNIT-1].next=NULL;
55 }
56
57 sp=freescans;
58 freescans=sp->next;
59
60 return sp;
61}
62
63void freescan(scan *sp) {
64 sp->next=freescans;
65 freescans=sp;
66}
67
68cachehost *getcachehost() {
69 int i;
70 cachehost *chp;
71
72 if (freecachehosts==NULL) {
73 freecachehosts=(cachehost *)smalloc(ALLOCUNIT*sizeof(cachehost));
74 for (i=0;i<(ALLOCUNIT-1);i++) {
75 freecachehosts[i].next=&(freecachehosts[i+1]);
76 }
77 freecachehosts[ALLOCUNIT-1].next=NULL;
78 }
79
80 chp=freecachehosts;
81 freecachehosts=chp->next;
82
83 return chp;
84}
85
86void freecachehost(cachehost *chp) {
87 chp->next=freecachehosts;
88 freecachehosts=chp;
89}
90
91pendingscan *getpendingscan() {
92 int i;
93 pendingscan *psp;
94
95 if (!freependingscans) {
96 freependingscans=(pendingscan *)smalloc(ALLOCUNIT * sizeof(pendingscan));
97 for (i=0;i<(ALLOCUNIT-1);i++)
98 freependingscans[i].next = freependingscans+i+1;
99 freependingscans[ALLOCUNIT-1].next=NULL;
100 }
101
102 psp=freependingscans;
103 freependingscans=psp->next;
104
105 return psp;
106}
107
108void freependingscan(pendingscan *psp) {
109 psp->next=freependingscans;
110 freependingscans=psp;
111}
112
113foundproxy *getfoundproxy() {
114 int i;
115 foundproxy *fpp;
116
117 if (!freefoundproxies) {
118 freefoundproxies=(foundproxy *)smalloc(ALLOCUNIT * sizeof(foundproxy));
119 for (i=0;i<(ALLOCUNIT-1);i++)
120 freefoundproxies[i].next = freefoundproxies+i+1;
121 freefoundproxies[ALLOCUNIT-1].next=NULL;
122 }
123
124 fpp=freefoundproxies;
125 freefoundproxies=fpp->next;
126
127 return fpp;
128}
129
130void freefoundproxy(foundproxy *fpp) {
131 fpp->next=freefoundproxies;
132 freefoundproxies=fpp;
133}
134