port fix from branch_1_1
[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/autoconf.h>
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include <freeradius-devel/missing.h>
34 #include <freeradius-devel/libradius.h>
35
36 char librad_errstr[1024];
37
38 /*
39  *  Do logging to a static buffer.  Note that we MIGHT be asked
40  *  to write a previous log message to librad_errstr.
41  *
42  *  This also isn't multithreaded-safe, so it'll have to be changed
43  *  in the future.
44  */
45 void librad_log(const char *fmt, ...)
46 {
47         va_list ap;
48         char my_errstr[sizeof(librad_errstr)];
49
50         va_start(ap, fmt);
51         vsnprintf(my_errstr, sizeof(my_errstr), fmt, ap);
52         strcpy(librad_errstr, my_errstr);
53         va_end(ap);
54 }
55
56 void librad_perror(const char *fmt, ...)
57 {
58         va_list ap;
59
60         va_start(ap, fmt);
61         vfprintf(stderr, fmt, ap);
62         if (strchr(fmt, ':') == NULL)
63                 fprintf(stderr, ": ");
64         fprintf(stderr, "%s\n", librad_errstr);
65 }