aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/acidtypes/util.c
blob: 0dbc63e991a4ab84f0f5709bf3754471077b9e2a (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
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <mach.h>
#include "dat.h"

static int nwarn;

void
warn(char *fmt, ...)
{
	va_list arg;

	if(++nwarn < 5){
		va_start(arg, fmt);
		fprint(2, "warning: ");
		vfprint(2, fmt, arg);
		fprint(2, "\n");
		va_end(arg);
	}else if(nwarn == 5)
		fprint(2, "[additional warnings elided...]\n");
}

void*
erealloc(void *v, uint n)
{
	v = realloc(v, n);
	if(v == nil)
		sysfatal("realloc: %r");
	return v;
}

void*
emalloc(uint n)
{
	void *v;

	v = mallocz(n, 1);
	if(v == nil)
		sysfatal("malloc: %r");
	return v;
}

char*
estrdup(char *s)
{
	s = strdup(s);
	if(s == nil)
		sysfatal("strdup: %r");
	return s;
}

TypeList*
mktl(Type *hd, TypeList *tail)
{
	TypeList *tl;

	tl = emalloc(sizeof(*tl));
	tl->hd = hd;
	tl->tl = tail;
	return tl;
}