/[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 269 - (hide annotations) (download)
Tue Aug 12 12:40:23 2003 UTC (9 years, 10 months ago) by rousseau
File MIME type: text/plain
File size: 1739 byte(s)
Initial revision
1 rousseau 269 /*
2     debug.c: log (or not) messages
3     Copyright (C) 2003 Ludovic Rousseau
4    
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9    
10     This program 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
13     GNU General Public License for more details.
14    
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18     */
19    
20     /*
21     * $Id$
22     */
23    
24    
25     #include "config.h"
26     #include "debug.h"
27    
28     #ifdef DEBUG
29    
30     #include <stdarg.h>
31     #include <stdio.h>
32     #include <string.h>
33    
34     #define DEBUG_BUF_SIZE ((256+20)*3+10)
35    
36     static char DebugBuffer[DEBUG_BUF_SIZE];
37    
38     void debug_msg(char *fmt, ...)
39     {
40     va_list argptr;
41    
42     va_start(argptr, fmt);
43     vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
44     va_end(argptr);
45    
46     fprintf(stderr, "%s\n", DebugBuffer);
47     } /* debug_msg */
48    
49     void debug_xxd(const char *msg, const unsigned char *buffer, const int len)
50     {
51     int i;
52     unsigned char *c, *debug_buf_end;
53    
54     debug_buf_end = DebugBuffer + DEBUG_BUF_SIZE - 5;
55    
56     strncpy(DebugBuffer, msg, sizeof(DebugBuffer)-1);
57     c = DebugBuffer + strlen(DebugBuffer);
58    
59     for (i = 0; (i < len) && (c < debug_buf_end); ++i)
60     {
61     sprintf(c, "%02X ", buffer[i]);
62     c += strlen(c);
63     }
64    
65     if (c >= debug_buf_end)
66     fprintf(stderr, "Debug buffer too short\n");
67    
68     fprintf(stderr, "%s\n", DebugBuffer);
69     } /* debug_xxd */
70    
71     #endif
72    

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5