aboutsummaryrefslogtreecommitdiffstats
path: root/test/ccured_olden/treeadd/ssplain.c
blob: 18c8a7211f2255f92b3cccd3e1299dcdd1cafbb7 (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
#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);
}


#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


#ifndef BEFOREBOX
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);
  if(! p) { printf("Cannot allocate\n"); exit(3); }
  return p;
}

void
ssplain_alloc_stats()
{
  chatting("Allocation stats: %d bytes allocated in %d allocations\n",
	   bytes_allocated, allocations);
}
#endif