Clean a bit - to be continued...
[seven-1.x.git] / libseven / tools.c
blob33c7837b44be4e57130bd1fa68a58dcd83e4a46f
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * tools.c: Various functions needed here and there.
5 * Copyright (C) 1996-2002 Hybrid Development Team
6 * Copyright (C) 2002-2005 ircd-ratbox development team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * USA
23 * Here is the original header:
25 * Useful stuff, ripped from places ..
26 * adrian chadd <adrian@creative.net.au>
28 * When you update these functions make sure you update the ones in tools.h
29 * as well!!!
32 #include "stdinc.h"
33 #define TOOLS_C
34 #include "tools.h"
35 #include "balloc.h"
36 #include "s_user.h"
38 #ifndef NDEBUG
40 * frob some memory. debugging time.
41 * -- adrian
43 void
44 mem_frob(void *data, int len)
46 unsigned long x = 0xdeadbeef;
47 unsigned char *b = (unsigned char *)&x;
48 int i;
49 char *cdata = data;
50 for (i = 0; i < len; i++)
52 *cdata = b[i % 4];
53 cdata++;
56 #endif
59 * init_dlink_nodes
62 extern BlockHeap *dnode_heap;
63 void
64 init_dlink_nodes(void)
66 dnode_heap = BlockHeapCreate(sizeof(dlink_node), DNODE_HEAP_SIZE);
67 if(dnode_heap == NULL)
68 outofmemory();
72 * make_dlink_node
74 * inputs - NONE
75 * output - pointer to new dlink_node
76 * side effects - NONE
78 dlink_node *
79 make_dlink_node(void)
81 return(BlockHeapAlloc(dnode_heap));
85 * free_dlink_node
87 * inputs - pointer to dlink_node
88 * output - NONE
89 * side effects - free given dlink_node
91 void
92 free_dlink_node(dlink_node * ptr)
94 assert(ptr != NULL);
96 BlockHeapFree(dnode_heap, ptr);
100 * find_umode_slot
102 * inputs - NONE
103 * outputs - an available umode bitmask or
104 * 0 if no umodes are available
105 * side effects - NONE
107 unsigned int
108 find_umode_slot(void)
110 unsigned int all_umodes = 0, my_umode = 0, i;
112 for (i = 0; i < 128; i++)
113 all_umodes |= user_modes[i];
115 for (my_umode = 1; my_umode && (all_umodes & my_umode);
116 my_umode <<= 1);
118 return my_umode;