Initial revision
[freeradius.git] / src / lib / log.c
1 /*
2  * log.c        Functions in the library call radlib_log() which
3  *              sets a global error string "char *librad_errstr".
4  *
5  * Version:     @(#)log.c  1.00  25-Oct-1998  miquels@cistron.nl
6  *
7  */
8
9 #include "autoconf.h"
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
14 #include <string.h>
15
16 char librad_errstr[1024];
17
18 void librad_log(char *fmt, ...)
19 {
20         va_list ap;
21
22         va_start(ap, fmt);
23 #ifdef HAVE_VSNPRINTF
24         vsnprintf(librad_errstr, sizeof(librad_errstr), fmt, ap);
25 #else
26         vsprintf(librad_errstr, fmt, ap);
27 #endif
28         va_end(ap);
29 }
30
31 void librad_perror(char *fmt, ...)
32 {
33         va_list *ap;
34
35         va_start(ap, fmt);
36         vfprintf(stderr, fmt, ap);
37         if (strchr(fmt, ':') == NULL)
38                 fprintf(stderr, ": ");
39         fprintf(stderr, "%s\n", librad_errstr);
40 }
41