Provide explicit casting to allow compilation on Mac OS X with clang.
Include platform-independent open_memstream for Apple platform.