]> mj.ucw.cz Git - libucw.git/blob - charset/debug.c
f67ea8c79a5fc9d8543fbaaf375b6088c716bdad
[libucw.git] / charset / debug.c
1 /*
2  *      The UniCode Library -- Debugging Support Functions
3  *
4  *      (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 #include <stdio.h>
8
9 #include "lib/lib.h"
10 #include "charset/unicode.h"
11
12 static byte *
13 get_static_buffer(uns size)
14 {
15   static byte *static_debug_buffer;
16   static uns static_debug_size;
17
18   if (!static_debug_buffer)
19     {
20       if (size < 1024)
21         size = 1024;
22       static_debug_buffer = xmalloc(size);
23       static_debug_size = size;
24     }
25   else if (static_debug_size < size)
26     {
27       size = (size+1023) & ~1023;
28       static_debug_buffer = xrealloc(static_debug_buffer, size);
29       static_debug_size = size;
30     }
31   return static_debug_buffer;
32 }
33
34 byte *
35 static_ucs2_to_utf8(word *w)
36 {
37   byte *buf = get_static_buffer(Ustrlen(w) * 3 + 1);
38
39   ucs2_to_utf8(buf, w);
40   return buf;
41 }