/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/portaudio/src/common/pa_debugprint.c
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/portaudio/src/common/pa_debugprint.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (9 years, 5 months ago) by william
File MIME type: text/plain
File size: 4012 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 /*
2 * $Id: pa_log.c $
3 * Portable Audio I/O Library Multi-Host API front end
4 * Validate function parameters and manage multiple host APIs.
5 *
6 * Based on the Open Source API proposed by Ross Bencina
7 * Copyright (c) 1999-2006 Ross Bencina, Phil Burk
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining
10 * a copy of this software and associated documentation files
11 * (the "Software"), to deal in the Software without restriction,
12 * including without limitation the rights to use, copy, modify, merge,
13 * publish, distribute, sublicense, and/or sell copies of the Software,
14 * and to permit persons to whom the Software is furnished to do so,
15 * subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 */
28
29 /*
30 * The text above constitutes the entire PortAudio license; however,
31 * the PortAudio community also makes the following non-binding requests:
32 *
33 * Any person wishing to distribute modifications to the Software is
34 * requested to send the modifications to the original developer so that
35 * they can be incorporated into the canonical version. It is also
36 * requested that these non-binding requests be included along with the
37 * license above.
38 */
39
40 /** @file
41 @ingroup common_src
42
43 @brief Implements log function.
44
45 PaUtil_SetLogPrintFunction can be user called to replace the provided
46 DefaultLogPrint function, which writes to stderr.
47 One can NOT pass var_args across compiler/dll boundaries as it is not
48 "byte code/abi portable". So the technique used here is to allocate a local
49 a static array, write in it, then callback the user with a pointer to its
50 start.
51
52 @todo Consider allocating strdump using dynamic allocation.
53 @todo Consider reentrancy and possibly corrupted strdump buffer.
54 */
55
56 #include <stdio.h>
57 #include <stdarg.h>
58
59 #include "pa_debugprint.h"
60
61 // for OutputDebugStringA
62 #if defined(_MSC_VER) && defined(PA_ENABLE_MSVC_DEBUG_OUTPUT)
63 #define WIN32_LEAN_AND_MEAN // exclude rare headers
64 #include "windows.h"
65 #endif
66
67 // User callback
68 static PaUtilLogCallback userCB = NULL;
69
70 // Sets user callback
71 void PaUtil_SetDebugPrintFunction(PaUtilLogCallback cb)
72 {
73 userCB = cb;
74 }
75
76 /*
77 If your platform doesnÂ’t have vsnprintf, you are stuck with a
78 VERY dangerous alternative, vsprintf (with no n)
79 */
80 #if _MSC_VER
81 /* Some Windows Mobile SDKs don't define vsnprintf but all define _vsnprintf (hopefully).
82 According to MSDN "vsnprintf is identical to _vsnprintf". So we use _vsnprintf with MSC.
83 */
84 #define VSNPRINTF _vsnprintf
85 #else
86 #define VSNPRINTF vsnprintf
87 #endif
88
89 #define PA_LOG_BUF_SIZE 2048
90
91 void PaUtil_DebugPrint( const char *format, ... )
92 {
93 // Optional logging into Output console of Visual Studio
94 #if defined(_MSC_VER) && defined(PA_ENABLE_MSVC_DEBUG_OUTPUT)
95 {
96 char buf[PA_LOG_BUF_SIZE];
97 va_list ap;
98 va_start(ap, format);
99 VSNPRINTF(buf, sizeof(buf), format, ap);
100 buf[sizeof(buf)-1] = 0;
101 OutputDebugStringA(buf);
102 va_end(ap);
103 }
104 #endif
105
106 // Output to User-Callback
107 if (userCB != NULL)
108 {
109 char strdump[PA_LOG_BUF_SIZE];
110 va_list ap;
111 va_start(ap, format);
112 VSNPRINTF(strdump, sizeof(strdump), format, ap);
113 strdump[sizeof(strdump)-1] = 0;
114 userCB(strdump);
115 va_end(ap);
116 }
117 else
118 // Standard output to stderr
119 {
120 va_list ap;
121 va_start(ap, format);
122 vfprintf(stderr, format, ap);
123 va_end(ap);
124 fflush(stderr);
125 }
126 }

  ViewVC Help
Powered by ViewVC 1.1.22