1 module Dgame.Internal.d2c;
2 
3 private:
4 
5 //import Dgame.Internal.Error;
6 import Dgame.Internal.m3;
7 
8 char[] heapBuffer;
9 char[256] stackBuffer = void;
10 
11 @nogc
12 char* make_buffer(size_t len) nothrow {
13     if (stackBuffer.length > len)
14         return stackBuffer.ptr;
15 
16     if (heapBuffer.length > len)
17         return heapBuffer.ptr;
18 
19     //print_fmt("(Re)Order heap buffer: %d\n", len + 1);
20     heapBuffer = remake(heapBuffer, len + 1);
21 
22     return heapBuffer.ptr;
23 }
24 
25 public:
26 
27 @nogc
28 static ~this() nothrow {
29     //print_fmt("Free heap buffer: %d\n", heapBuffer.length);
30     unmake(heapBuffer);
31 }
32 
33 @nogc
34 const(char)* toStringz(string text) nothrow {
35     if (text.length == 0)
36         return null;
37 
38     if (text[$ - 1] == '\0')
39         return text.ptr;
40 
41     char* ptr = make_buffer(text.length);
42     ptr[0 .. text.length] = text[];
43     ptr[text.length] = '\0';
44 
45     return ptr;
46 }