blob: b178e5f5a05eb6e84ed53f970d99ac511e2214e5 (
plain)
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
65
66
67
68
69
70
71
72
73
74
75
|
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <limits.h>
#include <stddef.h>
#include "ssplain.h"
void chatting(char *s, ...)
{
va_list ap;
va_start(ap,s);
vfprintf(stderr, s, ap);
va_end(ap);
}
void __Olden_panic(char *s, ...)
{
va_list ap;
va_start(ap,s);
vfprintf(stderr, s, ap);
va_end(ap);
exit(-1);
}
#ifdef SS_RAND
double drand48()
{
double d;
d = (double) random() / LONG_MAX;
return d;
}
long lrand48()
{
long l = random();
return l;
}
void srand48(long seed)
{
srand(seed);
}
#endif SS_RAND
static unsigned long bytes_allocated = 0;
static unsigned long allocations = 0;
void*
ssplain_malloc(int size)
{
allocations++;
bytes_allocated+=size;
return malloc(size);
}
void*
ssplain_calloc(int nelems, int size)
{
void *p;
allocations++;
bytes_allocated+= nelems * size;
p = calloc(nelems, size);
assert (p);
return p;
}
void
ssplain_alloc_stats()
{
chatting("Allocation stats: %d bytes allocated in %d allocations\n",
bytes_allocated, allocations);
}
|