-
Notifications
You must be signed in to change notification settings - Fork 4
/
util.c
64 lines (54 loc) · 1.06 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Copyright (c) 1999 Rafal Wojtczuk <[email protected]>. All rights reserved.
See the file COPYING for license details.
*/
#include <config.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include "tcp.h"
#include "util.h"
#include "nids.h"
void
nids_no_mem(char *func)
{
fprintf(stderr, "Out of memory in %s.\n", func);
exit(1);
}
char *
test_malloc(int x)
{
char *ret = malloc(x);
if (!ret)
nids_params.no_mem("test_malloc");
return ret;
}
void
register_callback(struct proc_node **procs, void (*x))
{
struct proc_node *ipp;
for (ipp = *procs; ipp; ipp = ipp->next)
if (x == ipp->item)
return;
ipp = mknew(struct proc_node);
ipp->item = x;
ipp->next = *procs;
*procs = ipp;
}
void
unregister_callback(struct proc_node **procs, void (*x))
{
struct proc_node *ipp;
struct proc_node *ipp_prev = 0;
for (ipp = *procs; ipp; ipp = ipp->next) {
if (x == ipp->item) {
if (ipp_prev)
ipp_prev->next = ipp->next;
else
*procs = ipp->next;
free(ipp);
return;
}
ipp_prev = ipp;
}
}