1: /*
2: * BIRD Client -- Utility Functions
3: *
4: * (c) 1999--2000 Martin Mares <mj@ucw.cz>
5: *
6: * Can be freely distributed and used under the terms of the GNU GPL.
7: */
8:
9: #include <stdio.h>
10: #include <stdlib.h>
11: #include <stdarg.h>
12:
13: #include "nest/bird.h"
14: #include "lib/string.h"
15: #include "client/client.h"
16:
17: /* Client versions of logging functions */
18:
19: static void
20: vlog(const char *msg, va_list args)
21: {
22: char buf[1024];
23:
24: int n = vsnprintf(buf, sizeof(buf), msg, args);
25: if (n < 0)
26: snprintf(buf, sizeof(buf), "???");
27: else if (n >= (int) sizeof(buf))
28: snprintf(buf + sizeof(buf) - 100, 100, " ... <too long>");
29: fputs(buf, stderr);
30: fputc('\n', stderr);
31: }
32:
33: void
34: bug(const char *msg, ...)
35: {
36: va_list args;
37:
38: va_start(args, msg);
39: cleanup();
40: fputs("Internal error: ", stderr);
41: vlog(msg, args);
42: vfprintf(stderr, msg, args);
43: va_end(args);
44: exit(1);
45: }
46:
47: void
48: die(const char *msg, ...)
49: {
50: va_list args;
51:
52: va_start(args, msg);
53: cleanup();
54: vlog(msg, args);
55: va_end(args);
56: exit(1);
57: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>