2 * log.c Functions in the library call radlib_log() which
3 * sets a global error string "char *librad_errstr".
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
21 * Copyright 2000 The FreeRADIUS server project
24 static const char rcsid[] = "$Id$";
33 #include "libradius.h"
35 char librad_errstr[1024];
38 * Do logging to a static buffer. Note that we MIGHT be asked
39 * to write a previous log message to librad_errstr.
41 * This also isn't multithreaded-safe, so it'll have to be changed
44 void librad_log(const char *fmt, ...)
47 char my_errstr[sizeof(librad_errstr)];
52 vsnprintf(my_errstr, sizeof(my_errstr), fmt, ap);
54 vsprintf(my_errstr, fmt, ap);
55 if (strlen(my_errstr) >= sizeof(my_errstr))
56 /* What can we do .. */
59 strcpy(librad_errstr, my_errstr);
63 void librad_perror(const char *fmt, ...)
68 vfprintf(stderr, fmt, ap);
69 if (strchr(fmt, ':') == NULL)
70 fprintf(stderr, ": ");
71 fprintf(stderr, "%s\n", librad_errstr);