Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <mach.h>
5 #include "dat.h"
7 static int nwarn;
9 void
10 warn(char *fmt, ...)
11 {
12 va_list arg;
14 if(++nwarn < 5){
15 va_start(arg, fmt);
16 fprint(2, "warning: ");
17 vfprint(2, fmt, arg);
18 fprint(2, "\n");
19 va_end(arg);
20 }else if(nwarn == 5)
21 fprint(2, "[additional warnings elided...]\n");
22 }
24 void*
25 erealloc(void *v, uint n)
26 {
27 v = realloc(v, n);
28 if(v == nil)
29 sysfatal("realloc: %r");
30 return v;
31 }
33 void*
34 emalloc(uint n)
35 {
36 void *v;
38 v = mallocz(n, 1);
39 if(v == nil)
40 sysfatal("malloc: %r");
41 return v;
42 }
44 char*
45 estrdup(char *s)
46 {
47 s = strdup(s);
48 if(s == nil)
49 sysfatal("strdup: %r");
50 return s;
51 }
53 TypeList*
54 mktl(Type *hd, TypeList *tail)
55 {
56 TypeList *tl;
58 tl = emalloc(sizeof(*tl));
59 tl->hd = hd;
60 tl->tl = tail;
61 return tl;
62 }