Split up parts so it can be conditionally included in build
Wrap open_memstream() as it is not standard
Make it build on OSX