]> mj.ucw.cz Git - libucw.git/blob - charset/debug.c
obuck_predict_last_oid() can be made safe easily.
[libucw.git] / charset / debug.c
1 /*
2  *      The UniCode Library -- Debugging Support Functions
3  *
4  *      (c) 1997 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include "lib/lib.h"
11 #include "charset/unicode.h"
12
13 static byte *
14 get_static_buffer(uns size)
15 {
16   static byte *static_debug_buffer;
17   static uns static_debug_size;
18
19   if (!static_debug_buffer)
20     {
21       if (size < 1024)
22         size = 1024;
23       static_debug_buffer = xmalloc(size);
24       static_debug_size = size;
25     }
26   else if (static_debug_size < size)
27     {
28       size = (size+1023) & ~1023;
29       static_debug_buffer = xrealloc(static_debug_buffer, size);
30       static_debug_size = size;
31     }
32   return static_debug_buffer;
33 }
34
35 byte *
36 static_ucs2_to_utf8(word *w)
37 {
38   byte *buf = get_static_buffer(Ustrlen(w) * 3 + 1);
39
40   ucs2_to_utf8(buf, w);
41   return buf;
42 }