]> mj.ucw.cz Git - maildups.git/blob - util.c
Teach mparse to handle maildirs
[maildups.git] / util.c
1 /*
2  *      Utility Functions
3  *
4  *      (c) 2005--2006 Martin Mares <mj@ucw.cz>
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <stdarg.h>
10 #include <string.h>
11
12 #include "util.h"
13
14 int verbose;
15
16 void NONRET
17 die(char *c, ...)
18 {
19   va_list args;
20   va_start(args, c);
21   fprintf(stderr, "%s: ", progname);
22   vfprintf(stderr, c, args);
23   fputc('\n', stderr);
24   va_end(args);
25   exit(1);
26 }
27
28 void
29 verb(int level, char *c, ...)
30 {
31   va_list args;
32   va_start(args, c);
33   if (verbose >= level)
34     {
35       vfprintf(stderr, c, args);
36       fputc('\n', stderr);
37     }
38   va_end(args);
39 }
40
41 void *
42 xmalloc(uns size)
43 {
44   void *buf = malloc(size);
45   if (!buf)
46     die("Unable to allocate %d bytes of memory", size);
47   return buf;
48 }
49
50 void *
51 xrealloc(void *old, uns size)
52 {
53   void *buf = realloc(old, size);
54   if (!buf)
55     die("Unable to allocate %d bytes of memory", size);
56   return buf;
57 }