-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.c
55 lines (46 loc) · 780 Bytes
/
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
/*
* cdoc
* Copyright (c) 2019 Matthew Veety.
* See LICENSE for details
*/
#include "impl.h"
volatile int debugprint = 0;
void
panic(char *s)
{
dprintf(2, "cdoc: panic: %s\n", s);
exit(-99);
}
void
error(char *s)
{
if(toks != nil && curtok != nil){
dprintf(2, "%s:%d: error: %s\n", curtok->fname, curtok->linenum, s);
exit(-2);
}
dprintf(2, "error: %s\n", s);
exit(-98);
}
void
fileerror(char *fname, char *s)
{
dprintf(2, "%s: error: %s\n", fname, s);
exit(-97);
}
void
warn(char *s)
{
if(toks != nil && curtok != nil)
dprintf(2, "%s:%d: warn: %s\n", curtok->fname, curtok->linenum, s);
else
dprintf(2, "warn: %s\n", s);
}
void*
emallocz(uintptr sz)
{
void *ptr;
if(!(ptr = malloc(sz)))
panic("bad malloc");
memset(ptr, 0, sz);
return ptr;
}