/[pcsclite]/trunk/Drivers/ccid/src/debug.c
ViewVC logotype

Contents of /trunk/Drivers/ccid/src/debug.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3268 - (show annotations) (download)
Mon Jan 5 14:28:26 2009 UTC (4 years, 4 months ago) by rousseau
File MIME type: text/plain
File size: 1894 byte(s)
explicitly cast result in void when not used (reported by the splint tool)
1 /*
2 debug.c: log (or not) messages
3 Copyright (C) 2003-2005 Ludovic Rousseau
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 /*
21 * $Id$
22 */
23
24
25 #include "config.h"
26 #include "debug.h"
27
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #define DEBUG_BUF_SIZE ((256+20)*3+10)
33
34 static char DebugBuffer[DEBUG_BUF_SIZE];
35
36 #define LOG_TO_STDERR
37
38 void log_msg(const int priority, const char *fmt, ...)
39 {
40 va_list argptr;
41
42 va_start(argptr, fmt);
43 (void)vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
44 va_end(argptr);
45
46 #ifdef LOG_TO_STDERR
47 (void)fprintf(stderr, "%s\n", DebugBuffer);
48 #endif
49 } /* log_msg */
50
51 void log_xxd(const int priority, const char *msg, const unsigned char *buffer,
52 const int len)
53 {
54 int i;
55 char *c, *debug_buf_end;
56
57 debug_buf_end = DebugBuffer + DEBUG_BUF_SIZE - 5;
58
59 strncpy(DebugBuffer, msg, sizeof(DebugBuffer)-1);
60 c = DebugBuffer + strlen(DebugBuffer);
61
62 for (i = 0; (i < len) && (c < debug_buf_end); ++i)
63 {
64 (void)sprintf(c, "%02X ", (unsigned char)buffer[i]);
65 c += strlen(c);
66 }
67
68 #ifdef LOG_TO_STDERR
69 if (c >= debug_buf_end)
70 (void)fprintf(stderr, "Debug buffer too short\n");
71
72 (void)fprintf(stderr, "%s\n", DebugBuffer);
73 #endif
74 } /* log_xxd */
75

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5