gallium: Use custom vsnprintf in WINDDK.
[mesa.git] / src / gallium / auxiliary / util / p_debug.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include <stdarg.h>
30
31 #ifdef WIN32
32 #include <windows.h>
33 #include <winddi.h>
34 #else
35 #include <stdio.h>
36 #include <stdlib.h>
37 #endif
38
39 #include "pipe/p_debug.h"
40 #include "pipe/p_compiler.h"
41
42
43 #ifdef WIN32
44 static INLINE void
45 rpl_EngDebugPrint(const char *format, ...)
46 {
47 va_list ap;
48 va_start(ap, format);
49 EngDebugPrint("", (PCHAR)format, ap);
50 va_end(ap);
51 }
52
53 int rpl_vsnprintf(char *, size_t, const char *, va_list);
54 #endif
55
56
57 void debug_vprintf(const char *format, va_list ap)
58 {
59 #ifdef WIN32
60 /* EngDebugPrint does not handle float point arguments, so we need to use
61 * our own vsnprintf implementation */
62 char buf[512 + 1];
63 rpl_vsnprintf(buf, sizeof(buf), format, ap);
64 rpl_EngDebugPrint("%s", buf);
65 #else
66 vfprintf(stderr, format, ap);
67 #endif
68 }
69
70
71 void debug_printf(const char *format, ...)
72 {
73 va_list ap;
74 va_start(ap, format);
75 debug_vprintf(format, ap);
76 va_end(ap);
77 }
78
79
80 static INLINE void debug_abort(void)
81 {
82 #ifdef WIN32
83 EngDebugBreak();
84 #else
85 abort();
86 #endif
87 }
88
89
90 void debug_assert_fail(const char *expr, const char *file, unsigned line)
91 {
92 debug_printf("%s:%i: Assertion `%s' failed.\n", file, line, expr);
93 debug_abort();
94 }