]> git.ipfire.org Git - thirdparty/bird.git/blame - client/util.c
We don't need bvsnprintf() in BIRD client
[thirdparty/bird.git] / client / util.c
CommitLineData
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 19static void
e598853e 20vlog(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), "???");
27 if (n >= sizeof(buf))
28 snprintf(buf + sizeof(buf) - 100, 100, " ... <too long>");
e69e4ed9
MM
29 fputs(buf, stderr);
30 fputc('\n', stderr);
31}
c51f132d 32
9fac310d 33void
e598853e 34bug(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);
9fac310d
MM
43 exit(1);
44}
45
46void
e598853e 47die(const char *msg, ...)
9fac310d
MM
48{
49 va_list args;
50
51 va_start(args, msg);
c51f132d 52 cleanup();
e69e4ed9 53 vlog(msg, args);
9fac310d
MM
54 exit(1);
55}