Question: Why malloc at all? Thats a serious performance penalty when you call this multiple times as its dispatched in many other functions including a context switch to the kernel and memory mapping.
The code from EvilSOB is better, but leaks the memory. In the end it could be done perfectly on the stack.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com