* configure.ac: Fix resolver autoconf code so it works (fails)
[gnupg.git] / util / assuan-logging.c
blobf2d6c876dada91bf8416e161db7401ffa6a5fa92
1 /* assuan-logging.c - Default logging function.
2 * Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
4 * This file is part of Assuan.
6 * Assuan is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * Assuan is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 * USA.
22 /* Please note that this is a stripped down and modified version of
23 the orginal Assuan code from libassuan. */
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdarg.h>
31 #ifdef HAVE_W32_SYSTEM
32 #include <windows.h>
33 #endif /*HAVE_W32_SYSTEM*/
35 #include "assuan-defs.h"
37 static char prefix_buffer[80];
38 static FILE *_assuan_log;
40 void
41 _assuan_set_default_log_stream (FILE *fp)
43 if (!_assuan_log)
44 _assuan_log = fp;
47 void
48 assuan_set_assuan_log_stream (FILE *fp)
50 _assuan_log = fp;
53 FILE *
54 assuan_get_assuan_log_stream (void)
56 return _assuan_log ? _assuan_log : stderr;
60 /* Set the prefix to be used for logging to TEXT or
61 resets it to the default if TEXT is NULL. */
62 void
63 assuan_set_assuan_log_prefix (const char *text)
65 if (text)
67 strncpy (prefix_buffer, text, sizeof (prefix_buffer)-1);
68 prefix_buffer[sizeof (prefix_buffer)-1] = 0;
70 else
71 *prefix_buffer = 0;
74 const char *
75 assuan_get_assuan_log_prefix (void)
77 return prefix_buffer;
81 void
82 _assuan_log_printf (const char *format, ...)
84 va_list arg_ptr;
85 FILE *fp;
86 const char *prf;
88 fp = assuan_get_assuan_log_stream ();
89 prf = assuan_get_assuan_log_prefix ();
90 if (*prf)
92 fputs (prf, fp);
93 fputs (": ", fp);
96 va_start (arg_ptr, format);
97 vfprintf (fp, format, arg_ptr );
98 va_end (arg_ptr);
103 #ifdef HAVE_W32_SYSTEM
104 const char *
105 _assuan_w32_strerror (int ec)
107 static char strerr[256];
109 if (ec == -1)
110 ec = (int)GetLastError ();
111 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, ec,
112 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
113 strerr, sizeof (strerr)-1, NULL);
114 return strerr;
116 #endif /*HAVE_W32_SYSTEM*/