Massively cleaned up #include's, so they're in a consistent
[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,2006  The FreeRADIUS server project
22  */
23
24 #include <freeradius-devel/ident.h>
25 RCSID("$Id$")
26
27 #include <freeradius-devel/libradius.h>
28
29 char librad_errstr[1024];
30
31 /*
32  *  Do logging to a static buffer.  Note that we MIGHT be asked
33  *  to write a previous log message to librad_errstr.
34  *
35  *  This also isn't multithreaded-safe, so it'll have to be changed
36  *  in the future.
37  */
38 void librad_log(const char *fmt, ...)
39 {
40         va_list ap;
41         char my_errstr[sizeof(librad_errstr)];
42
43         va_start(ap, fmt);
44         vsnprintf(my_errstr, sizeof(my_errstr), fmt, ap);
45         strcpy(librad_errstr, my_errstr);
46         va_end(ap);
47 }
48
49 void librad_perror(const char *fmt, ...)
50 {
51         va_list ap;
52
53         va_start(ap, fmt);
54         vfprintf(stderr, fmt, ap);
55         if (strchr(fmt, ':') == NULL)
56                 fprintf(stderr, ": ");
57         fprintf(stderr, "%s\n", librad_errstr);
58 }