Build and link the version resource for Windows builds
[wine/multimedia.git] / debug.c
blob84beba0e7fd40b45611b0852bbf2aa8444a9240d
1 #ifdef __WINESRC__
2 #error This file should not be compiled with Wine.
3 #endif
5 #include <stdarg.h>
6 #include <stdio.h>
7 #include <stdlib.h>
9 #include <windows.h>
11 /* allocate some tmp string space */
12 /* FIXME: this is not 100% thread-safe */
13 static char *get_temp_buffer( size_t size )
15 static char *list[32];
16 static LONG pos;
17 char *ret;
18 int idx;
20 idx = InterlockedExchangeAdd( &pos, 1 ) % (sizeof(list)/sizeof(list[0]));
21 if ((ret = realloc( list[idx], size ))) list[idx] = ret;
22 return ret;
26 /* release unused part of the buffer */
27 static void release_temp_buffer( char *buffer, size_t size )
29 /* don't bother doing anything */
30 (void)buffer;
31 (void)size;
34 /* printf with temp buffer allocation */
35 const char *wine_dbg_sprintf( const char *format, ... )
37 static const int max_size = 200;
38 char *ret;
39 int len;
40 va_list valist;
42 va_start(valist, format);
43 ret = get_temp_buffer( max_size );
44 len = vsnprintf( ret, max_size, format, valist );
45 if (len == -1 || len >= max_size) ret[max_size-1] = 0;
46 else release_temp_buffer( ret, len + 1 );
47 va_end(valist);
48 return ret;
51 /* default implementation of wine_dbgstr_wn */
52 const char *wine_dbgstr_wn( const WCHAR *str, int n )
54 char *dst, *res;
55 size_t size;
57 if (!((ULONG_PTR)str >> 16))
59 if (!str) return "(null)";
60 res = get_temp_buffer( 6 );
61 sprintf( res, "#%04x", LOWORD(str) );
62 return res;
64 if (n == -1)
66 const WCHAR *end = str;
67 while (*end) end++;
68 n = end - str;
70 if (n < 0) n = 0;
71 size = 12 + min( 300, n * 5 );
72 dst = res = get_temp_buffer( size );
73 *dst++ = 'L';
74 *dst++ = '"';
75 while (n-- > 0 && dst <= res + size - 10)
77 WCHAR c = *str++;
78 switch (c)
80 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
81 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
82 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
83 case '"': *dst++ = '\\'; *dst++ = '"'; break;
84 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
85 default:
86 if (c >= ' ' && c <= 126)
87 *dst++ = c;
88 else
90 *dst++ = '\\';
91 sprintf(dst,"%04x",c);
92 dst+=4;
96 *dst++ = '"';
97 if (n > 0)
99 *dst++ = '.';
100 *dst++ = '.';
101 *dst++ = '.';
103 *dst++ = 0;
104 release_temp_buffer( res, dst - res );
105 return res;