]> git.ipfire.org Git - thirdparty/bird.git/blob - client/util.c
We don't need bvsnprintf() in BIRD client
[thirdparty/bird.git] / client / util.c
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 if (n >= 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 exit(1);
44 }
45
46 void
47 die(const char *msg, ...)
48 {
49 va_list args;
50
51 va_start(args, msg);
52 cleanup();
53 vlog(msg, args);
54 exit(1);
55 }