import from HEAD:
[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:     $Id$
6  *
7  *   This library is free software; you can redistribute it and/or
8  *   modify it under the terms of the GNU Lesser General Public
9  *   License as published by the Free Software Foundation; either
10  *   version 2.1 of the License, or (at your option) any later version.
11  *
12  *   This library is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  *   Lesser General Public License for more details.
16  *
17  *   You should have received a copy of the GNU Lesser General Public
18  *   License along with this library; if not, write to the Free Software
19  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  *
21  * Copyright 2000  The FreeRADIUS server project
22  */
23
24 static const char rcsid[] = "$Id$";
25
26 #include "autoconf.h"
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <string.h>
32
33 #include "libradius.h"
34
35 char librad_errstr[1024];
36
37 /*
38  *  Do logging to a static buffer.  Note that we MIGHT be asked
39  *  to write a previous log message to librad_errstr.
40  *
41  *  This also isn't multithreaded-safe, so it'll have to be changed
42  *  in the future.
43  */
44 void librad_log(const char *fmt, ...)
45 {
46         va_list ap;
47         char my_errstr[sizeof(librad_errstr)];
48
49         va_start(ap, fmt);
50         vsnprintf(my_errstr, sizeof(my_errstr), fmt, ap);
51         strcpy(librad_errstr, my_errstr);
52         va_end(ap);
53 }
54
55 void librad_perror(const char *fmt, ...)
56 {
57         va_list ap;
58
59         va_start(ap, fmt);
60         vfprintf(stderr, fmt, ap);
61         if (strchr(fmt, ':') == NULL)
62                 fprintf(stderr, ": ");
63         fprintf(stderr, "%s\n", librad_errstr);
64 }