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