~ubuntu-branches/debian/squeeze/libmusclecard/squeeze

« back to all changes in this revision

Viewing changes to src/debug.c

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Rousseau
  • Date: 2009-05-01 18:34:32 UTC
  • mfrom: (1.2.1 upstream) (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090501183432-hl0bvuaol8zej369
Tags: 1.3.6-1
* new upstream release
 - Fix "FTBFS: musclecard.c:1384: error: conflicting types for
   'MSCCreateObject'" fixed upstream (Closes: #526498)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * Copyright (C) 1999-2002
5
5
 *  David Corcoran <corcoran@linuxnet.com>
6
 
 * Copyright (C) 1999-2005
 
6
 * Copyright (C) 1999-2008
7
7
 *  Ludovic Rousseau <ludovic.rousseau@free.fr>
8
8
 *
9
 
 * $Id: debug.c,v 1.1.1.1 2006-05-02 20:53:34 rousseau Exp $
 
9
 * $Id: debug.c,v 1.1.1.2 2009-05-01 13:24:46 rousseau Exp $
10
10
 */
11
11
 
12
12
/**
13
13
 * @file
14
 
 * @brief This handles debugging.
 
14
 * @brief This handles debugging for libpcsclite.
15
15
 */
16
 
 
 
16
 
17
17
#include "config.h"
18
18
#include <stdarg.h>
19
19
#include <stdlib.h>
25
25
 
26
26
#define DEBUG_BUF_SIZE 2048
27
27
 
28
 
/* default level is a bit verbose to be backward compatible */
29
 
static char LogLevel = PCSC_LOG_ERROR;
30
 
 
31
 
static signed char LogDoColor = 0;      /* no color by default */
32
 
 
33
 
void log_init(void)
 
28
/** default level is quiet to avoid polluting fd 2 (possibly NOT stderr) */
 
29
static char LogLevel = PCSC_LOG_CRITICAL+1;
 
30
 
 
31
static signed char LogDoColor = 0;      /**< no color by default */
 
32
 
 
33
static void log_init(void)
34
34
{
35
35
        char *e;
36
36
 
40
40
        e = getenv("MUSCLECARD_DEBUG");
41
41
#endif
42
42
        if (e)
43
 
        {
44
43
                LogLevel = atoi(e);
45
 
                printf("pouet %d\n", LogLevel);
46
 
        }
47
44
 
48
 
        /* no color under Windows */
49
 
#ifndef WIN32
50
45
        /* log to stderr and stderr is a tty? */
51
46
        if (isatty(fileno(stderr)))
52
47
        {
56
51
                term = getenv("TERM");
57
52
                if (term)
58
53
                {
59
 
                        int i;
 
54
                        unsigned int i;
60
55
 
61
56
                        /* for each known color terminal */
62
57
                        for (i = 0; i < sizeof(terms) / sizeof(terms[0]); i++)
70
65
                        }
71
66
                }
72
67
        }
73
 
#endif
74
68
} /* log_init */
75
69
 
76
70
void log_msg(const int priority, const char *fmt, ...)
89
83
                return;
90
84
 
91
85
        va_start(argptr, fmt);
92
 
#ifndef WIN32
93
 
        vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
94
 
#else
95
 
#if HAVE_VSNPRINTF
96
 
        vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
97
 
#else
98
 
        vsprintf(DebugBuffer, fmt, argptr);
99
 
#endif
100
 
#endif
 
86
        (void)vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
101
87
        va_end(argptr);
102
88
 
103
 
#ifndef WIN32
104
89
        {
105
90
                if (LogDoColor)
106
91
                {
130
115
                else
131
116
                        fprintf(stderr, "%s\n", DebugBuffer);
132
117
        }
133
 
#else
134
 
        fprintf(stderr, "%s\n", DebugBuffer);
135
 
#endif
136
118
} /* log_msg */
137
119
 
138
120
void log_xxd(const int priority, const char *msg, const unsigned char *buffer,
148
130
 
149
131
        debug_buf_end = DebugBuffer + DEBUG_BUF_SIZE - 5;
150
132
 
151
 
        strlcpy(DebugBuffer, msg, sizeof(DebugBuffer));
 
133
        (void)strlcpy(DebugBuffer, msg, sizeof(DebugBuffer));
152
134
        c = DebugBuffer + strlen(DebugBuffer);
153
135
 
154
136
        for (i = 0; (i < len) && (c < debug_buf_end); ++i)