]> jfr.im git - irc/quakenet/newserv.git/blob - proxyscan/proxyscanalloc.c
Initial Import
[irc/quakenet/newserv.git] / proxyscan / proxyscanalloc.c
1 /* proxyscanalloc.c */
2
3 #include "proxyscan.h"
4
5 #include <stdlib.h>
6
7 #define ALLOCUNIT 1024
8
9 scan *freescans;
10 cachehost *freecachehosts;
11 pendingscan *freependingscans;
12 foundproxy *freefoundproxies;
13
14 void *mallocs=NULL;
15
16 void *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
32 void 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
44 scan *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
63 void freescan(scan *sp) {
64 sp->next=freescans;
65 freescans=sp;
66 }
67
68 cachehost *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
86 void freecachehost(cachehost *chp) {
87 chp->next=freecachehosts;
88 freecachehosts=chp;
89 }
90
91 pendingscan *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
108 void freependingscan(pendingscan *psp) {
109 psp->next=freependingscans;
110 freependingscans=psp;
111 }
112
113 foundproxy *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
130 void freefoundproxy(foundproxy *fpp) {
131 fpp->next=freefoundproxies;
132 freefoundproxies=fpp;
133 }
134