]>
Commit | Line | Data |
---|---|---|
9fac310d MM |
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> | |
9fac310d MM |
10 | #include <stdlib.h> |
11 | #include <stdarg.h> | |
12 | ||
13 | #include "nest/bird.h" | |
e69e4ed9 | 14 | #include "lib/string.h" |
9fac310d MM |
15 | #include "client/client.h" |
16 | ||
17 | /* Client versions of logging functions */ | |
18 | ||
e69e4ed9 | 19 | static void |
e598853e | 20 | vlog(const char *msg, va_list args) |
e69e4ed9 MM |
21 | { |
22 | char buf[1024]; | |
23 | ||
3f2c7600 OZ |
24 | int n = vsnprintf(buf, sizeof(buf), msg, args); |
25 | if (n < 0) | |
26 | snprintf(buf, sizeof(buf), "???"); | |
3e236955 | 27 | else if (n >= (int) sizeof(buf)) |
3f2c7600 | 28 | snprintf(buf + sizeof(buf) - 100, 100, " ... <too long>"); |
e69e4ed9 MM |
29 | fputs(buf, stderr); |
30 | fputc('\n', stderr); | |
31 | } | |
c51f132d | 32 | |
9fac310d | 33 | void |
e598853e | 34 | bug(const char *msg, ...) |
9fac310d MM |
35 | { |
36 | va_list args; | |
37 | ||
38 | va_start(args, msg); | |
c51f132d | 39 | cleanup(); |
9fac310d | 40 | fputs("Internal error: ", stderr); |
e69e4ed9 | 41 | vlog(msg, args); |
9fac310d | 42 | vfprintf(stderr, msg, args); |
8f01879c | 43 | va_end(args); |
9fac310d MM |
44 | exit(1); |
45 | } | |
46 | ||
47 | void | |
e598853e | 48 | die(const char *msg, ...) |
9fac310d MM |
49 | { |
50 | va_list args; | |
51 | ||
52 | va_start(args, msg); | |
c51f132d | 53 | cleanup(); |
e69e4ed9 | 54 | vlog(msg, args); |
8f01879c | 55 | va_end(args); |
9fac310d MM |
56 | exit(1); |
57 | } |